Skip to content

Commit 482fa2e

Browse files
Merge pull request #422 from appwrite/fix-js-bigint
Fix: Big Integers
2 parents dfcaafb + ca6c41c commit 482fa2e

File tree

6 files changed

+15
-11
lines changed

6 files changed

+15
-11
lines changed

composer.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

templates/cli/lib/client.js.twig

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const os = require('os');
22
const axios = require("axios");
3+
const JSONbig = require("json-bigint")({ storeAsString: false });
34
const FormData = require("form-data");
45
const {{spec.title | caseUcfirst}}Exception = require("./exception.js");
56
const { globalConfig } = require("./config.js");
@@ -130,11 +131,9 @@ class Client {
130131
params: method.toUpperCase() === "GET" ? params : {},
131132
headers: headers,
132133
data:
133-
method.toUpperCase() === "GET" ||
134-
contentType.startsWith("multipart/form-data")
135-
? formData
136-
: params,
134+
method.toUpperCase() === "GET" || contentType.startsWith("multipart/form-data") ? formData : params,
137135
json: contentType.startsWith("application/json"),
136+
transformRequest: method.toUpperCase() === "GET" || contentType.startsWith("multipart/form-data") ? undefined : (data) => JSONbig.stringify(data),
138137
responseType: responseType,
139138
};
140139
try {

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
const inquirer = require("inquirer");
2+
const JSONbig = require("json-bigint")({ storeAsString: false });
23
const { Command } = require("commander");
34
const { localConfig } = require("../config");
45
const { questionsDeployFunctions, questionsGetEntrypoint, questionsDeployCollections } = require("../questions");
@@ -319,7 +320,7 @@ const createAttribute = async (collectionId, attribute) => {
319320
const deployCollection = async () => {
320321
let response = {};
321322
let answers = await inquirer.prompt(questionsDeployCollections[0])
322-
let collections = answers.collections
323+
let collections = answers.collections.map((collection) => JSONbig.parse(collection));
323324

324325
for (let collection of collections) {
325326
log(`Deploying collection ${collection.name} ( ${collection['$id']} )`)

templates/cli/lib/config.js.twig

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const os = require('os');
22
const fs = require("fs");
33
const _path = require("path");
44
const process = require("process");
5+
const JSONbig = require("json-bigint")({ storeAsString: false });
56

67
class Config {
78
constructor(path) {
@@ -11,7 +12,8 @@ class Config {
1112

1213
read() {
1314
try {
14-
this.data = require(this.path);
15+
const file = fs.readFileSync(this.path).toString();
16+
this.data = JSONbig.parse(file);
1517
} catch (e) {
1618
// console.log(`${this.path} not found. Empty data`);
1719
this.data = {};
@@ -23,7 +25,7 @@ class Config {
2325
if (!fs.existsSync(dir)){
2426
fs.mkdirSync(dir, { recursive: true });
2527
}
26-
fs.writeFileSync(this.path, JSON.stringify(this.data, null, 4));
28+
fs.writeFileSync(this.path, JSONbig.stringify(this.data, null, 4));
2729
}
2830

2931
get(key) {
@@ -46,7 +48,7 @@ class Config {
4648
}
4749

4850
has(key) {
49-
return this.data.hasOwnProperty(key);
51+
return this.data[key] !== undefined;
5052
}
5153

5254
keys() {
@@ -58,7 +60,7 @@ class Config {
5860
}
5961

6062
toString() {
61-
return JSON.stringify(this.data, null, 4);
63+
return JSONbig.stringify(this.data, null, 4);
6264
}
6365
}
6466

templates/cli/lib/questions.js.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const { localConfig } = require('./config');
22
const { projectsList } = require('./commands/projects');
33
const { functionsListRuntimes } = require('./commands/functions');
4+
const JSONbig = require("json-bigint")({ storeAsString: false });
45

56
const getIgnores = (runtime) => {
67
const languge = runtime.split('-')[0];
@@ -217,7 +218,7 @@ const questionsDeployCollections = [
217218
let choices = collections.map((collection, idx) => {
218219
return {
219220
name: `${collection.name} (${collection['$id']})`,
220-
value: collection
221+
value: JSONbig.stringify(collection)
221222
}
222223
})
223224
return choices;

templates/cli/package.json.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
"cli-table3": "^0.6.2",
2828
"commander": "^9.2.0",
2929
"form-data": "^4.0.0",
30+
"json-bigint": "^1.0.0",
3031
"inquirer": "^8.2.4",
3132
"tar": "^6.1.11",
3233
"ignore": "^5.2.0"

0 commit comments

Comments
 (0)