@typedb/driver-http 3.13.6 → 3.14.0
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/dist/index.cjs +231 -5
- package/dist/index.d.ts +18 -2
- package/dist/index.mjs +231 -5
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -67,6 +67,230 @@ function isQueryResponseLegacy(res) {
|
|
|
67
67
|
return res.query != null && "blocks" in res.query;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-opt/bin/http-ts/src/json.ts
|
|
71
|
+
function parseJson(text) {
|
|
72
|
+
if (!UNSAFE_INTEGER_CANDIDATE.test(text)) return JSON.parse(text);
|
|
73
|
+
const parser = new JsonParser(text);
|
|
74
|
+
const value = parser.parseValue();
|
|
75
|
+
parser.skipWhitespace();
|
|
76
|
+
if (!parser.atEnd()) parser.fail("Unexpected trailing content");
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
var UNSAFE_INTEGER_CANDIDATE = /(^|[\[,:\s-])\d{16}/;
|
|
80
|
+
var JSON_NUMBER = /^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/;
|
|
81
|
+
function stringifyJson(value) {
|
|
82
|
+
const out = [];
|
|
83
|
+
writeValue(value, out);
|
|
84
|
+
return out.join("");
|
|
85
|
+
}
|
|
86
|
+
function writeValue(value, out) {
|
|
87
|
+
if (value !== null && typeof value === "object" && typeof value.toJSON === "function") {
|
|
88
|
+
value = value.toJSON();
|
|
89
|
+
}
|
|
90
|
+
if (value === null) {
|
|
91
|
+
out.push("null");
|
|
92
|
+
} else if (typeof value === "bigint") {
|
|
93
|
+
out.push(value.toString());
|
|
94
|
+
} else if (typeof value === "number") {
|
|
95
|
+
out.push(Number.isFinite(value) ? JSON.stringify(value) : "null");
|
|
96
|
+
} else if (typeof value === "boolean" || typeof value === "string") {
|
|
97
|
+
out.push(JSON.stringify(value));
|
|
98
|
+
} else if (Array.isArray(value)) {
|
|
99
|
+
out.push("[");
|
|
100
|
+
value.forEach((item, i) => {
|
|
101
|
+
if (i > 0) out.push(",");
|
|
102
|
+
if (item === void 0 || typeof item === "function" || typeof item === "symbol") out.push("null");
|
|
103
|
+
else writeValue(item, out);
|
|
104
|
+
});
|
|
105
|
+
out.push("]");
|
|
106
|
+
} else if (typeof value === "object") {
|
|
107
|
+
out.push("{");
|
|
108
|
+
let first = true;
|
|
109
|
+
for (const [key, member] of Object.entries(value)) {
|
|
110
|
+
if (member === void 0 || typeof member === "function" || typeof member === "symbol") continue;
|
|
111
|
+
if (!first) out.push(",");
|
|
112
|
+
first = false;
|
|
113
|
+
out.push(JSON.stringify(key), ":");
|
|
114
|
+
writeValue(member, out);
|
|
115
|
+
}
|
|
116
|
+
out.push("}");
|
|
117
|
+
} else {
|
|
118
|
+
out.push("null");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
var ESCAPES = {
|
|
122
|
+
'"': '"',
|
|
123
|
+
"\\": "\\",
|
|
124
|
+
"/": "/",
|
|
125
|
+
b: "\b",
|
|
126
|
+
f: "\f",
|
|
127
|
+
n: "\n",
|
|
128
|
+
r: "\r",
|
|
129
|
+
t: " "
|
|
130
|
+
};
|
|
131
|
+
var JsonParser = class {
|
|
132
|
+
constructor(text) {
|
|
133
|
+
this.at = 0;
|
|
134
|
+
this.text = text;
|
|
135
|
+
}
|
|
136
|
+
atEnd() {
|
|
137
|
+
return this.at >= this.text.length;
|
|
138
|
+
}
|
|
139
|
+
fail(message) {
|
|
140
|
+
throw new SyntaxError(`${message} at position ${this.at}`);
|
|
141
|
+
}
|
|
142
|
+
skipWhitespace() {
|
|
143
|
+
while (this.at < this.text.length) {
|
|
144
|
+
const c = this.text[this.at];
|
|
145
|
+
if (c === " " || c === "\n" || c === " " || c === "\r") this.at++;
|
|
146
|
+
else break;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
parseValue() {
|
|
150
|
+
this.skipWhitespace();
|
|
151
|
+
if (this.atEnd()) this.fail("Unexpected end of input");
|
|
152
|
+
const c = this.text[this.at];
|
|
153
|
+
switch (c) {
|
|
154
|
+
case "{":
|
|
155
|
+
return this.parseObject();
|
|
156
|
+
case "[":
|
|
157
|
+
return this.parseArray();
|
|
158
|
+
case '"':
|
|
159
|
+
return this.parseString();
|
|
160
|
+
case "t":
|
|
161
|
+
return this.parseLiteral("true", true);
|
|
162
|
+
case "f":
|
|
163
|
+
return this.parseLiteral("false", false);
|
|
164
|
+
case "n":
|
|
165
|
+
return this.parseLiteral("null", null);
|
|
166
|
+
default:
|
|
167
|
+
return this.parseNumber();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
parseLiteral(word, value) {
|
|
171
|
+
if (this.text.startsWith(word, this.at)) {
|
|
172
|
+
this.at += word.length;
|
|
173
|
+
return value;
|
|
174
|
+
}
|
|
175
|
+
this.fail(`Expected ${word}`);
|
|
176
|
+
}
|
|
177
|
+
parseObject() {
|
|
178
|
+
this.at++;
|
|
179
|
+
const result = {};
|
|
180
|
+
this.skipWhitespace();
|
|
181
|
+
if (this.text[this.at] === "}") {
|
|
182
|
+
this.at++;
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
for (; ; ) {
|
|
186
|
+
this.skipWhitespace();
|
|
187
|
+
if (this.text[this.at] !== '"') this.fail("Expected a property name");
|
|
188
|
+
const key = this.parseString();
|
|
189
|
+
this.skipWhitespace();
|
|
190
|
+
if (this.text[this.at] !== ":") this.fail("Expected ':'");
|
|
191
|
+
this.at++;
|
|
192
|
+
Object.defineProperty(result, key, {
|
|
193
|
+
value: this.parseValue(),
|
|
194
|
+
writable: true,
|
|
195
|
+
enumerable: true,
|
|
196
|
+
configurable: true
|
|
197
|
+
});
|
|
198
|
+
this.skipWhitespace();
|
|
199
|
+
const c = this.text[this.at];
|
|
200
|
+
if (c === ",") {
|
|
201
|
+
this.at++;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
if (c === "}") {
|
|
205
|
+
this.at++;
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
208
|
+
this.fail("Expected ',' or '}'");
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
parseArray() {
|
|
212
|
+
this.at++;
|
|
213
|
+
const result = [];
|
|
214
|
+
this.skipWhitespace();
|
|
215
|
+
if (this.text[this.at] === "]") {
|
|
216
|
+
this.at++;
|
|
217
|
+
return result;
|
|
218
|
+
}
|
|
219
|
+
for (; ; ) {
|
|
220
|
+
result.push(this.parseValue());
|
|
221
|
+
this.skipWhitespace();
|
|
222
|
+
const c = this.text[this.at];
|
|
223
|
+
if (c === ",") {
|
|
224
|
+
this.at++;
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
if (c === "]") {
|
|
228
|
+
this.at++;
|
|
229
|
+
return result;
|
|
230
|
+
}
|
|
231
|
+
this.fail("Expected ',' or ']'");
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
parseString() {
|
|
235
|
+
this.at++;
|
|
236
|
+
let out = "";
|
|
237
|
+
let chunkStart = this.at;
|
|
238
|
+
for (; ; ) {
|
|
239
|
+
if (this.atEnd()) this.fail("Unterminated string");
|
|
240
|
+
const c = this.text[this.at];
|
|
241
|
+
if (c === '"') {
|
|
242
|
+
out += this.text.slice(chunkStart, this.at);
|
|
243
|
+
this.at++;
|
|
244
|
+
return out;
|
|
245
|
+
}
|
|
246
|
+
if (c === "\\") {
|
|
247
|
+
out += this.text.slice(chunkStart, this.at);
|
|
248
|
+
this.at++;
|
|
249
|
+
const escape = this.text[this.at];
|
|
250
|
+
if (escape === "u") {
|
|
251
|
+
const hex = this.text.slice(this.at + 1, this.at + 5);
|
|
252
|
+
if (!/^[0-9a-fA-F]{4}$/.test(hex)) this.fail("Invalid unicode escape");
|
|
253
|
+
out += String.fromCharCode(parseInt(hex, 16));
|
|
254
|
+
this.at += 5;
|
|
255
|
+
} else {
|
|
256
|
+
const replacement = ESCAPES[escape];
|
|
257
|
+
if (replacement === void 0) this.fail("Invalid escape sequence");
|
|
258
|
+
out += replacement;
|
|
259
|
+
this.at++;
|
|
260
|
+
}
|
|
261
|
+
chunkStart = this.at;
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
this.at++;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
parseNumber() {
|
|
268
|
+
const start = this.at;
|
|
269
|
+
if (this.text[this.at] === "-") this.at++;
|
|
270
|
+
while (isDigit(this.text[this.at])) this.at++;
|
|
271
|
+
let isInteger = true;
|
|
272
|
+
if (this.text[this.at] === ".") {
|
|
273
|
+
isInteger = false;
|
|
274
|
+
this.at++;
|
|
275
|
+
while (isDigit(this.text[this.at])) this.at++;
|
|
276
|
+
}
|
|
277
|
+
if (this.text[this.at] === "e" || this.text[this.at] === "E") {
|
|
278
|
+
isInteger = false;
|
|
279
|
+
this.at++;
|
|
280
|
+
if (this.text[this.at] === "+" || this.text[this.at] === "-") this.at++;
|
|
281
|
+
while (isDigit(this.text[this.at])) this.at++;
|
|
282
|
+
}
|
|
283
|
+
const literal = this.text.slice(start, this.at);
|
|
284
|
+
if (!JSON_NUMBER.test(literal)) this.fail(`Invalid number '${literal}'`);
|
|
285
|
+
const value = Number(literal);
|
|
286
|
+
if (isInteger && !Number.isSafeInteger(value)) return BigInt(literal);
|
|
287
|
+
return value;
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
function isDigit(c) {
|
|
291
|
+
return c !== void 0 && c >= "0" && c <= "9";
|
|
292
|
+
}
|
|
293
|
+
|
|
70
294
|
// ../../../../../../../../../execroot/_main/bazel-out/k8-opt/bin/http-ts/src/analyzed-conjunction.ts
|
|
71
295
|
function getVariableName(structure, variable) {
|
|
72
296
|
return _optionalChain([structure, 'access', _ => _.variables, 'access', _2 => _2[variable.id], 'optionalAccess', _3 => _3.name]);
|
|
@@ -226,7 +450,7 @@ var TypeDBHttpDriver = class {
|
|
|
226
450
|
const url = `${this.currentOrigin}${path}`;
|
|
227
451
|
let tokenResp = await this.getToken();
|
|
228
452
|
if ("err" in tokenResp) return tokenErrToResult(tokenResp);
|
|
229
|
-
const bodyString = body !== void 0 ?
|
|
453
|
+
const bodyString = body !== void 0 ? stringifyJson(body) : void 0;
|
|
230
454
|
let headers = this.authHeaders(tokenResp.ok.token, options);
|
|
231
455
|
let resp;
|
|
232
456
|
try {
|
|
@@ -255,7 +479,7 @@ var TypeDBHttpDriver = class {
|
|
|
255
479
|
async switchToRedirectTarget(resp) {
|
|
256
480
|
let json;
|
|
257
481
|
try {
|
|
258
|
-
json = await resp.
|
|
482
|
+
json = parseJson(await resp.text());
|
|
259
483
|
} catch (e5) {
|
|
260
484
|
return false;
|
|
261
485
|
}
|
|
@@ -307,7 +531,7 @@ var TypeDBHttpDriver = class {
|
|
|
307
531
|
const body = { username: this.params.username, password: this.params.password };
|
|
308
532
|
let resp;
|
|
309
533
|
try {
|
|
310
|
-
resp = await fetch(url, { method: "POST", body:
|
|
534
|
+
resp = await fetch(url, { method: "POST", body: stringifyJson(body), headers: { "Content-Type": "application/json" } });
|
|
311
535
|
} catch (e6) {
|
|
312
536
|
return driverError("HDR2", `Cannot connect to server at ${this.currentOrigin}`);
|
|
313
537
|
}
|
|
@@ -321,7 +545,7 @@ var TypeDBHttpDriver = class {
|
|
|
321
545
|
}
|
|
322
546
|
async jsonOrNull(resp) {
|
|
323
547
|
try {
|
|
324
|
-
return await resp.
|
|
548
|
+
return parseJson(await resp.text());
|
|
325
549
|
} catch (e7) {
|
|
326
550
|
return null;
|
|
327
551
|
}
|
|
@@ -349,5 +573,7 @@ var TypeDBHttpDriver = class {
|
|
|
349
573
|
|
|
350
574
|
|
|
351
575
|
|
|
352
|
-
|
|
576
|
+
|
|
577
|
+
|
|
578
|
+
exports.TypeDBHttpDriver = TypeDBHttpDriver; exports.allOrigins = allOrigins; exports.driverError = driverError; exports.getVariableName = getVariableName; exports.hostPortFromOrigin = hostPortFromOrigin; exports.isApiError = isApiError; exports.isApiErrorResponse = isApiErrorResponse; exports.isBasicParams = isBasicParams; exports.isMisdirectedError = isMisdirectedError; exports.isOkResponse = isOkResponse; exports.isQueryResponseLegacy = isQueryResponseLegacy; exports.isTranslatedParams = isTranslatedParams; exports.parseJson = parseJson; exports.remoteOrigin = remoteOrigin; exports.resolveOrigin = resolveOrigin; exports.stringifyJson = stringifyJson;
|
|
353
579
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.d.ts
CHANGED
|
@@ -465,6 +465,22 @@ declare function isOkResponse<OK_RES>(res: ApiResponse<OK_RES>): res is ApiOkRes
|
|
|
465
465
|
declare function isApiErrorResponse(res: ApiResponse): res is ApiErrorResponse;
|
|
466
466
|
declare function isQueryResponseLegacy(res: ConceptRowsQueryResponse | ConceptRowsQueryResponseLegacy): boolean;
|
|
467
467
|
|
|
468
|
+
/**
|
|
469
|
+
* Parses JSON, returning a `bigint` for any integer a `number` cannot hold
|
|
470
|
+
* exactly. Otherwise behaves as `JSON.parse`, which reads every number as a
|
|
471
|
+
* double and so rounds integers beyond 2^53.
|
|
472
|
+
*
|
|
473
|
+
* The type of an integer therefore depends on its magnitude: a `number` below
|
|
474
|
+
* 2^53 and a `bigint` from there up, so compare with `==` rather than `===` if
|
|
475
|
+
* either is possible.
|
|
476
|
+
*/
|
|
477
|
+
declare function parseJson(text: string): any;
|
|
478
|
+
/**
|
|
479
|
+
* Serializes to JSON, writing a `bigint` as a number. `JSON.stringify` throws on
|
|
480
|
+
* one, so a value taken from an answer could not otherwise be sent back.
|
|
481
|
+
*/
|
|
482
|
+
declare function stringifyJson(value: unknown): string;
|
|
483
|
+
|
|
468
484
|
declare class TypeDBHttpDriver {
|
|
469
485
|
private params;
|
|
470
486
|
private token?;
|
|
@@ -533,9 +549,9 @@ interface AnalyzeOptions {
|
|
|
533
549
|
interface User {
|
|
534
550
|
username: string;
|
|
535
551
|
}
|
|
536
|
-
type GivenRowEntry = Value | Entity | Relation | Attribute | boolean | number | string;
|
|
552
|
+
type GivenRowEntry = Value | Entity | Relation | Attribute | boolean | number | bigint | string;
|
|
537
553
|
type GivenRows = {
|
|
538
554
|
[varName: string]: GivenRowEntry;
|
|
539
555
|
}[];
|
|
540
556
|
|
|
541
|
-
export { type AnalyzeOptions, type AnalyzeResponse, type AnalyzedConjunction, type AnalyzedFetch, type AnalyzedFunction, type AnalyzedPipeline, type Answer, type AnswerType, type ApiError, type ApiErrorResponse, type ApiOkResponse, type ApiResponse, type Attribute, type AttributeType, type Concept, type ConceptDocument, type ConceptDocumentsQueryResponse, type ConceptRow, type ConceptRowAnswer, type ConceptRowsQueryResponse, type ConceptRowsQueryResponseLegacy, type ConjunctionAnnotations, type ConstraintAny, type ConstraintComparison, type ConstraintDeleteConcepts, type ConstraintExpression, type ConstraintExpressionLegacy, type ConstraintFunction, type ConstraintHas, type ConstraintIid, type ConstraintIs, type ConstraintIsa, type ConstraintIsaExact, type ConstraintKind, type ConstraintLabel, type ConstraintLinks, type ConstraintLinksLegacy, type ConstraintNot, type ConstraintOr, type ConstraintOwns, type ConstraintPlays, type ConstraintRelates, type ConstraintSpan, type ConstraintSub, type ConstraintSubExact, type ConstraintTry, type ConstraintValue, type ConstraintVertexAny, type ConstraintVertexLabel, type ConstraintVertexNamedRole, type ConstraintVertexValue, type ConstraintVertexVariable, type Database, type DatabasesListResponse, type Distribution, type DriverParams, type DriverParamsBasic, type DriverParamsTranslated, type EdgeKind, type Entity, type EntityType, type FetchAnnotationFieldEntry, type FunctionReturnStructure, type FunctionSingleReturnSelector, type Given, type GivenRowEntry, type GivenRows, type InstantiableType, type MisdirectedError, type OkQueryResponse, type PipelineStage, type QueryConjunctionLegacy, type QueryOptions, type QueryResponse, type QueryResponseBase, type QueryStructureLegacy, type QueryType, type Reducer, type Relation, type RelationType, type ReplicationRole, type ReplicationStatus, type RoleType, type Server, type ServersListResponse, type SignInResponse, type ThingKind, type TransactionOpenResponse, type TransactionOptions, type TransactionType, type TranslatedAddress, type Type, TypeDBHttpDriver, type TypeKind, type User, type UsersListResponse, type Value, type ValueKind, type ValueType, type VariableAnnotations, type VariableId, type VariableInfo, type VersionResponse, allOrigins, driverError, getVariableName, hostPortFromOrigin, isApiError, isApiErrorResponse, isBasicParams, isMisdirectedError, isOkResponse, isQueryResponseLegacy, isTranslatedParams, remoteOrigin, resolveOrigin };
|
|
557
|
+
export { type AnalyzeOptions, type AnalyzeResponse, type AnalyzedConjunction, type AnalyzedFetch, type AnalyzedFunction, type AnalyzedPipeline, type Answer, type AnswerType, type ApiError, type ApiErrorResponse, type ApiOkResponse, type ApiResponse, type Attribute, type AttributeType, type Concept, type ConceptDocument, type ConceptDocumentsQueryResponse, type ConceptRow, type ConceptRowAnswer, type ConceptRowsQueryResponse, type ConceptRowsQueryResponseLegacy, type ConjunctionAnnotations, type ConstraintAny, type ConstraintComparison, type ConstraintDeleteConcepts, type ConstraintExpression, type ConstraintExpressionLegacy, type ConstraintFunction, type ConstraintHas, type ConstraintIid, type ConstraintIs, type ConstraintIsa, type ConstraintIsaExact, type ConstraintKind, type ConstraintLabel, type ConstraintLinks, type ConstraintLinksLegacy, type ConstraintNot, type ConstraintOr, type ConstraintOwns, type ConstraintPlays, type ConstraintRelates, type ConstraintSpan, type ConstraintSub, type ConstraintSubExact, type ConstraintTry, type ConstraintValue, type ConstraintVertexAny, type ConstraintVertexLabel, type ConstraintVertexNamedRole, type ConstraintVertexValue, type ConstraintVertexVariable, type Database, type DatabasesListResponse, type Distribution, type DriverParams, type DriverParamsBasic, type DriverParamsTranslated, type EdgeKind, type Entity, type EntityType, type FetchAnnotationFieldEntry, type FunctionReturnStructure, type FunctionSingleReturnSelector, type Given, type GivenRowEntry, type GivenRows, type InstantiableType, type MisdirectedError, type OkQueryResponse, type PipelineStage, type QueryConjunctionLegacy, type QueryOptions, type QueryResponse, type QueryResponseBase, type QueryStructureLegacy, type QueryType, type Reducer, type Relation, type RelationType, type ReplicationRole, type ReplicationStatus, type RoleType, type Server, type ServersListResponse, type SignInResponse, type ThingKind, type TransactionOpenResponse, type TransactionOptions, type TransactionType, type TranslatedAddress, type Type, TypeDBHttpDriver, type TypeKind, type User, type UsersListResponse, type Value, type ValueKind, type ValueType, type VariableAnnotations, type VariableId, type VariableInfo, type VersionResponse, allOrigins, driverError, getVariableName, hostPortFromOrigin, isApiError, isApiErrorResponse, isBasicParams, isMisdirectedError, isOkResponse, isQueryResponseLegacy, isTranslatedParams, parseJson, remoteOrigin, resolveOrigin, stringifyJson };
|
package/dist/index.mjs
CHANGED
|
@@ -67,6 +67,230 @@ function isQueryResponseLegacy(res) {
|
|
|
67
67
|
return res.query != null && "blocks" in res.query;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
+
// ../../../../../../../../../execroot/_main/bazel-out/k8-opt/bin/http-ts/src/json.ts
|
|
71
|
+
function parseJson(text) {
|
|
72
|
+
if (!UNSAFE_INTEGER_CANDIDATE.test(text)) return JSON.parse(text);
|
|
73
|
+
const parser = new JsonParser(text);
|
|
74
|
+
const value = parser.parseValue();
|
|
75
|
+
parser.skipWhitespace();
|
|
76
|
+
if (!parser.atEnd()) parser.fail("Unexpected trailing content");
|
|
77
|
+
return value;
|
|
78
|
+
}
|
|
79
|
+
var UNSAFE_INTEGER_CANDIDATE = /(^|[\[,:\s-])\d{16}/;
|
|
80
|
+
var JSON_NUMBER = /^-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?$/;
|
|
81
|
+
function stringifyJson(value) {
|
|
82
|
+
const out = [];
|
|
83
|
+
writeValue(value, out);
|
|
84
|
+
return out.join("");
|
|
85
|
+
}
|
|
86
|
+
function writeValue(value, out) {
|
|
87
|
+
if (value !== null && typeof value === "object" && typeof value.toJSON === "function") {
|
|
88
|
+
value = value.toJSON();
|
|
89
|
+
}
|
|
90
|
+
if (value === null) {
|
|
91
|
+
out.push("null");
|
|
92
|
+
} else if (typeof value === "bigint") {
|
|
93
|
+
out.push(value.toString());
|
|
94
|
+
} else if (typeof value === "number") {
|
|
95
|
+
out.push(Number.isFinite(value) ? JSON.stringify(value) : "null");
|
|
96
|
+
} else if (typeof value === "boolean" || typeof value === "string") {
|
|
97
|
+
out.push(JSON.stringify(value));
|
|
98
|
+
} else if (Array.isArray(value)) {
|
|
99
|
+
out.push("[");
|
|
100
|
+
value.forEach((item, i) => {
|
|
101
|
+
if (i > 0) out.push(",");
|
|
102
|
+
if (item === void 0 || typeof item === "function" || typeof item === "symbol") out.push("null");
|
|
103
|
+
else writeValue(item, out);
|
|
104
|
+
});
|
|
105
|
+
out.push("]");
|
|
106
|
+
} else if (typeof value === "object") {
|
|
107
|
+
out.push("{");
|
|
108
|
+
let first = true;
|
|
109
|
+
for (const [key, member] of Object.entries(value)) {
|
|
110
|
+
if (member === void 0 || typeof member === "function" || typeof member === "symbol") continue;
|
|
111
|
+
if (!first) out.push(",");
|
|
112
|
+
first = false;
|
|
113
|
+
out.push(JSON.stringify(key), ":");
|
|
114
|
+
writeValue(member, out);
|
|
115
|
+
}
|
|
116
|
+
out.push("}");
|
|
117
|
+
} else {
|
|
118
|
+
out.push("null");
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
var ESCAPES = {
|
|
122
|
+
'"': '"',
|
|
123
|
+
"\\": "\\",
|
|
124
|
+
"/": "/",
|
|
125
|
+
b: "\b",
|
|
126
|
+
f: "\f",
|
|
127
|
+
n: "\n",
|
|
128
|
+
r: "\r",
|
|
129
|
+
t: " "
|
|
130
|
+
};
|
|
131
|
+
var JsonParser = class {
|
|
132
|
+
constructor(text) {
|
|
133
|
+
this.at = 0;
|
|
134
|
+
this.text = text;
|
|
135
|
+
}
|
|
136
|
+
atEnd() {
|
|
137
|
+
return this.at >= this.text.length;
|
|
138
|
+
}
|
|
139
|
+
fail(message) {
|
|
140
|
+
throw new SyntaxError(`${message} at position ${this.at}`);
|
|
141
|
+
}
|
|
142
|
+
skipWhitespace() {
|
|
143
|
+
while (this.at < this.text.length) {
|
|
144
|
+
const c = this.text[this.at];
|
|
145
|
+
if (c === " " || c === "\n" || c === " " || c === "\r") this.at++;
|
|
146
|
+
else break;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
parseValue() {
|
|
150
|
+
this.skipWhitespace();
|
|
151
|
+
if (this.atEnd()) this.fail("Unexpected end of input");
|
|
152
|
+
const c = this.text[this.at];
|
|
153
|
+
switch (c) {
|
|
154
|
+
case "{":
|
|
155
|
+
return this.parseObject();
|
|
156
|
+
case "[":
|
|
157
|
+
return this.parseArray();
|
|
158
|
+
case '"':
|
|
159
|
+
return this.parseString();
|
|
160
|
+
case "t":
|
|
161
|
+
return this.parseLiteral("true", true);
|
|
162
|
+
case "f":
|
|
163
|
+
return this.parseLiteral("false", false);
|
|
164
|
+
case "n":
|
|
165
|
+
return this.parseLiteral("null", null);
|
|
166
|
+
default:
|
|
167
|
+
return this.parseNumber();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
parseLiteral(word, value) {
|
|
171
|
+
if (this.text.startsWith(word, this.at)) {
|
|
172
|
+
this.at += word.length;
|
|
173
|
+
return value;
|
|
174
|
+
}
|
|
175
|
+
this.fail(`Expected ${word}`);
|
|
176
|
+
}
|
|
177
|
+
parseObject() {
|
|
178
|
+
this.at++;
|
|
179
|
+
const result = {};
|
|
180
|
+
this.skipWhitespace();
|
|
181
|
+
if (this.text[this.at] === "}") {
|
|
182
|
+
this.at++;
|
|
183
|
+
return result;
|
|
184
|
+
}
|
|
185
|
+
for (; ; ) {
|
|
186
|
+
this.skipWhitespace();
|
|
187
|
+
if (this.text[this.at] !== '"') this.fail("Expected a property name");
|
|
188
|
+
const key = this.parseString();
|
|
189
|
+
this.skipWhitespace();
|
|
190
|
+
if (this.text[this.at] !== ":") this.fail("Expected ':'");
|
|
191
|
+
this.at++;
|
|
192
|
+
Object.defineProperty(result, key, {
|
|
193
|
+
value: this.parseValue(),
|
|
194
|
+
writable: true,
|
|
195
|
+
enumerable: true,
|
|
196
|
+
configurable: true
|
|
197
|
+
});
|
|
198
|
+
this.skipWhitespace();
|
|
199
|
+
const c = this.text[this.at];
|
|
200
|
+
if (c === ",") {
|
|
201
|
+
this.at++;
|
|
202
|
+
continue;
|
|
203
|
+
}
|
|
204
|
+
if (c === "}") {
|
|
205
|
+
this.at++;
|
|
206
|
+
return result;
|
|
207
|
+
}
|
|
208
|
+
this.fail("Expected ',' or '}'");
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
parseArray() {
|
|
212
|
+
this.at++;
|
|
213
|
+
const result = [];
|
|
214
|
+
this.skipWhitespace();
|
|
215
|
+
if (this.text[this.at] === "]") {
|
|
216
|
+
this.at++;
|
|
217
|
+
return result;
|
|
218
|
+
}
|
|
219
|
+
for (; ; ) {
|
|
220
|
+
result.push(this.parseValue());
|
|
221
|
+
this.skipWhitespace();
|
|
222
|
+
const c = this.text[this.at];
|
|
223
|
+
if (c === ",") {
|
|
224
|
+
this.at++;
|
|
225
|
+
continue;
|
|
226
|
+
}
|
|
227
|
+
if (c === "]") {
|
|
228
|
+
this.at++;
|
|
229
|
+
return result;
|
|
230
|
+
}
|
|
231
|
+
this.fail("Expected ',' or ']'");
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
parseString() {
|
|
235
|
+
this.at++;
|
|
236
|
+
let out = "";
|
|
237
|
+
let chunkStart = this.at;
|
|
238
|
+
for (; ; ) {
|
|
239
|
+
if (this.atEnd()) this.fail("Unterminated string");
|
|
240
|
+
const c = this.text[this.at];
|
|
241
|
+
if (c === '"') {
|
|
242
|
+
out += this.text.slice(chunkStart, this.at);
|
|
243
|
+
this.at++;
|
|
244
|
+
return out;
|
|
245
|
+
}
|
|
246
|
+
if (c === "\\") {
|
|
247
|
+
out += this.text.slice(chunkStart, this.at);
|
|
248
|
+
this.at++;
|
|
249
|
+
const escape = this.text[this.at];
|
|
250
|
+
if (escape === "u") {
|
|
251
|
+
const hex = this.text.slice(this.at + 1, this.at + 5);
|
|
252
|
+
if (!/^[0-9a-fA-F]{4}$/.test(hex)) this.fail("Invalid unicode escape");
|
|
253
|
+
out += String.fromCharCode(parseInt(hex, 16));
|
|
254
|
+
this.at += 5;
|
|
255
|
+
} else {
|
|
256
|
+
const replacement = ESCAPES[escape];
|
|
257
|
+
if (replacement === void 0) this.fail("Invalid escape sequence");
|
|
258
|
+
out += replacement;
|
|
259
|
+
this.at++;
|
|
260
|
+
}
|
|
261
|
+
chunkStart = this.at;
|
|
262
|
+
continue;
|
|
263
|
+
}
|
|
264
|
+
this.at++;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
parseNumber() {
|
|
268
|
+
const start = this.at;
|
|
269
|
+
if (this.text[this.at] === "-") this.at++;
|
|
270
|
+
while (isDigit(this.text[this.at])) this.at++;
|
|
271
|
+
let isInteger = true;
|
|
272
|
+
if (this.text[this.at] === ".") {
|
|
273
|
+
isInteger = false;
|
|
274
|
+
this.at++;
|
|
275
|
+
while (isDigit(this.text[this.at])) this.at++;
|
|
276
|
+
}
|
|
277
|
+
if (this.text[this.at] === "e" || this.text[this.at] === "E") {
|
|
278
|
+
isInteger = false;
|
|
279
|
+
this.at++;
|
|
280
|
+
if (this.text[this.at] === "+" || this.text[this.at] === "-") this.at++;
|
|
281
|
+
while (isDigit(this.text[this.at])) this.at++;
|
|
282
|
+
}
|
|
283
|
+
const literal = this.text.slice(start, this.at);
|
|
284
|
+
if (!JSON_NUMBER.test(literal)) this.fail(`Invalid number '${literal}'`);
|
|
285
|
+
const value = Number(literal);
|
|
286
|
+
if (isInteger && !Number.isSafeInteger(value)) return BigInt(literal);
|
|
287
|
+
return value;
|
|
288
|
+
}
|
|
289
|
+
};
|
|
290
|
+
function isDigit(c) {
|
|
291
|
+
return c !== void 0 && c >= "0" && c <= "9";
|
|
292
|
+
}
|
|
293
|
+
|
|
70
294
|
// ../../../../../../../../../execroot/_main/bazel-out/k8-opt/bin/http-ts/src/analyzed-conjunction.ts
|
|
71
295
|
function getVariableName(structure, variable) {
|
|
72
296
|
return structure.variables[variable.id]?.name;
|
|
@@ -226,7 +450,7 @@ var TypeDBHttpDriver = class {
|
|
|
226
450
|
const url = `${this.currentOrigin}${path}`;
|
|
227
451
|
let tokenResp = await this.getToken();
|
|
228
452
|
if ("err" in tokenResp) return tokenErrToResult(tokenResp);
|
|
229
|
-
const bodyString = body !== void 0 ?
|
|
453
|
+
const bodyString = body !== void 0 ? stringifyJson(body) : void 0;
|
|
230
454
|
let headers = this.authHeaders(tokenResp.ok.token, options);
|
|
231
455
|
let resp;
|
|
232
456
|
try {
|
|
@@ -255,7 +479,7 @@ var TypeDBHttpDriver = class {
|
|
|
255
479
|
async switchToRedirectTarget(resp) {
|
|
256
480
|
let json;
|
|
257
481
|
try {
|
|
258
|
-
json = await resp.
|
|
482
|
+
json = parseJson(await resp.text());
|
|
259
483
|
} catch {
|
|
260
484
|
return false;
|
|
261
485
|
}
|
|
@@ -307,7 +531,7 @@ var TypeDBHttpDriver = class {
|
|
|
307
531
|
const body = { username: this.params.username, password: this.params.password };
|
|
308
532
|
let resp;
|
|
309
533
|
try {
|
|
310
|
-
resp = await fetch(url, { method: "POST", body:
|
|
534
|
+
resp = await fetch(url, { method: "POST", body: stringifyJson(body), headers: { "Content-Type": "application/json" } });
|
|
311
535
|
} catch {
|
|
312
536
|
return driverError("HDR2", `Cannot connect to server at ${this.currentOrigin}`);
|
|
313
537
|
}
|
|
@@ -321,7 +545,7 @@ var TypeDBHttpDriver = class {
|
|
|
321
545
|
}
|
|
322
546
|
async jsonOrNull(resp) {
|
|
323
547
|
try {
|
|
324
|
-
return await resp.
|
|
548
|
+
return parseJson(await resp.text());
|
|
325
549
|
} catch {
|
|
326
550
|
return null;
|
|
327
551
|
}
|
|
@@ -347,7 +571,9 @@ export {
|
|
|
347
571
|
isOkResponse,
|
|
348
572
|
isQueryResponseLegacy,
|
|
349
573
|
isTranslatedParams,
|
|
574
|
+
parseJson,
|
|
350
575
|
remoteOrigin,
|
|
351
|
-
resolveOrigin
|
|
576
|
+
resolveOrigin,
|
|
577
|
+
stringifyJson
|
|
352
578
|
};
|
|
353
579
|
//# sourceMappingURL=index.mjs.map
|
package/package.json
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"name": "@typedb/driver-http", "version": "3.
|
|
1
|
+
{"name": "@typedb/driver-http", "version": "3.14.0", "description": "TypeDB HTTP Driver", "author": "TypeDB Community <community@typedb.com>", "license": "Apache-2.0", "homepage": "https://typedb.com", "repository": {"type": "git", "url": "https://github.com/typedb/typedb-driver"}, "bugs": {"url": "https://github.com/typedb/typedb-driver/issues"}, "keywords": ["database", "typedb"], "main": "dist/index.cjs", "module": "dist/index.mjs", "types": "dist/index.d.ts", "type": "module", "exports": {".": {"types": "./dist/index.d.ts", "import": "./dist/index.mjs", "require": "./dist/index.cjs"}}, "scripts": {"build:dev": "tsc", "build": "tsup", "test": "cucumber-js", "docs": "typedoc"}, "packageManager": "pnpm@8.15.9", "packageConfig": {"access": "public"}, "devDependencies": {"@cucumber/cucumber": "9.0.0", "@types/node": "24.0.12", "tsup": "8.5.0", "typedoc": "^0.28.7", "typescript": "5.8.3"}}
|