diff --git a/app/config/collections.php b/app/config/collections.php index ec8cae940c..093b790097 100644 --- a/app/config/collections.php +++ b/app/config/collections.php @@ -1965,7 +1965,7 @@ $collections = [ '$id' => ID::custom('vars'), 'type' => Database::VAR_STRING, 'format' => '', - 'size' => 1000000, + 'size' => 16384, 'signed' => true, 'required' => false, 'default' => null, @@ -3114,7 +3114,7 @@ $collections = [ 'required' => true, 'default' => null, 'array' => false, - 'filters' => [] + 'filters' => [ 'encrypt' ] ] ], 'indexes' => [ @@ -3132,6 +3132,13 @@ $collections = [ 'lengths' => [Database::LENGTH_KEY, Database::LENGTH_KEY], 'orders' => [Database::ORDER_ASC, Database::ORDER_ASC], ], + [ + '$id' => '_key_key', + 'type' => Database::INDEX_KEY, + 'attributes' => ['key'], + 'lengths' => [Database::LENGTH_KEY], + 'orders' => [Database::ORDER_ASC], + ], ], ], ]; diff --git a/app/config/errors.php b/app/config/errors.php index abe5d61c5b..cb005b8d7c 100644 --- a/app/config/errors.php +++ b/app/config/errors.php @@ -529,6 +529,11 @@ return [ 'description' => 'Domain with the requested ID could not be found.', 'code' => 404, ], + Exception::DOMAIN_ALREADY_EXISTS => [ + 'name' => Exception::DOMAIN_ALREADY_EXISTS, + 'description' => 'A Domain with the requested ID already exists.', + 'code' => 409, + ], Exception::VARIABLE_NOT_FOUND => [ 'name' => Exception::VARIABLE_NOT_FOUND, 'description' => 'Variable with the requested ID could not be found.', @@ -539,14 +544,9 @@ return [ 'description' => 'Variable with the same ID already exists in your project.', 'code' => 409, ], - Exception::DOCUMENT_MISSING_PAYLOAD => [ - 'name' => Exception::DOCUMENT_MISSING_PAYLOAD, - 'description' => 'The document payload is missing.', - 'code' => 400, - ], Exception::VARIABLE_MISSING_PAYLOAD => [ 'name' => Exception::VARIABLE_MISSING_PAYLOAD, - 'description' => 'You didn\'t specify either variable key nor value.', + 'description' => 'The variable key or value is missing.', 'code' => 400, ], Exception::DOMAIN_VERIFICATION_FAILED => [ diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index a474601453..fe1628de84 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -82,7 +82,7 @@ App::post('/v1/functions') 'scheduleNext' => null, 'timeout' => $timeout, 'search' => implode(' ', [$functionId, $name, $runtime]), - 'vars' => [] + 'vars' => null ])); $eventsInstance->setParam('functionId', $function->getId()); @@ -1209,20 +1209,22 @@ App::post('/v1/functions/:functionId/variables') } $variable = new Document([ - '$id' => $dbForProject->getId(), - '$read' => ['role:all'], - '$write' => ['role:all'], + '$id' => ID::unique(), + '$permissions' => [ + Permission::read(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), + ], 'functionInternalId' => $function->getInternalId(), 'functionId' => $function->getId(), 'key' => $key, - 'value' => $value, - 'vars' => null + 'value' => $value ]); try { $variable = $dbForProject->createDocument('variables', $variable); } catch (DuplicateException $th) { - throw new Exception('Variable name already used.', 409, Exception::VARIABLE_ALREADY_EXISTS); + throw new Exception('Variable key already used.', 409, Exception::VARIABLE_ALREADY_EXISTS); } $dbForProject->deleteCachedDocument('functions', $function->getId()); @@ -1340,7 +1342,7 @@ App::put('/v1/functions/:functionId/variables/:variableId') try { $dbForProject->updateDocument('variables', $variable->getId(), $variable); } catch (DuplicateException $th) { - throw new Exception('Variable name already used.', 409, Exception::VARIABLE_ALREADY_EXISTS); + throw new Exception('Variable key already used.', 409, Exception::VARIABLE_ALREADY_EXISTS); } $dbForProject->deleteCachedDocument('functions', $function->getId()); diff --git a/docs/references/functions/create-variable.md b/docs/references/functions/create-variable.md index 1bee5894e7..35747c42a6 100644 --- a/docs/references/functions/create-variable.md +++ b/docs/references/functions/create-variable.md @@ -1 +1 @@ -Create a new function variable. These variables can be accessed within functions using the `env` object received through the payload of an execution. \ No newline at end of file +Create a new function variable. These variables can be accessed within function in the `env` object under the request variable. \ No newline at end of file diff --git a/docs/references/functions/list-variables.md b/docs/references/functions/list-variables.md index b939ac92d4..68bd5e17e1 100644 --- a/docs/references/functions/list-variables.md +++ b/docs/references/functions/list-variables.md @@ -1 +1 @@ -Get a list of all variables that are currently active on your function. \ No newline at end of file +Get a list of all variables of a specific function. \ No newline at end of file diff --git a/src/Appwrite/Utopia/Response/Model/Database.php b/src/Appwrite/Utopia/Response/Model/Database.php index 1a98747ac7..317fa6668f 100644 --- a/src/Appwrite/Utopia/Response/Model/Database.php +++ b/src/Appwrite/Utopia/Response/Model/Database.php @@ -23,16 +23,16 @@ class Database extends Model 'example' => 'My Database', ]) ->addRule('$createdAt', [ - 'type' => self::TYPE_INTEGER, - 'description' => 'Collection creation date in Unix timestamp.', - 'default' => 0, - 'example' => 1592981250, + 'type' => self::TYPE_DATETIME, + 'description' => 'Database creation date in Datetime', + 'default' => '', + 'example' => self::TYPE_DATETIME_EXAMPLE, ]) ->addRule('$updatedAt', [ - 'type' => self::TYPE_INTEGER, - 'description' => 'Collection update date in Unix timestamp.', - 'default' => 0, - 'example' => 1592981250, + 'type' => self::TYPE_DATETIME, + 'description' => 'Database update date in Datetime', + 'default' => '', + 'example' => self::TYPE_DATETIME_EXAMPLE, ]) ; } diff --git a/src/Appwrite/Utopia/Response/Model/Token.php b/src/Appwrite/Utopia/Response/Model/Token.php index 5801e6d950..3d666f349e 100644 --- a/src/Appwrite/Utopia/Response/Model/Token.php +++ b/src/Appwrite/Utopia/Response/Model/Token.php @@ -36,7 +36,7 @@ class Token extends Model ]) ->addRule('expire', [ 'type' => self::TYPE_DATETIME, - 'description' => 'Token expiration date in Unix timestamp.', + 'description' => 'Token expiration date in Datetime.', 'default' => '', 'example' => self::TYPE_DATETIME_EXAMPLE, ]) diff --git a/src/Appwrite/Utopia/Response/Model/Variable.php b/src/Appwrite/Utopia/Response/Model/Variable.php index 7afa5dd601..8dbcb44430 100644 --- a/src/Appwrite/Utopia/Response/Model/Variable.php +++ b/src/Appwrite/Utopia/Response/Model/Variable.php @@ -17,16 +17,16 @@ class Variable extends Model 'example' => '5e5ea5c16897e', ]) ->addRule('$createdAt', [ - 'type' => self::TYPE_INTEGER, - 'description' => 'Variable creation date in Unix timestamp.', - 'default' => 0, - 'example' => 1592981250, + 'type' => self::TYPE_DATETIME, + 'description' => 'Variable creation date in Datetime', + 'default' => '', + 'example' => self::TYPE_DATETIME_EXAMPLE, ]) ->addRule('$updatedAt', [ - 'type' => self::TYPE_INTEGER, - 'description' => 'Variable update date in Unix timestamp.', - 'default' => 0, - 'example' => 1592981250, + 'type' => self::TYPE_DATETIME, + 'description' => 'Variable creation date in Datetime', + 'default' => '', + 'example' => self::TYPE_DATETIME_EXAMPLE, ]) ->addRule('key', [ 'type' => self::TYPE_STRING,