Skip to content

Add inc/dec #179

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Change Log

## 8.2.2

* Fix object comparison logic when pushing settings
* Type generation fixes:
* Dart: Fixed import casing to snake_case, removed `extends Document` and hardcoded attributes, removed unnecessary imports
* Java: Fixed indentation to 4 spaces, updated imports to `java.util.Objects`, fixed enum casing in strict mode as per [Oracle official docs](https://docs.oracle.com/javase/tutorial/java/javaOO/enum.html)
* Javascript: Updated optional values formatting from `|null` to `| null`
* Kotlin: Fixed indentation to 4 spaces per [Kotlinlang official docs](https://kotlinlang.org/docs/coding-conventions.html#indentation)
* PHP: Fixed indentation to 4 spaces per [PHP Fig official docs](https://www.php-fig.org/psr/psr-2/)
* Swift: Fixed indentation to 4 spaces, improved `decodeIfPresent` usage for optionals, added missing `public` to `init` method
* Typescript: Fixed indentation to 4 spaces per [Typescript coding guidelines](https://github.com/microsoft/TypeScript/wiki/Coding-guidelines)

## 8.2.1

* Added `--with-variables` option to the Sites command for adding/updating environment variables
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Once the installation is complete, you can verify the install using

```sh
$ appwrite -v
8.2.1
8.3.0
```

### Install using prebuilt binaries
Expand Down Expand Up @@ -60,7 +60,7 @@ $ scoop install https://raw.githubusercontent.com/appwrite/sdk-for-cli/master/sc
Once the installation completes, you can verify your install using
```
$ appwrite -v
8.2.1
8.3.0
```

## Getting Started
Expand Down
7 changes: 7 additions & 0 deletions docs/examples/databases/decrement-document-attribute.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appwrite databases decrementDocumentAttribute \
--databaseId <DATABASE_ID> \
--collectionId <COLLECTION_ID> \
--documentId <DOCUMENT_ID> \
--attribute '' \


7 changes: 7 additions & 0 deletions docs/examples/databases/increment-document-attribute.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
appwrite databases incrementDocumentAttribute \
--databaseId <DATABASE_ID> \
--collectionId <COLLECTION_ID> \
--documentId <DOCUMENT_ID> \
--attribute '' \


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/8.2.1/appwrite-cli-win-x64.exe"
$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/8.2.1/appwrite-cli-win-arm64.exe"
$GITHUB_x64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/8.3.0/appwrite-cli-win-x64.exe"
$GITHUB_arm64_URL = "https://github.com/appwrite/sdk-for-cli/releases/download/8.3.0/appwrite-cli-win-arm64.exe"

$APPWRITE_BINARY_NAME = "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="8.2.1"
GITHUB_LATEST_VERSION="8.3.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 @@ -16,8 +16,8 @@ class Client {
'x-sdk-name': 'Command Line',
'x-sdk-platform': 'console',
'x-sdk-language': 'cli',
'x-sdk-version': '8.2.1',
'user-agent' : `AppwriteCLI/8.2.1 (${os.type()} ${os.version()}; ${os.arch()})`,
'x-sdk-version': '8.3.0',
'user-agent' : `AppwriteCLI/8.3.0 (${os.type()} ${os.version()}; ${os.arch()})`,
'X-Appwrite-Response-Format' : '1.7.0',
};
}
Expand Down
110 changes: 109 additions & 1 deletion lib/commands/databases.js
Original file line number Diff line number Diff line change
Expand Up @@ -1990,6 +1990,90 @@ const databasesListDocumentLogs = async ({databaseId,collectionId,documentId,que

}

/**
* @typedef {Object} DatabasesDecrementDocumentAttributeRequestParams
* @property {string} databaseId Database ID.
* @property {string} collectionId Collection ID.
* @property {string} documentId Document ID.
* @property {string} attribute Attribute key.
* @property {number} value Value to decrement the attribute by. The value must be a number.
* @property {number} min Minimum value for the attribute. If the current value is lesser than this value, an exception will be thrown.
* @property {boolean} overrideForCli
* @property {boolean} parseOutput
* @property {libClient | undefined} sdk
*/

/**
* @param {DatabasesDecrementDocumentAttributeRequestParams} params
*/
const databasesDecrementDocumentAttribute = async ({databaseId,collectionId,documentId,attribute,value,min,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
let client = !sdk ? await sdkForProject() :
sdk;
let apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/decrement'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId).replace('{attribute}', attribute);
let payload = {};
if (typeof value !== 'undefined') {
payload['value'] = value;
}
if (typeof min !== 'undefined') {
payload['min'] = min;
}

let response = undefined;

response = await client.call('patch', apiPath, {
'content-type': 'application/json',
}, payload);

if (parseOutput) {
parse(response)
}

return response;

}

/**
* @typedef {Object} DatabasesIncrementDocumentAttributeRequestParams
* @property {string} databaseId Database ID.
* @property {string} collectionId Collection ID.
* @property {string} documentId Document ID.
* @property {string} attribute Attribute key.
* @property {number} value Value to increment the attribute by. The value must be a number.
* @property {number} max Maximum value for the attribute. If the current value is greater than this value, an error will be thrown.
* @property {boolean} overrideForCli
* @property {boolean} parseOutput
* @property {libClient | undefined} sdk
*/

/**
* @param {DatabasesIncrementDocumentAttributeRequestParams} params
*/
const databasesIncrementDocumentAttribute = async ({databaseId,collectionId,documentId,attribute,value,max,parseOutput = true, overrideForCli = false, sdk = undefined}) => {
let client = !sdk ? await sdkForProject() :
sdk;
let apiPath = '/databases/{databaseId}/collections/{collectionId}/documents/{documentId}/{attribute}/increment'.replace('{databaseId}', databaseId).replace('{collectionId}', collectionId).replace('{documentId}', documentId).replace('{attribute}', attribute);
let payload = {};
if (typeof value !== 'undefined') {
payload['value'] = value;
}
if (typeof max !== 'undefined') {
payload['max'] = max;
}

let response = undefined;

response = await client.call('patch', apiPath, {
'content-type': 'application/json',
}, payload);

if (parseOutput) {
parse(response)
}

return response;

}

/**
* @typedef {Object} DatabasesListIndexesRequestParams
* @property {string} databaseId Database ID.
Expand Down Expand Up @@ -2668,7 +2752,7 @@ databases

databases
.command(`upsert-documents`)
.description(`**WARNING: Experimental Feature** - This endpoint is experimental and not yet officially supported. It may be subject to breaking changes or removal in future versions. Create or update Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console.`)
.description(`**WARNING: Experimental Feature** - This endpoint is experimental and not yet officially supported. It may be subject to breaking changes or removal in future versions. Create or update Documents. Before using this route, you should create a new collection resource using either a [server integration](https://appwrite.io/docs/server/databases#databasesCreateCollection) API or directly from your database console. `)
.requiredOption(`--database-id <database-id>`, `Database ID.`)
.requiredOption(`--collection-id <collection-id>`, `Collection ID.`)
.requiredOption(`--documents [documents...]`, `Array of document data as JSON objects. May contain partial documents.`)
Expand Down Expand Up @@ -2738,6 +2822,28 @@ databases
.option(`--queries [queries...]`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Only supported methods are limit and offset`)
.action(actionRunner(databasesListDocumentLogs))

databases
.command(`decrement-document-attribute`)
.description(`Decrement a specific attribute of a document by a given value.`)
.requiredOption(`--database-id <database-id>`, `Database ID.`)
.requiredOption(`--collection-id <collection-id>`, `Collection ID.`)
.requiredOption(`--document-id <document-id>`, `Document ID.`)
.requiredOption(`--attribute <attribute>`, `Attribute key.`)
.option(`--value <value>`, `Value to decrement the attribute by. The value must be a number.`, parseInteger)
.option(`--min <min>`, `Minimum value for the attribute. If the current value is lesser than this value, an exception will be thrown.`, parseInteger)
.action(actionRunner(databasesDecrementDocumentAttribute))

databases
.command(`increment-document-attribute`)
.description(`Increment a specific attribute of a document by a given value.`)
.requiredOption(`--database-id <database-id>`, `Database ID.`)
.requiredOption(`--collection-id <collection-id>`, `Collection ID.`)
.requiredOption(`--document-id <document-id>`, `Document ID.`)
.requiredOption(`--attribute <attribute>`, `Attribute key.`)
.option(`--value <value>`, `Value to increment the attribute by. The value must be a number.`, parseInteger)
.option(`--max <max>`, `Maximum value for the attribute. If the current value is greater than this value, an error will be thrown.`, parseInteger)
.action(actionRunner(databasesIncrementDocumentAttribute))

databases
.command(`list-indexes`)
.description(`List indexes in the collection.`)
Expand Down Expand Up @@ -2853,6 +2959,8 @@ module.exports = {
databasesUpdateDocument,
databasesDeleteDocument,
databasesListDocumentLogs,
databasesDecrementDocumentAttribute,
databasesIncrementDocumentAttribute,
databasesListIndexes,
databasesCreateIndex,
databasesGetIndex,
Expand Down
13 changes: 11 additions & 2 deletions lib/commands/push.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,8 +417,17 @@ const getObjectChanges = (remote, local, index, what) => {

if (remote[index] && local[index]) {
for (let [service, status] of Object.entries(remote[index])) {
if (status !== local[index][service]) {
changes.push({ group: what, setting: service, remote: chalk.red(status), local: chalk.green(local[index][service]) })
const localValue = local[index][service];
let valuesEqual = false;

if (Array.isArray(status) && Array.isArray(localValue)) {
valuesEqual = JSON.stringify(status) === JSON.stringify(localValue);
} else {
valuesEqual = status === localValue;
}

if (!valuesEqual) {
changes.push({ group: what, setting: service, remote: chalk.red(status), local: chalk.green(localValue) })
}
}
}
Expand Down
9 changes: 5 additions & 4 deletions lib/commands/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require("path");
const { LanguageMeta, detectLanguage } = require("../type-generation/languages/language");
const { Command, Option, Argument } = require("commander");
const { localConfig } = require("../config");
const { success, log, actionRunner } = require("../parser");
const { success, log, warn, actionRunner } = require("../parser");
const { PHP } = require("../type-generation/languages/php");
const { TypeScript } = require("../type-generation/languages/typescript");
const { Kotlin } = require("../type-generation/languages/kotlin");
Expand Down Expand Up @@ -71,7 +71,7 @@ const typesCommand = actionRunner(async (rawOutputDirectory, {language, strict})
}

if (strict) {
log(`Strict mode enabled: Field names will be converted to follow ${language} conventions`);
warn(`Strict mode enabled: Field names will be converted to follow ${language} conventions`);
}

const meta = createLanguageMeta(language);
Expand Down Expand Up @@ -118,7 +118,7 @@ const typesCommand = actionRunner(async (rawOutputDirectory, {language, strict})
collections,
strict,
...templateHelpers,
getType: meta.getType
getType: meta.getType,
});

const destination = singleFileDestination || path.join(outputDirectory, meta.getFileName());
Expand All @@ -128,10 +128,11 @@ const typesCommand = actionRunner(async (rawOutputDirectory, {language, strict})
} else {
for (const collection of collections) {
const content = templater({
collections,
collection,
strict,
...templateHelpers,
getType: meta.getType
getType: meta.getType,
});

const destination = path.join(outputDirectory, meta.getFileName(collection));
Expand Down
4 changes: 2 additions & 2 deletions lib/commands/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ const usersUpdateStatus = async ({userId,status,parseOutput = true, overrideForC
/**
* @typedef {Object} UsersListTargetsRequestParams
* @property {string} userId User ID.
* @property {string[]} queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, email, phone, status, passwordUpdate, registration, emailVerification, phoneVerification, labels
* @property {string[]} queries Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: userId, providerId, identifier, providerType
* @property {boolean} overrideForCli
* @property {boolean} parseOutput
* @property {libClient | undefined} sdk
Expand Down Expand Up @@ -1927,7 +1927,7 @@ users
.command(`list-targets`)
.description(`List the messaging targets that are associated with a user.`)
.requiredOption(`--user-id <user-id>`, `User ID.`)
.option(`--queries [queries...]`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: name, email, phone, status, passwordUpdate, registration, emailVerification, phoneVerification, labels`)
.option(`--queries [queries...]`, `Array of query strings generated using the Query class provided by the SDK. [Learn more about queries](https://appwrite.io/docs/queries). Maximum of 100 queries are allowed, each 4096 characters long. You may filter on the following attributes: userId, providerId, identifier, providerType`)
.action(actionRunner(usersListTargets))

users
Expand Down
2 changes: 1 addition & 1 deletion lib/commands/vcs.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ vcs

vcs
.command(`get-repository-contents`)
.description(`Get a list of files and directories from a GitHub repository connected to your project. This endpoint returns the contents of a specified repository path, including file names, sizes, and whether each item is a file or directory. The GitHub installation must be properly configured and the repository must be accessible through your installation for this endpoint to work. `)
.description(`Get a list of files and directories from a GitHub repository connected to your project. This endpoint returns the contents of a specified repository path, including file names, sizes, and whether each item is a file or directory. The GitHub installation must be properly configured and the repository must be accessible through your installation for this endpoint to work.`)
.requiredOption(`--installation-id <installation-id>`, `Installation Id`)
.requiredOption(`--provider-repository-id <provider-repository-id>`, `Repository Id`)
.option(`--provider-root-directory <provider-root-directory>`, `Path to get contents of nested directory`)
Expand Down
40 changes: 26 additions & 14 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,27 +125,39 @@ class Config {
}

class Local extends Config {
static CONFIG_FILE_PATH = "appwrite.json";
static CONFIG_FILE_PATH = "appwrite.config.json";
static CONFIG_FILE_PATH_LEGACY = "appwrite.json";
configDirectoryPath = ""

constructor(path = Local.CONFIG_FILE_PATH) {
constructor(path = Local.CONFIG_FILE_PATH, legacyPath = Local.CONFIG_FILE_PATH_LEGACY) {
let absolutePath = Local.findConfigFile(path) || Local.findConfigFile(legacyPath);

if (!absolutePath) {
absolutePath = `${process.cwd()}/${path}`;
}

super(absolutePath);
this.configDirectoryPath = _path.dirname(absolutePath);
}

static findConfigFile(filename) {
let currentPath = process.cwd();
let absolutePath = `${currentPath}/${path}`;

while (true) {
if (fs.existsSync(`${currentPath}/${path}`)) {
absolutePath = `${currentPath}/${path}`;
break
} else {
const parentDirectory = _path.dirname(currentPath);
if (parentDirectory === currentPath) { // we hit the top directory
break;
}
currentPath = parentDirectory
const filePath = `${currentPath}/${filename}`;

if (fs.existsSync(filePath)) {
return filePath;
}

const parentDirectory = _path.dirname(currentPath);
if (parentDirectory === currentPath) {
break;
}
currentPath = parentDirectory;
}
super(absolutePath);
this.configDirectoryPath =_path.dirname(absolutePath);

return null;
}

getDirname() {
Expand Down
2 changes: 1 addition & 1 deletion lib/parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const parseError = (err) => {
} catch {
}

const version = '8.2.1';
const version = '8.3.0';
const stepsToReproduce = `Running \`appwrite ${cliConfig.reportData.data.args.join(' ')}\``;
const yourEnvironment = `CLI version: ${version}\nOperation System: ${os.type()}\nAppwrite version: ${appwriteVersion}\nIs Cloud: ${isCloud()}`;

Expand Down
Loading