Skip to content

Commit

Permalink
[Flight] Add support BigInt support (#26479)
Browse files Browse the repository at this point in the history
## Summary

Adds support for sending `BigInt` to Flight and Flight Reply

## How did you test this change?

- added tests

DiffTrain build for [fd0511c](fd0511c)
  • Loading branch information
eps1lon committed Mar 29, 2023
1 parent fc1026b commit c49caca
Show file tree
Hide file tree
Showing 9 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion compiled/facebook-www/REVISION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
85de6fde515148babd36eae2b7384ad8e62b732a
fd0511c728e186905b7f0e71f072b4b247d6f29f
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,11 @@ function parseModelString(response, parentObject, key, value) {
return undefined;
}

case "n": {
// BigInt
return BigInt(value.substring(2));
}

default: {
// We assume that anything else is a reference ID.
var _id3 = parseInt(value.substring(1), 16);
Expand Down
5 changes: 5 additions & 0 deletions compiled/facebook-www/ReactFlightDOMRelayClient-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,11 @@ function parseModelString(response, parentObject, key, value) {
return undefined;
}

case "n": {
// BigInt
return BigInt(value.substring(2));
}

default: {
// We assume that anything else is a reference ID.
var _id3 = parseInt(value.substring(1), 16);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ function parseModelString(response, parentObject, key, value) {
}
case "u":
return;
case "n":
return BigInt(value.substring(2));
default:
value = parseInt(value.substring(1), 16);
response = getChunk(response, value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ function parseModelString(response, parentObject, key, value) {
}
case "u":
return;
case "n":
return BigInt(value.substring(2));
default:
value = parseInt(value.substring(1), 16);
response = getChunk(response, value);
Expand Down
11 changes: 5 additions & 6 deletions compiled/facebook-www/ReactFlightDOMRelayServer-dev.classic.js
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,10 @@ function serializeUndefined() {
return "$undefined";
}

function serializeBigInt(n) {
return "$n" + n.toString(10);
}

function serializeClientReference(request, parent, key, clientReference) {
var clientReferenceKey = getClientReferenceKey(clientReference);
var writtenClientReferences = request.writtenClientReferences;
Expand Down Expand Up @@ -2110,12 +2114,7 @@ function resolveModelToJSON(request, parent, key, value) {
}

if (typeof value === "bigint") {
throw new Error(
"BigInt (" +
value +
") is not yet supported in Client Component props." +
describeObjectForErrorMessage(parent, key)
);
return serializeBigInt(value);
}

throw new Error(
Expand Down
11 changes: 5 additions & 6 deletions compiled/facebook-www/ReactFlightDOMRelayServer-dev.modern.js
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,10 @@ function serializeUndefined() {
return "$undefined";
}

function serializeBigInt(n) {
return "$n" + n.toString(10);
}

function serializeClientReference(request, parent, key, clientReference) {
var clientReferenceKey = getClientReferenceKey(clientReference);
var writtenClientReferences = request.writtenClientReferences;
Expand Down Expand Up @@ -2110,12 +2114,7 @@ function resolveModelToJSON(request, parent, key, value) {
}

if (typeof value === "bigint") {
throw new Error(
"BigInt (" +
value +
") is not yet supported in Client Component props." +
describeObjectForErrorMessage(parent, key)
);
return serializeBigInt(value);
}

throw new Error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -909,13 +909,7 @@ function resolveModelToJSON(request, parent, key, value) {
element.set(value, key);
return "$" + key.toString(16);
}
if ("bigint" === typeof value)
throw Error(
"BigInt (" +
value +
") is not yet supported in Client Component props." +
describeObjectForErrorMessage(parent, key)
);
if ("bigint" === typeof value) return "$n" + value.toString(10);
throw Error(
"Type " +
typeof value +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -909,13 +909,7 @@ function resolveModelToJSON(request, parent, key, value) {
element.set(value, key);
return "$" + key.toString(16);
}
if ("bigint" === typeof value)
throw Error(
"BigInt (" +
value +
") is not yet supported in Client Component props." +
describeObjectForErrorMessage(parent, key)
);
if ("bigint" === typeof value) return "$n" + value.toString(10);
throw Error(
"Type " +
typeof value +
Expand Down

0 comments on commit c49caca

Please sign in to comment.