Skip to content

Commit 964f518

Browse files
Merge pull request #31 from appwrite/dev
feat: update sdk to 0.16
2 parents aed828f + 4495f6b commit 964f518

File tree

17 files changed

+3950
-95
lines changed

17 files changed

+3950
-95
lines changed

.github/workflows/npm-publish.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ jobs:
1313
registry-url: 'https://registry.npmjs.org'
1414
- name: Setup binfmt with QEMU
1515
run: |
16-
sudo apt update
1716
sudo apt install qemu binfmt-support qemu-user-static
1817
update-binfmts --display
1918
- name: Setup ldid

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
77
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)
88

9-
**This SDK is compatible with Appwrite server version latest. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-cli/releases).**
9+
**This SDK is compatible with Appwrite server version 0.13.x. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-cli/releases).**
1010

1111
Appwrite is an open-source backend as a service server that abstract and simplify complex and repetitive development tasks behind a very simple to use REST API. Appwrite aims to help you develop your apps faster and in a more secure way. Use the Command Line SDK to integrate your app with the Appwrite server to easily start interacting with all of Appwrite backend APIs and tools. For full API documentation and tutorials go to [https://appwrite.io/docs](https://appwrite.io/docs)
1212

@@ -29,7 +29,7 @@ Once the installation is complete, you can verify the install using
2929

3030
```sh
3131
$ appwrite -v
32-
0.15.0
32+
0.16.0
3333
```
3434

3535
### Install using prebuilt binaries
@@ -58,7 +58,7 @@ $ iwr -useb https://appwrite.io/cli/install.ps1 | iex
5858
Once the installation completes, you can verify your install using
5959
```
6060
$ appwrite -v
61-
0.15.0
61+
0.16.0
6262
```
6363

6464
## Getting Started

install.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
# You can use "View source" of this page to see the full script.
1414

1515
# REPO
16-
$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/0.15.0/appwrite-cli-win-x64.exe"
17-
$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/0.15.0/appwrite-cli-win-arm64.exe"
16+
$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/0.16.0/appwrite-cli-win-x64.exe"
17+
$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/0.16.0/appwrite-cli-win-arm64.exe"
1818

1919
# Appwrite download directory
2020
$APPWRITE_DOWNLOAD_DIR = Join-Path -Path $env:TEMP -ChildPath "appwrite.exe"

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ printSuccess() {
9797
downloadBinary() {
9898
echo "[2/4] Downloading executable for $OS ($ARCH) ..."
9999

100-
GITHUB_LATEST_VERSION="0.15.0"
100+
GITHUB_LATEST_VERSION="0.16.0"
101101
GITHUB_FILE="appwrite-cli-${OS}-${ARCH}"
102102
GITHUB_URL="https://github.com/$GITHUB_REPOSITORY_NAME/releases/download/$GITHUB_LATEST_VERSION/$GITHUB_FILE"
103103

lib/client.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ class Client {
1111
this.endpoint = 'https://HOSTNAME/v1';
1212
this.headers = {
1313
'content-type': '',
14-
'x-sdk-version': 'appwrite:cli:0.15.0',
15-
'User-Agent' : `AppwriteCLI/0.15.0 (${os.type()} ${os.version()}; ${os.arch()})`,
14+
'x-sdk-version': 'appwrite:cli:0.16.0',
15+
'User-Agent' : `AppwriteCLI/0.16.0 (${os.type()} ${os.version()}; ${os.arch()})`,
1616
'X-Appwrite-Response-Format' : '0.13.0',
1717
};
1818
}

lib/commands/account.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ const accountUpdatePrefs = async ({ prefs, parseOutput = true, sdk = undefined})
234234

235235
/** Body Params */
236236
if (typeof prefs !== 'undefined') {
237-
payload['prefs'] = prefs;
237+
payload['prefs'] = JSON.parse(prefs);
238238
}
239239

240240
let response = undefined;
@@ -782,4 +782,4 @@ module.exports = {
782782
accountDeleteSession,
783783
accountCreateVerification,
784784
accountUpdateVerification
785-
};
785+
};

lib/commands/avatars.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,4 +346,4 @@ module.exports = {
346346
avatarsGetImage,
347347
avatarsGetInitials,
348348
avatarsGetQR
349-
};
349+
};

lib/commands/database.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,7 +648,7 @@ const databaseCreateDocument = async ({ collectionId, documentId, data, read, wr
648648
}
649649

650650
if (typeof data !== 'undefined') {
651-
payload['data'] = data;
651+
payload['data'] = JSON.parse(data);
652652
}
653653

654654
if (typeof read !== 'undefined') {
@@ -703,7 +703,7 @@ const databaseUpdateDocument = async ({ collectionId, documentId, data, read, wr
703703

704704
/** Body Params */
705705
if (typeof data !== 'undefined') {
706-
payload['data'] = data;
706+
payload['data'] = JSON.parse(data);
707707
}
708708

709709
if (typeof read !== 'undefined') {
@@ -1235,4 +1235,4 @@ module.exports = {
12351235
databaseListCollectionLogs,
12361236
databaseGetUsage,
12371237
databaseGetCollectionUsage
1238-
};
1238+
};

lib/commands/functions.js

Lines changed: 44 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ const functionsCreate = async ({ functionId, name, execute, runtime, vars, event
8484
}
8585

8686
if (typeof vars !== 'undefined') {
87-
payload['vars'] = vars;
87+
payload['vars'] = JSON.parse(vars);
8888
}
8989

9090
if (typeof events !== 'undefined') {
@@ -169,7 +169,7 @@ const functionsUpdate = async ({ functionId, name, execute, vars, events, schedu
169169
}
170170

171171
if (typeof vars !== 'undefined') {
172-
payload['vars'] = vars;
172+
payload['vars'] = JSON.parse(vars);
173173
}
174174

175175
if (typeof events !== 'undefined') {
@@ -287,6 +287,7 @@ const functionsCreateDeployment = async ({ functionId, entrypoint, code, activat
287287
let archivePath = fs.realpathSync('code.tar.gz')
288288
if (typeof archivePath !== 'undefined') {
289289
payload['code'] = archivePath;
290+
code = archivePath;
290291
}
291292

292293
if (typeof activate !== 'undefined') {
@@ -301,46 +302,53 @@ const functionsCreateDeployment = async ({ functionId, entrypoint, code, activat
301302

302303
response = await client.call('post', path, {
303304
'content-type': 'multipart/form-data',
304-
}, payload);
305+
}, payload).catch(err => {
306+
fs.unlinkSync(archivePath);
307+
throw err
308+
});
305309
} else {
306310
const streamFilePath = payload['code'];
307311
let id = undefined;
308312

313+
let counter = 0;
309314
const totalCounters = Math.ceil(size / libClient.CHUNK_SIZE);
310315

311-
for (let counter = 0; counter < totalCounters; counter++) {
312-
const start = (counter * libClient.CHUNK_SIZE);
313-
const end = Math.min((((counter * libClient.CHUNK_SIZE) + libClient.CHUNK_SIZE) - 1), size);
314-
const headers = {
315-
'content-type': 'multipart/form-data',
316-
'content-range': 'bytes ' + start + '-' + end + '/' + size
317-
};
318-
319-
if (id) {
320-
headers['x-appwrite-id'] = id;
321-
}
322-
323-
const stream = fs.createReadStream(streamFilePath, {
324-
start,
325-
end
316+
const headers = {
317+
'content-type': 'multipart/form-data',
318+
};
319+
320+
321+
for (counter; counter < totalCounters; counter++) {
322+
const start = (counter * libClient.CHUNK_SIZE);
323+
const end = Math.min((((counter * libClient.CHUNK_SIZE) + libClient.CHUNK_SIZE) - 1), size);
324+
325+
headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
326+
327+
if (id) {
328+
headers['x-appwrite-id'] = id;
329+
}
330+
331+
const stream = fs.createReadStream(streamFilePath, {
332+
start,
333+
end
334+
});
335+
payload['code'] = stream;
336+
337+
response = await client.call('post', path, headers, payload);
338+
339+
if (!id) {
340+
id = response['$id'];
341+
}
342+
343+
if (onProgress !== null) {
344+
onProgress({
345+
$id: response['$id'],
346+
progress: Math.min((counter+1) * libClient.CHUNK_SIZE, size) / size * 100,
347+
sizeUploaded: end+1,
348+
chunksTotal: response['chunksTotal'],
349+
chunksUploaded: response['chunksUploaded']
326350
});
327-
payload['code'] = stream;
328-
329-
response = await client.call('post', path, headers, payload);
330-
331-
if (!id) {
332-
id = response['$id'];
333-
}
334-
335-
if (onProgress !== null) {
336-
onProgress({
337-
$id: response['$id'],
338-
progress: Math.min((counter+1) * libClient.CHUNK_SIZE, size) / size * 100,
339-
sizeUploaded: end+1,
340-
chunksTotal: response['chunksTotal'],
341-
chunksUploaded: response['chunksUploaded']
342-
});
343-
}
351+
}
344352
}
345353
}
346354

@@ -699,4 +707,4 @@ module.exports = {
699707
functionsCreateExecution,
700708
functionsGetExecution,
701709
functionsGetUsage
702-
};
710+
};

lib/commands/health.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,4 @@ module.exports = {
266266
healthGetQueueWebhooks,
267267
healthGetStorageLocal,
268268
healthGetTime
269-
};
269+
};

lib/commands/locale.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,4 @@ module.exports = {
174174
localeGetCountriesPhones,
175175
localeGetCurrencies,
176176
localeGetLanguages
177-
};
177+
};

lib/commands/projects.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1188,4 +1188,4 @@ module.exports = {
11881188
projectsGetWebhook,
11891189
projectsUpdateWebhook,
11901190
projectsDeleteWebhook
1191-
};
1191+
};

lib/commands/storage.js

Lines changed: 45 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -303,46 +303,57 @@ const storageCreateFile = async ({ bucketId, fileId, file, read, write, parseOut
303303

304304
response = await client.call('post', path, {
305305
'content-type': 'multipart/form-data',
306-
}, payload);
306+
}, payload)
307307
} else {
308308
const streamFilePath = payload['file'];
309309
let id = undefined;
310310

311+
let counter = 0;
311312
const totalCounters = Math.ceil(size / libClient.CHUNK_SIZE);
312313

313-
for (let counter = 0; counter < totalCounters; counter++) {
314-
const start = (counter * libClient.CHUNK_SIZE);
315-
const end = Math.min((((counter * libClient.CHUNK_SIZE) + libClient.CHUNK_SIZE) - 1), size);
316-
const headers = {
317-
'content-type': 'multipart/form-data',
318-
'content-range': 'bytes ' + start + '-' + end + '/' + size
319-
};
320-
321-
if (id) {
322-
headers['x-appwrite-id'] = id;
323-
}
324-
325-
const stream = fs.createReadStream(streamFilePath, {
326-
start,
327-
end
314+
const headers = {
315+
'content-type': 'multipart/form-data',
316+
};
317+
318+
if(fileId != 'unique()') {
319+
try {
320+
response = await client.call('get', path + '/' + fileId, headers);
321+
counter = response.chunksUploaded;
322+
} catch(e) {
323+
}
324+
}
325+
326+
for (counter; counter < totalCounters; counter++) {
327+
const start = (counter * libClient.CHUNK_SIZE);
328+
const end = Math.min((((counter * libClient.CHUNK_SIZE) + libClient.CHUNK_SIZE) - 1), size);
329+
330+
headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size;
331+
332+
if (id) {
333+
headers['x-appwrite-id'] = id;
334+
}
335+
336+
const stream = fs.createReadStream(streamFilePath, {
337+
start,
338+
end
339+
});
340+
payload['file'] = stream;
341+
342+
response = await client.call('post', path, headers, payload);
343+
344+
if (!id) {
345+
id = response['$id'];
346+
}
347+
348+
if (onProgress !== null) {
349+
onProgress({
350+
$id: response['$id'],
351+
progress: Math.min((counter+1) * libClient.CHUNK_SIZE, size) / size * 100,
352+
sizeUploaded: end+1,
353+
chunksTotal: response['chunksTotal'],
354+
chunksUploaded: response['chunksUploaded']
328355
});
329-
payload['file'] = stream;
330-
331-
response = await client.call('post', path, headers, payload);
332-
333-
if (!id) {
334-
id = response['$id'];
335-
}
336-
337-
if (onProgress !== null) {
338-
onProgress({
339-
$id: response['$id'],
340-
progress: Math.min((counter+1) * libClient.CHUNK_SIZE, size) / size * 100,
341-
sizeUploaded: end+1,
342-
chunksTotal: response['chunksTotal'],
343-
chunksUploaded: response['chunksUploaded']
344-
});
345-
}
356+
}
346357
}
347358
}
348359

@@ -752,4 +763,4 @@ module.exports = {
752763
storageGetFileView,
753764
storageGetUsage,
754765
storageGetBucketUsage
755-
};
766+
};

lib/commands/teams.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,4 +432,4 @@ module.exports = {
432432
teamsUpdateMembershipRoles,
433433
teamsDeleteMembership,
434434
teamsUpdateMembershipStatus
435-
};
435+
};

lib/commands/users.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ const usersUpdatePrefs = async ({ userId, prefs, parseOutput = true, sdk = undef
285285

286286
/** Body Params */
287287
if (typeof prefs !== 'undefined') {
288-
payload['prefs'] = prefs;
288+
payload['prefs'] = JSON.parse(prefs);
289289
}
290290

291291
let response = undefined;
@@ -539,4 +539,4 @@ module.exports = {
539539
usersDeleteSession,
540540
usersUpdateStatus,
541541
usersUpdateVerification
542-
};
542+
};

0 commit comments

Comments
 (0)