Skip to content

Commit c4fa9ec

Browse files
committed
fix(cli): use JSONbig to parse and stringify JSON
Due to the way JavaScript handles numbers, the standard JSON parser will convert the max PHP int, 9223372036854775807, to 9223372036854776000. However, this is problematic because the resulting number is an invalid int in PHP so the integer validation fails. This PR ensures we use JSONbig to parse and stringify JSON in the CLI to retain the precision of the numbers.
1 parent b9cd545 commit c4fa9ec

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

templates/cli/lib/client.js.twig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ class Client {
118118

119119
body = formData;
120120
} else {
121-
body = JSON.stringify(params);
121+
body = JSONbig.stringify(params);
122122
}
123123

124124
let response = undefined;
@@ -174,7 +174,7 @@ class Client {
174174
const text = await response.text();
175175
let json = undefined;
176176
try {
177-
json = JSON.parse(text);
177+
json = JSONbig.parse(text);
178178
} catch (error) {
179179
return text;
180180
}

templates/cli/lib/commands/push.js.twig

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -354,8 +354,8 @@ const createAttribute = async (databaseId, collectionId, attribute) => {
354354
collectionId,
355355
key: attribute.key,
356356
required: attribute.required,
357-
min: parseInt(attribute.min.toString()),
358-
max: parseInt(attribute.max.toString()),
357+
min: attribute.min,
358+
max: attribute.max,
359359
xdefault: attribute.default,
360360
array: attribute.array,
361361
parseOutput: false
@@ -366,8 +366,8 @@ const createAttribute = async (databaseId, collectionId, attribute) => {
366366
collectionId,
367367
key: attribute.key,
368368
required: attribute.required,
369-
min: parseFloat(attribute.min.toString()),
370-
max: parseFloat(attribute.max.toString()),
369+
min: attribute.min,
370+
max: attribute.max,
371371
xdefault: attribute.default,
372372
array: attribute.array,
373373
parseOutput: false
@@ -471,8 +471,8 @@ const updateAttribute = async (databaseId, collectionId, attribute) => {
471471
collectionId,
472472
key: attribute.key,
473473
required: attribute.required,
474-
min: parseInt(attribute.min.toString()),
475-
max: parseInt(attribute.max.toString()),
474+
min: attribute.min,
475+
max: attribute.max,
476476
xdefault: attribute.default,
477477
array: attribute.array,
478478
parseOutput: false
@@ -483,8 +483,8 @@ const updateAttribute = async (databaseId, collectionId, attribute) => {
483483
collectionId,
484484
key: attribute.key,
485485
required: attribute.required,
486-
min: parseFloat(attribute.min.toString()),
487-
max: parseFloat(attribute.max.toString()),
486+
min: attribute.min,
487+
max: attribute.max,
488488
xdefault: attribute.default,
489489
array: attribute.array,
490490
parseOutput: false

0 commit comments

Comments
 (0)