Skip to content

Commit

Permalink
Merge pull request #31 from appwrite/dev
Browse files Browse the repository at this point in the history
feat: update sdk to 0.16
  • Loading branch information
christyjacob4 authored Apr 13, 2022
2 parents aed828f + 4495f6b commit 964f518
Show file tree
Hide file tree
Showing 17 changed files with 3,950 additions and 95 deletions.
1 change: 0 additions & 1 deletion .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ jobs:
registry-url: 'https://registry.npmjs.org'
- name: Setup binfmt with QEMU
run: |
sudo apt update
sudo apt install qemu binfmt-support qemu-user-static
update-binfmts --display
- name: Setup ldid
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
[![Twitter Account](https://img.shields.io/twitter/follow/appwrite?color=00acee&label=twitter&style=flat-square)](https://twitter.com/appwrite)
[![Discord](https://img.shields.io/discord/564160730845151244?label=discord&style=flat-square)](https://appwrite.io/discord)

**This SDK is compatible with Appwrite server version latest. For older versions, please check [previous releases](https://github.com/appwrite/sdk-for-cli/releases).**
**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).**

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)

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

```sh
$ appwrite -v
0.15.0
0.16.0
```

### Install using prebuilt binaries
Expand Down Expand Up @@ -58,7 +58,7 @@ $ iwr -useb https://appwrite.io/cli/install.ps1 | iex
Once the installation completes, you can verify your install using
```
$ appwrite -v
0.15.0
0.16.0
```

## Getting Started
Expand Down
4 changes: 2 additions & 2 deletions install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
# You can use "View source" of this page to see the full script.

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

# Appwrite download directory
$APPWRITE_DOWNLOAD_DIR = Join-Path -Path $env:TEMP -ChildPath "appwrite.exe"
Expand Down
2 changes: 1 addition & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ printSuccess() {
downloadBinary() {
echo "[2/4] Downloading executable for $OS ($ARCH) ..."

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

Expand Down
4 changes: 2 additions & 2 deletions lib/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ class Client {
this.endpoint = 'https://HOSTNAME/v1';
this.headers = {
'content-type': '',
'x-sdk-version': 'appwrite:cli:0.15.0',
'User-Agent' : `AppwriteCLI/0.15.0 (${os.type()} ${os.version()}; ${os.arch()})`,
'x-sdk-version': 'appwrite:cli:0.16.0',
'User-Agent' : `AppwriteCLI/0.16.0 (${os.type()} ${os.version()}; ${os.arch()})`,
'X-Appwrite-Response-Format' : '0.13.0',
};
}
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ const accountUpdatePrefs = async ({ prefs, parseOutput = true, sdk = undefined})

/** Body Params */
if (typeof prefs !== 'undefined') {
payload['prefs'] = prefs;
payload['prefs'] = JSON.parse(prefs);
}

let response = undefined;
Expand Down Expand Up @@ -782,4 +782,4 @@ module.exports = {
accountDeleteSession,
accountCreateVerification,
accountUpdateVerification
};
};
2 changes: 1 addition & 1 deletion lib/commands/avatars.js
Original file line number Diff line number Diff line change
Expand Up @@ -346,4 +346,4 @@ module.exports = {
avatarsGetImage,
avatarsGetInitials,
avatarsGetQR
};
};
6 changes: 3 additions & 3 deletions lib/commands/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ const databaseCreateDocument = async ({ collectionId, documentId, data, read, wr
}

if (typeof data !== 'undefined') {
payload['data'] = data;
payload['data'] = JSON.parse(data);
}

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

/** Body Params */
if (typeof data !== 'undefined') {
payload['data'] = data;
payload['data'] = JSON.parse(data);
}

if (typeof read !== 'undefined') {
Expand Down Expand Up @@ -1235,4 +1235,4 @@ module.exports = {
databaseListCollectionLogs,
databaseGetUsage,
databaseGetCollectionUsage
};
};
80 changes: 44 additions & 36 deletions lib/commands/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const functionsCreate = async ({ functionId, name, execute, runtime, vars, event
}

if (typeof vars !== 'undefined') {
payload['vars'] = vars;
payload['vars'] = JSON.parse(vars);
}

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

if (typeof vars !== 'undefined') {
payload['vars'] = vars;
payload['vars'] = JSON.parse(vars);
}

if (typeof events !== 'undefined') {
Expand Down Expand Up @@ -287,6 +287,7 @@ const functionsCreateDeployment = async ({ functionId, entrypoint, code, activat
let archivePath = fs.realpathSync('code.tar.gz')
if (typeof archivePath !== 'undefined') {
payload['code'] = archivePath;
code = archivePath;
}

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

response = await client.call('post', path, {
'content-type': 'multipart/form-data',
}, payload);
}, payload).catch(err => {
fs.unlinkSync(archivePath);
throw err
});
} else {
const streamFilePath = payload['code'];
let id = undefined;

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

for (let counter = 0; counter < totalCounters; counter++) {
const start = (counter * libClient.CHUNK_SIZE);
const end = Math.min((((counter * libClient.CHUNK_SIZE) + libClient.CHUNK_SIZE) - 1), size);
const headers = {
'content-type': 'multipart/form-data',
'content-range': 'bytes ' + start + '-' + end + '/' + size
};

if (id) {
headers['x-appwrite-id'] = id;
}

const stream = fs.createReadStream(streamFilePath, {
start,
end
const headers = {
'content-type': 'multipart/form-data',
};


for (counter; counter < totalCounters; counter++) {
const start = (counter * libClient.CHUNK_SIZE);
const end = Math.min((((counter * libClient.CHUNK_SIZE) + libClient.CHUNK_SIZE) - 1), size);

headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size;

if (id) {
headers['x-appwrite-id'] = id;
}

const stream = fs.createReadStream(streamFilePath, {
start,
end
});
payload['code'] = stream;

response = await client.call('post', path, headers, payload);

if (!id) {
id = response['$id'];
}

if (onProgress !== null) {
onProgress({
$id: response['$id'],
progress: Math.min((counter+1) * libClient.CHUNK_SIZE, size) / size * 100,
sizeUploaded: end+1,
chunksTotal: response['chunksTotal'],
chunksUploaded: response['chunksUploaded']
});
payload['code'] = stream;

response = await client.call('post', path, headers, payload);

if (!id) {
id = response['$id'];
}

if (onProgress !== null) {
onProgress({
$id: response['$id'],
progress: Math.min((counter+1) * libClient.CHUNK_SIZE, size) / size * 100,
sizeUploaded: end+1,
chunksTotal: response['chunksTotal'],
chunksUploaded: response['chunksUploaded']
});
}
}
}
}

Expand Down Expand Up @@ -699,4 +707,4 @@ module.exports = {
functionsCreateExecution,
functionsGetExecution,
functionsGetUsage
};
};
2 changes: 1 addition & 1 deletion lib/commands/health.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,4 @@ module.exports = {
healthGetQueueWebhooks,
healthGetStorageLocal,
healthGetTime
};
};
2 changes: 1 addition & 1 deletion lib/commands/locale.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,4 @@ module.exports = {
localeGetCountriesPhones,
localeGetCurrencies,
localeGetLanguages
};
};
2 changes: 1 addition & 1 deletion lib/commands/projects.js
Original file line number Diff line number Diff line change
Expand Up @@ -1188,4 +1188,4 @@ module.exports = {
projectsGetWebhook,
projectsUpdateWebhook,
projectsDeleteWebhook
};
};
79 changes: 45 additions & 34 deletions lib/commands/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,46 +303,57 @@ const storageCreateFile = async ({ bucketId, fileId, file, read, write, parseOut

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

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

for (let counter = 0; counter < totalCounters; counter++) {
const start = (counter * libClient.CHUNK_SIZE);
const end = Math.min((((counter * libClient.CHUNK_SIZE) + libClient.CHUNK_SIZE) - 1), size);
const headers = {
'content-type': 'multipart/form-data',
'content-range': 'bytes ' + start + '-' + end + '/' + size
};

if (id) {
headers['x-appwrite-id'] = id;
}

const stream = fs.createReadStream(streamFilePath, {
start,
end
const headers = {
'content-type': 'multipart/form-data',
};

if(fileId != 'unique()') {
try {
response = await client.call('get', path + '/' + fileId, headers);
counter = response.chunksUploaded;
} catch(e) {
}
}

for (counter; counter < totalCounters; counter++) {
const start = (counter * libClient.CHUNK_SIZE);
const end = Math.min((((counter * libClient.CHUNK_SIZE) + libClient.CHUNK_SIZE) - 1), size);

headers['content-range'] = 'bytes ' + start + '-' + end + '/' + size;

if (id) {
headers['x-appwrite-id'] = id;
}

const stream = fs.createReadStream(streamFilePath, {
start,
end
});
payload['file'] = stream;

response = await client.call('post', path, headers, payload);

if (!id) {
id = response['$id'];
}

if (onProgress !== null) {
onProgress({
$id: response['$id'],
progress: Math.min((counter+1) * libClient.CHUNK_SIZE, size) / size * 100,
sizeUploaded: end+1,
chunksTotal: response['chunksTotal'],
chunksUploaded: response['chunksUploaded']
});
payload['file'] = stream;

response = await client.call('post', path, headers, payload);

if (!id) {
id = response['$id'];
}

if (onProgress !== null) {
onProgress({
$id: response['$id'],
progress: Math.min((counter+1) * libClient.CHUNK_SIZE, size) / size * 100,
sizeUploaded: end+1,
chunksTotal: response['chunksTotal'],
chunksUploaded: response['chunksUploaded']
});
}
}
}
}

Expand Down Expand Up @@ -752,4 +763,4 @@ module.exports = {
storageGetFileView,
storageGetUsage,
storageGetBucketUsage
};
};
2 changes: 1 addition & 1 deletion lib/commands/teams.js
Original file line number Diff line number Diff line change
Expand Up @@ -432,4 +432,4 @@ module.exports = {
teamsUpdateMembershipRoles,
teamsDeleteMembership,
teamsUpdateMembershipStatus
};
};
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ const usersUpdatePrefs = async ({ userId, prefs, parseOutput = true, sdk = undef

/** Body Params */
if (typeof prefs !== 'undefined') {
payload['prefs'] = prefs;
payload['prefs'] = JSON.parse(prefs);
}

let response = undefined;
Expand Down Expand Up @@ -539,4 +539,4 @@ module.exports = {
usersDeleteSession,
usersUpdateStatus,
usersUpdateVerification
};
};
Loading

0 comments on commit 964f518

Please sign in to comment.