@geodedb/client 1.0.0-alpha.13 → 1.0.0-alpha.15
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.d.mts +42 -5
- package/dist/index.d.ts +42 -5
- package/dist/index.js +47 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +47 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -2
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Decimal from 'decimal.js-light';
|
|
2
|
+
import { parse, stringify, isLosslessNumber } from 'lossless-json';
|
|
2
3
|
import * as fs from 'fs';
|
|
3
4
|
import * as crypto from 'crypto';
|
|
4
5
|
|
|
@@ -553,8 +554,20 @@ function fromJSON(value, typeHint) {
|
|
|
553
554
|
if ("id" in obj && "labels" in obj && "properties" in obj) {
|
|
554
555
|
return GQLValue.node(obj);
|
|
555
556
|
}
|
|
556
|
-
if ("id" in obj && "type" in obj
|
|
557
|
-
|
|
557
|
+
if ("id" in obj && "type" in obj) {
|
|
558
|
+
const hasStartEnd = "startNode" in obj && "endNode" in obj;
|
|
559
|
+
const hasFromTo = "from" in obj && "to" in obj;
|
|
560
|
+
if (hasStartEnd || hasFromTo) {
|
|
561
|
+
const rawEdge = obj;
|
|
562
|
+
const normalizedEdge = {
|
|
563
|
+
id: rawEdge.id,
|
|
564
|
+
type: rawEdge.type,
|
|
565
|
+
startNode: rawEdge.startNode ?? rawEdge.from ?? "",
|
|
566
|
+
endNode: rawEdge.endNode ?? rawEdge.to ?? "",
|
|
567
|
+
properties: rawEdge.properties ?? {}
|
|
568
|
+
};
|
|
569
|
+
return GQLValue.edge(normalizedEdge);
|
|
570
|
+
}
|
|
558
571
|
}
|
|
559
572
|
if ("nodes" in obj && "edges" in obj && Array.isArray(obj.nodes)) {
|
|
560
573
|
return GQLValue.path(obj);
|
|
@@ -649,8 +662,17 @@ function convertWithType(value, type) {
|
|
|
649
662
|
return fromJSON(value);
|
|
650
663
|
case "NODE":
|
|
651
664
|
return GQLValue.node(value);
|
|
652
|
-
case "EDGE":
|
|
653
|
-
|
|
665
|
+
case "EDGE": {
|
|
666
|
+
const rawEdge = value;
|
|
667
|
+
const normalizedEdge = {
|
|
668
|
+
id: rawEdge.id,
|
|
669
|
+
type: rawEdge.type,
|
|
670
|
+
startNode: rawEdge.startNode ?? rawEdge.from ?? "",
|
|
671
|
+
endNode: rawEdge.endNode ?? rawEdge.to ?? "",
|
|
672
|
+
properties: rawEdge.properties ?? {}
|
|
673
|
+
};
|
|
674
|
+
return GQLValue.edge(normalizedEdge);
|
|
675
|
+
}
|
|
654
676
|
case "PATH":
|
|
655
677
|
return GQLValue.path(value);
|
|
656
678
|
default:
|
|
@@ -988,8 +1010,20 @@ var init_types = __esm({
|
|
|
988
1010
|
};
|
|
989
1011
|
}
|
|
990
1012
|
});
|
|
991
|
-
|
|
992
|
-
|
|
1013
|
+
function bigIntReviver(_key, value) {
|
|
1014
|
+
if (isLosslessNumber(value)) {
|
|
1015
|
+
const str = value.value;
|
|
1016
|
+
if (/^-?\d+$/.test(str)) {
|
|
1017
|
+
const num = Number(str);
|
|
1018
|
+
if (Number.isSafeInteger(num)) {
|
|
1019
|
+
return num;
|
|
1020
|
+
}
|
|
1021
|
+
return BigInt(str);
|
|
1022
|
+
}
|
|
1023
|
+
return Number(str);
|
|
1024
|
+
}
|
|
1025
|
+
return value;
|
|
1026
|
+
}
|
|
993
1027
|
function parseFrame(data) {
|
|
994
1028
|
let str;
|
|
995
1029
|
if (Buffer.isBuffer(data)) {
|
|
@@ -998,7 +1032,7 @@ function parseFrame(data) {
|
|
|
998
1032
|
str = data;
|
|
999
1033
|
}
|
|
1000
1034
|
try {
|
|
1001
|
-
const frame =
|
|
1035
|
+
const frame = parse(str, bigIntReviver);
|
|
1002
1036
|
if (!frame.result || typeof frame.result.type !== "string") {
|
|
1003
1037
|
const topLevel = frame;
|
|
1004
1038
|
if (typeof topLevel.type === "string") {
|
|
@@ -1147,7 +1181,7 @@ function buildPingMessage() {
|
|
|
1147
1181
|
};
|
|
1148
1182
|
}
|
|
1149
1183
|
function serializeMessage(msg) {
|
|
1150
|
-
const json =
|
|
1184
|
+
const json = stringify(msg, void 0, void 0, [bigIntStringifier]);
|
|
1151
1185
|
return Buffer.from(json + "\n", "utf-8");
|
|
1152
1186
|
}
|
|
1153
1187
|
function rewritePlaceholders(query2, args) {
|
|
@@ -1220,7 +1254,7 @@ function mergeParams(positionalParams, namedParams) {
|
|
|
1220
1254
|
}
|
|
1221
1255
|
return { ...positionalParams, ...namedParams };
|
|
1222
1256
|
}
|
|
1223
|
-
var MsgType, RespType;
|
|
1257
|
+
var MsgType, RespType, bigIntStringifier;
|
|
1224
1258
|
var init_protocol = __esm({
|
|
1225
1259
|
"src/protocol.ts"() {
|
|
1226
1260
|
init_errors();
|
|
@@ -1246,6 +1280,10 @@ var init_protocol = __esm({
|
|
|
1246
1280
|
RESULT: "RESULT",
|
|
1247
1281
|
STATUS: "STATUS"
|
|
1248
1282
|
};
|
|
1283
|
+
bigIntStringifier = {
|
|
1284
|
+
test: (value) => typeof value === "bigint",
|
|
1285
|
+
stringify: (value) => value.toString()
|
|
1286
|
+
};
|
|
1249
1287
|
}
|
|
1250
1288
|
});
|
|
1251
1289
|
|