1
0
Fork 0
mirror of synced 2024-06-13 08:14:46 +12:00

Implement functions CRUD operations

This commit is contained in:
Matej Bačo 2022-07-20 07:18:49 +00:00
parent 9035db1137
commit 183a18f618
10 changed files with 455 additions and 38 deletions

View file

@ -1940,12 +1940,12 @@ $collections = [
'$id' => 'vars',
'type' => Database::VAR_STRING,
'format' => '',
'size' => 8192,
'size' => 16384,
'signed' => true,
'required' => false,
'default' => [],
'default' => null,
'array' => false,
'filters' => ['json', 'encrypt'],
'filters' => ['subQueryVariables'],
],
[
'$id' => 'events',
@ -2974,6 +2974,74 @@ $collections = [
],
]
],
'variables' => [
'$collection' => Database::METADATA,
'$id' => 'variables',
'name' => 'variables',
'attributes' => [
[
'$id' => 'functionInternalId',
'type' => Database::VAR_STRING,
'format' => '',
'size' => Database::LENGTH_KEY,
'signed' => true,
'required' => false,
'default' => null,
'array' => false,
'filters' => [],
],
[
'$id' => 'functionId',
'type' => Database::VAR_STRING,
'format' => '',
'size' => Database::LENGTH_KEY,
'signed' => true,
'required' => false,
'default' => null,
'array' => false,
'filters' => [],
],
[
'$id' => 'key',
'type' => Database::VAR_STRING,
'format' => '',
'size' => Database::LENGTH_KEY,
'signed' => true,
'required' => false,
'default' => null,
'array' => false,
'filters' => [],
],
[
'$id' => 'value',
'type' => Database::VAR_STRING,
'format' => '',
'size' => 16384,
'signed' => true,
'required' => true,
'default' => null,
'array' => false,
'filters' => []
]
],
'indexes' => [
[
'$id' => '_key_function',
'type' => Database::INDEX_KEY,
'attributes' => ['functionInternalId'],
'lengths' => [Database::LENGTH_KEY],
'orders' => [Database::ORDER_ASC],
],
[
'$id' => '_key_uniqueKey',
'type' => Database::INDEX_UNIQUE,
'attributes' => ['functionInternalId', 'key'],
'lengths' => [Database::LENGTH_KEY, Database::LENGTH_KEY],
'orders' => [Database::ORDER_ASC, Database::ORDER_ASC],
],
],
],
];
return $collections;

View file

@ -502,11 +502,26 @@ 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.',
Exception::VARIABLE_NOT_FOUND => [
'name' => Exception::VARIABLE_NOT_FOUND,
'description' => 'Variable with the requested ID could not be found.',
'code' => 404,
],
Exception::VARIABLE_ALREADY_EXISTS => [
'name' => Exception::VARIABLE_ALREADY_EXISTS,
'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.',
'code' => 400,
],
Exception::DOMAIN_VERIFICATION_FAILED => [
'name' => Exception::DOMAIN_VERIFICATION_FAILED,
'description' => 'Domain verification for the requested domain has failed.',

View file

@ -54,14 +54,13 @@ App::post('/v1/functions')
->param('name', '', new Text(128), 'Function name. Max length: 128 chars.')
->param('execute', [], new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with execution permissions. By default no user is granted with any execute permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed, each 64 characters long.')
->param('runtime', '', new WhiteList(array_keys(Config::getParam('runtimes')), true), 'Execution runtime.')
->param('vars', [], new Assoc(), 'Key-value JSON object that will be passed to the function as environment variables.', true)
->param('events', [], new ArrayList(new ValidatorEvent(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Events list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' events are allowed.', true)
->param('schedule', '', new Cron(), 'Schedule CRON syntax.', true)
->param('timeout', 15, new Range(1, (int) App::getEnv('_APP_FUNCTIONS_TIMEOUT', 900)), 'Function maximum execution time in seconds.', true)
->inject('response')
->inject('dbForProject')
->inject('events')
->action(function (string $functionId, string $name, array $execute, string $runtime, array $vars, array $events, string $schedule, int $timeout, Response $response, Database $dbForProject, Event $eventsInstance) {
->action(function (string $functionId, string $name, array $execute, string $runtime, array $events, string $schedule, int $timeout, Response $response, Database $dbForProject, Event $eventsInstance) {
$functionId = ($functionId == 'unique()') ? $dbForProject->getId() : $functionId;
$function = $dbForProject->createDocument('functions', new Document([
@ -71,7 +70,7 @@ App::post('/v1/functions')
'name' => $name,
'runtime' => $runtime,
'deployment' => '',
'vars' => $vars,
'vars' => null,
'events' => $events,
'schedule' => $schedule,
'schedulePrevious' => 0,
@ -291,7 +290,6 @@ App::put('/v1/functions/:functionId')
->param('functionId', '', new UID(), 'Function ID.')
->param('name', '', new Text(128), 'Function name. Max length: 128 chars.')
->param('execute', [], new Permissions(APP_LIMIT_ARRAY_PARAMS_SIZE), 'An array of strings with execution permissions. By default no user is granted with any execute permissions. [learn more about permissions](https://appwrite.io/docs/permissions) and get a full list of available permissions. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' scopes are allowed, each 64 characters long.')
->param('vars', [], new Assoc(), 'Key-value JSON object that will be passed to the function as environment variables.', true)
->param('events', [], new ArrayList(new ValidatorEvent(), APP_LIMIT_ARRAY_PARAMS_SIZE), 'Events list. Maximum of ' . APP_LIMIT_ARRAY_PARAMS_SIZE . ' events are allowed.', true)
->param('schedule', '', new Cron(), 'Schedule CRON syntax.', true)
->param('timeout', 15, new Range(1, (int) App::getEnv('_APP_FUNCTIONS_TIMEOUT', 900)), 'Maximum execution time in seconds.', true)
@ -300,7 +298,7 @@ App::put('/v1/functions/:functionId')
->inject('project')
->inject('user')
->inject('events')
->action(function (string $functionId, string $name, array $execute, array $vars, array $events, string $schedule, int $timeout, Response $response, Database $dbForProject, Document $project, Document $user, Event $eventsInstance) {
->action(function (string $functionId, string $name, array $execute, array $events, string $schedule, int $timeout, Response $response, Database $dbForProject, Document $project, Document $user, Event $eventsInstance) {
$function = $dbForProject->getDocument('functions', $functionId);
@ -315,7 +313,6 @@ App::put('/v1/functions/:functionId')
$function = $dbForProject->updateDocument('functions', $function->getId(), new Document(array_merge($function->getArrayCopy(), [
'execute' => $execute,
'name' => $name,
'vars' => $vars,
'events' => $events,
'schedule' => $schedule,
'scheduleNext' => (int)$next,

View file

@ -20,6 +20,7 @@ use Utopia\Database\Document;
use Utopia\Database\Query;
use Utopia\Database\Validator\Authorization;
use Utopia\Database\Validator\UID;
use Utopia\Database\Exception\Duplicate as DuplicateException;
use Utopia\Domains\Domain;
use Utopia\Registry\Registry;
use Appwrite\Extend\Exception;
@ -32,7 +33,6 @@ use Utopia\Validator\Text;
use Utopia\Validator\WhiteList;
App::init(function (Document $project) {
if ($project->getId() !== 'console') {
throw new Exception('Access to this API is forbidden.', 401, Exception::GENERAL_ACCESS_FORBIDDEN);
}
@ -1426,3 +1426,246 @@ App::delete('/v1/projects/:projectId/domains/:domainId')
$response->noContent();
});
// Variables
App::post('/v1/projects/:projectId/variables/:functionId')
->desc('Create Variable')
->groups(['api', 'projectsScoped'])
->label('scope', 'projects.write')
->label('sdk.auth', [APP_AUTH_TYPE_ADMIN])
->label('sdk.namespace', 'projects')
->label('sdk.method', 'createVariable')
->label('sdk.response.code', Response::STATUS_CODE_CREATED)
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
->label('sdk.response.model', Response::MODEL_VARIABLE)
->param('projectId', null, new UID(), 'Project unique ID.')
->param('functionId', null, new UID(), 'Function unique ID.', true)
->param('key', null, new Text(255), 'Variable key. Max length: 255 chars.')
->param('value', null, new Text(16384), 'Variable value. Max length: 16384 chars.')
->inject('response')
->inject('dbForConsole')
->inject('dbForProject')
->action(function (string $projectId, string $functionId, string $key, string $value, Response $response, Database $dbForConsole, Database $dbForProject) {
$project = $dbForConsole->getDocument('projects', $projectId);
if ($project->isEmpty()) {
throw new Exception('Project not found', 404, Exception::PROJECT_NOT_FOUND);
}
$function = $dbForProject->getDocument('functions', $functionId);
if ($function->isEmpty()) {
throw new Exception('Function not found', 404, Exception::FUNCTION_NOT_FOUND);
}
$variable = new Document([
'$id' => $dbForProject->getId(),
'$read' => ['role:all'],
'$write' => ['role:all'],
'functionInternalId' => $function->getInternalId(),
'functionId' => $function->getId(),
'key' => $key,
'value' => $value,
]);
try {
$variable = $dbForProject->createDocument('variables', $variable);
} catch (DuplicateException $th) {
throw new Exception('Variable name already used.', 409, Exception::VARIABLE_ALREADY_EXISTS);
}
$dbForProject->deleteCachedDocument('functions', $function->getId());
$response->setStatusCode(Response::STATUS_CODE_CREATED);
$response->dynamic($variable, Response::MODEL_VARIABLE);
});
App::get('/v1/projects/:projectId/variables/:functionId')
->desc('List Variables')
->groups(['api', 'projectsScoped'])
->label('scope', 'projects.read')
->label('sdk.auth', [APP_AUTH_TYPE_ADMIN])
->label('sdk.namespace', 'projects')
->label('sdk.method', 'listVariables')
->label('sdk.response.code', Response::STATUS_CODE_OK)
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
->label('sdk.response.model', Response::MODEL_VARIABLE_LIST)
->param('projectId', null, new UID(), 'Project unique ID.')
->param('functionId', null, new UID(), 'Function unique ID.', true)
// TODO: Pagination
->inject('response')
->inject('dbForConsole')
->inject('dbForProject')
->action(function (string $projectId, string $functionId, Response $response, Database $dbForConsole, Database $dbForProject) {
$project = $dbForConsole->getDocument('projects', $projectId);
if ($project->isEmpty()) {
throw new Exception('Project not found', 404, Exception::PROJECT_NOT_FOUND);
}
$function = $dbForProject->getDocument('functions', $functionId);
if ($function->isEmpty()) {
throw new Exception('Function not found', 404, Exception::FUNCTION_NOT_FOUND);
}
$variables = $dbForProject->find('variables', [
new Query('functionInternalId', Query::TYPE_EQUAL, [$function->getInternalId()]),
], 5000);
$response->dynamic(new Document([
'variables' => $variables,
'total' => count($variables),
]), Response::MODEL_VARIABLE_LIST);
});
App::get('/v1/projects/:projectId/variables/:functionId/:variableId')
->desc('Get Variable')
->groups(['api', 'projectsScoped'])
->label('scope', 'projects.read')
->label('sdk.auth', [APP_AUTH_TYPE_ADMIN])
->label('sdk.namespace', 'projects')
->label('sdk.method', 'getVariable')
->label('sdk.response.code', Response::STATUS_CODE_OK)
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
->label('sdk.response.model', Response::MODEL_VARIABLE)
->param('projectId', null, new UID(), 'Project unique ID.')
->param('functionId', null, new UID(), 'Function unique ID.')
->param('variableId', null, new UID(), 'Variable unique ID.')
->inject('response')
->inject('dbForConsole')
->inject('dbForProject')
->action(function (string $projectId, string $functionId, string $variableId, Response $response, Database $dbForConsole, Database $dbForProject) {
$project = $dbForConsole->getDocument('projects', $projectId);
if ($project->isEmpty()) {
throw new Exception('Project not found', 404, Exception::PROJECT_NOT_FOUND);
}
$function = $dbForProject->getDocument('functions', $functionId);
if ($function->isEmpty()) {
throw new Exception('Function not found', 404, Exception::FUNCTION_NOT_FOUND);
}
$variable = $dbForProject->findOne('variables', [
new Query('_uid', Query::TYPE_EQUAL, [$variableId]),
new Query('functionInternalId', Query::TYPE_EQUAL, [$function->getInternalId()])
]);
if ($variable === false || $variable->isEmpty()) {
throw new Exception('Variable not found', 404, Exception::VARIABLE_NOT_FOUND);
}
$response->dynamic($variable, Response::MODEL_VARIABLE);
});
App::put('/v1/projects/:projectId/variables/:functionId/:variableId')
->desc('Update Variable')
->groups(['api', 'projectsScoped'])
->label('scope', 'projects.write')
->label('sdk.auth', [APP_AUTH_TYPE_ADMIN])
->label('sdk.namespace', 'projects')
->label('sdk.method', 'updateVariable')
->label('sdk.response.code', Response::STATUS_CODE_OK)
->label('sdk.response.type', Response::CONTENT_TYPE_JSON)
->label('sdk.response.model', Response::MODEL_VARIABLE)
->param('projectId', null, new UID(), 'Project unique ID.')
->param('functionId', null, new UID(), 'Function unique ID.')
->param('variableId', null, new UID(), 'Variable unique ID.')
->param('key', null, new Text(255), 'Variable key. Max length: 255 chars.', true)
->param('value', null, new Text(16384), 'Variable value. Max length: 16384 chars.', true)
->inject('response')
->inject('dbForConsole')
->inject('dbForProject')
->action(function (string $projectId, string $functionId, string $variableId, ?string $key, ?string $value, Response $response, Database $dbForConsole, Database $dbForProject) {
if(empty($key) && empty($value)) {
throw new Exception('Missing key or value. Define at least one.', 400, Exception::VARIABLE_MISSING_PAYLOAD);
}
$project = $dbForConsole->getDocument('projects', $projectId);
if ($project->isEmpty()) {
throw new Exception('Project not found', 404, Exception::PROJECT_NOT_FOUND);
}
$function = $dbForProject->getDocument('functions', $functionId);
if ($function->isEmpty()) {
throw new Exception('Function not found', 404, Exception::FUNCTION_NOT_FOUND);
}
$variable = $dbForProject->findOne('variables', [
new Query('_uid', Query::TYPE_EQUAL, [$variableId]),
new Query('functionInternalId', Query::TYPE_EQUAL, [$function->getInternalId()])
]);
if ($variable === false || $variable->isEmpty()) {
throw new Exception('Variable not found', 404, Exception::VARIABLE_NOT_FOUND);
}
$variable
->setAttribute('key', $key ?? $variable->getAttribute('key'))
->setAttribute('value', $value ?? $variable->getAttribute('value'))
;
try {
$dbForProject->updateDocument('variables', $variable->getId(), $variable);
} catch (DuplicateException $th) {
throw new Exception('Variable name already used.', 409, Exception::VARIABLE_ALREADY_EXISTS);
}
$dbForProject->deleteCachedDocument('functions', $function->getId());
$response->dynamic($variable, Response::MODEL_VARIABLE);
});
App::delete('/v1/projects/:projectId/variables/:functionId/:variableId')
->desc('Delete Variable')
->groups(['api', 'projectsScoped'])
->label('scope', 'projects.write')
->label('sdk.auth', [APP_AUTH_TYPE_ADMIN])
->label('sdk.namespace', 'projects')
->label('sdk.method', 'deleteVariable')
->label('sdk.response.code', Response::STATUS_CODE_NOCONTENT)
->label('sdk.response.model', Response::MODEL_NONE)
->param('projectId', null, new UID(), 'Project unique ID.')
->param('functionId', null, new UID(), 'Function unique ID.')
->param('variableId', null, new UID(), 'Variable unique ID.')
->inject('response')
->inject('dbForConsole')
->inject('dbForProject')
->action(function (string $projectId, string $functionId, string $variableId, Response $response, Database $dbForConsole, Database $dbForProject) {
$project = $dbForConsole->getDocument('projects', $projectId);
if ($project->isEmpty()) {
throw new Exception('Project not found', 404, Exception::PROJECT_NOT_FOUND);
}
$function = $dbForProject->getDocument('functions', $functionId);
if ($function->isEmpty()) {
throw new Exception('Function not found', 404, Exception::FUNCTION_NOT_FOUND);
}
$variable = $dbForProject->findOne('variables', [
new Query('_uid', Query::TYPE_EQUAL, [$variableId]),
new Query('functionInternalId', Query::TYPE_EQUAL, [$function->getInternalId()])
]);
if ($variable === false || $variable->isEmpty()) {
throw new Exception('Variable not found', 404, Exception::VARIABLE_NOT_FOUND);
}
$dbForProject->deleteDocument('variables', $variable->getId());
$dbForProject->deleteCachedDocument('functions', $function->getId());
$response->noContent();
});

View file

@ -377,6 +377,27 @@ Database::addFilter(
}
);
Database::addFilter(
'subQueryVariables',
function (mixed $value) {
return null;
},
function (mixed $value, Document $document, Database $database) {
$variables = $database
->find('variables', [
new Query('functionInternalId', Query::TYPE_EQUAL, [$document->getInternalId()]),
], $database->getAttributeLimit(), 0, []);
$object = [];
foreach ($variables as $variable) {
$object[$variable['key']] = $variable['value'];
}
return $object;
}
);
Database::addFilter(
'encrypt',
function (mixed $value) {

39
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "380d806f7540199698d12a7abeb13534",
"content-hash": "677b1b47c8567f0b7b05645e2bbc7bc7",
"packages": [
{
"name": "adhocore/jwt",
@ -2051,16 +2051,16 @@
},
{
"name": "utopia-php/database",
"version": "0.18.7",
"version": "0.18.9",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/database.git",
"reference": "d542ee433f1a545d926ffaf707bdf952dc18a52e"
"reference": "227b3ca919149b7b0d6556c8effe9ee46ed081e6"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/database/zipball/d542ee433f1a545d926ffaf707bdf952dc18a52e",
"reference": "d542ee433f1a545d926ffaf707bdf952dc18a52e",
"url": "https://api.github.com/repos/utopia-php/database/zipball/227b3ca919149b7b0d6556c8effe9ee46ed081e6",
"reference": "227b3ca919149b7b0d6556c8effe9ee46ed081e6",
"shasum": ""
},
"require": {
@ -2109,9 +2109,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/database/issues",
"source": "https://github.com/utopia-php/database/tree/0.18.7"
"source": "https://github.com/utopia-php/database/tree/0.18.9"
},
"time": "2022-07-11T10:20:33+00:00"
"time": "2022-07-19T09:42:53+00:00"
},
{
"name": "utopia-php/domains",
@ -2387,16 +2387,16 @@
},
{
"name": "utopia-php/orchestration",
"version": "dev-cli-lib-upgrade",
"version": "0.6.0",
"source": {
"type": "git",
"url": "https://github.com/utopia-php/orchestration.git",
"reference": "06f2afef516aca900ddb483689ebe6f8e7037d28"
"reference": "94263976413871efb6b16157a7101a81df3b6d78"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/utopia-php/orchestration/zipball/06f2afef516aca900ddb483689ebe6f8e7037d28",
"reference": "06f2afef516aca900ddb483689ebe6f8e7037d28",
"url": "https://api.github.com/repos/utopia-php/orchestration/zipball/94263976413871efb6b16157a7101a81df3b6d78",
"reference": "94263976413871efb6b16157a7101a81df3b6d78",
"shasum": ""
},
"require": {
@ -2436,9 +2436,9 @@
],
"support": {
"issues": "https://github.com/utopia-php/orchestration/issues",
"source": "https://github.com/utopia-php/orchestration/tree/cli-lib-upgrade"
"source": "https://github.com/utopia-php/orchestration/tree/0.6.0"
},
"time": "2022-07-13T14:55:12+00:00"
"time": "2022-07-13T16:47:18+00:00"
},
{
"name": "utopia-php/preloader",
@ -5346,18 +5346,9 @@
"time": "2022-05-17T05:48:52+00:00"
}
],
"aliases": [
{
"package": "utopia-php/orchestration",
"version": "dev-cli-lib-upgrade",
"alias": "0.4.1",
"alias_normalized": "0.4.1.0"
}
],
"aliases": [],
"minimum-stability": "stable",
"stability-flags": {
"utopia-php/orchestration": 20
},
"stability-flags": [],
"prefer-stable": false,
"prefer-lowest": false,
"platform": {

View file

@ -162,6 +162,11 @@ class Exception extends \Exception
/** Keys */
public const KEY_NOT_FOUND = 'key_not_found';
/** Variables */
public const VARIABLE_NOT_FOUND = 'variable_not_found';
public const VARIABLE_ALREADY_EXISTS = 'variable_already_exists';
public const VARIABLE_MISSING_PAYLOAD = 'variable_missing_payload';
/** Platform */
public const PLATFORM_NOT_FOUND = 'platform_not_found';

View file

@ -70,6 +70,7 @@ use Appwrite\Utopia\Response\Model\UsageFunctions;
use Appwrite\Utopia\Response\Model\UsageProject;
use Appwrite\Utopia\Response\Model\UsageStorage;
use Appwrite\Utopia\Response\Model\UsageUsers;
use Appwrite\Utopia\Response\Model\Variable;
/**
* @method Response setStatusCode(int $code = 200)
@ -175,6 +176,8 @@ class Response extends SwooleResponse
public const MODEL_PLATFORM_LIST = 'platformList';
public const MODEL_DOMAIN = 'domain';
public const MODEL_DOMAIN_LIST = 'domainList';
public const MODEL_VARIABLE = 'variable';
public const MODEL_VARIABLE_LIST = 'variableList';
// Health
public const MODEL_HEALTH_STATUS = 'healthStatus';
@ -242,6 +245,7 @@ class Response extends SwooleResponse
->setModel(new BaseList('Currencies List', self::MODEL_CURRENCY_LIST, 'currencies', self::MODEL_CURRENCY))
->setModel(new BaseList('Phones List', self::MODEL_PHONE_LIST, 'phones', self::MODEL_PHONE))
->setModel(new BaseList('Metric List', self::MODEL_METRIC_LIST, 'metrics', self::MODEL_METRIC, true, false))
->setModel(new BaseList('Variables List', self::MODEL_VARIABLE_LIST, 'variables', self::MODEL_VARIABLE, true, false))
// Entities
->setModel(new Database())
->setModel(new Collection())
@ -278,6 +282,7 @@ class Response extends SwooleResponse
->setModel(new Key())
->setModel(new Domain())
->setModel(new Platform())
->setModel(new Variable())
->setModel(new Country())
->setModel(new Continent())
->setModel(new Language())

View file

@ -61,7 +61,7 @@ class Func extends Model
'default' => '',
'example' => '5e5ea5c16897e',
])
->addRule('vars', [
->addRule('vars', [ // TODO: Refactor response model to array (of Variables)
'type' => self::TYPE_JSON,
'description' => 'Function environment variables.',
'default' => new \stdClass(),

View file

@ -0,0 +1,72 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
class Variable extends Model
{
public function __construct()
{
$this
->addRule('$id', [
'type' => self::TYPE_STRING,
'description' => 'Function ID.',
'default' => '',
'example' => '5e5ea5c16897e',
])
->addRule('$createdAt', [
'type' => self::TYPE_INTEGER,
'description' => 'Function creation date in Unix timestamp.',
'default' => 0,
'example' => 1592981250,
])
->addRule('$updatedAt', [
'type' => self::TYPE_INTEGER,
'description' => 'Function update date in Unix timestamp.',
'default' => 0,
'example' => 1592981250,
])
->addRule('key', [
'type' => self::TYPE_STRING,
'description' => 'Variable key.',
'default' => '',
'example' => 'API_KEY',
'array' => false,
])
->addRule('value', [
'type' => self::TYPE_STRING,
'description' => 'Variable value.',
'default' => '',
'example' => 'myPa$$word1',
])
->addRule('functionId', [
'type' => self::TYPE_STRING,
'description' => 'ID of function variable is scoped for.',
'default' => '',
'example' => '5e5ea5c16897e',
])
;
}
/**
* Get Name
*
* @return string
*/
public function getName(): string
{
return 'Variable';
}
/**
* Get Type
*
* @return string
*/
public function getType(): string
{
return Response::MODEL_VARIABLE;
}
}