1
0
Fork 0
mirror of synced 2024-06-03 11:24:48 +12:00

Merge branch 'response-refactor' of github.com:appwrite/appwrite into swoole

This commit is contained in:
Eldad Fux 2020-06-26 12:55:45 +03:00
commit 1fd6dee5f1
31 changed files with 978 additions and 175 deletions

View file

@ -19,6 +19,10 @@
- Added container names to docker-compose.yml (@drandell)
- Upgraded ClamAV container image to version 1.0.9
- Optimised function execution by using fully-qualified function calls
- New and consistent response format for all API object + new response examples in the docs
- Removed user roles attribute from user object (can be fetched from /v1/teams/memberships) **
- Removed type attribute from session object response (used only internally)
- ** - might be changed before merging to master
## Bug Fixes

View file

@ -16,6 +16,7 @@ use Appwrite\Database\Document;
use Appwrite\Database\Validator\Authorization;
use Appwrite\Event\Event;
use Appwrite\Network\Validator\Origin;
use Appwrite\Utopia\Response;
/*
* Configuration files
@ -267,7 +268,6 @@ $utopia->options(function () use ($request, $response) {
});
$utopia->error(function ($error /* @var $error Exception */) use ($request, $response, $utopia, $project) {
$env = Config::getParam('env');
$version = Config::getParam('version');
switch ($error->getCode()) {
@ -289,7 +289,7 @@ $utopia->error(function ($error /* @var $error Exception */) use ($request, $res
$_SERVER = []; // Reset before reporting to error log to avoid keys being compromised
$output = ((App::MODE_TYPE_DEVELOPMENT == $env)) ? [
$output = ($utopia->isDevelopment()) ? [
'message' => $error->getMessage(),
'code' => $error->getCode(),
'file' => $error->getFile(),
@ -334,9 +334,8 @@ $utopia->error(function ($error /* @var $error Exception */) use ($request, $res
$response->send($layout->render());
}
$response
->json($output)
;
$response->dynamic(new Document($output),
$utopia->isDevelopment() ? Response::MODEL_ERROR_DEV : Response::MODEL_LOCALE);
});
$utopia->get('/manifest.json')

View file

@ -4,7 +4,6 @@ global $utopia, $register, $request, $response, $user, $audit,
$webhook, $mail, $project, $projectDB, $clients;
use Utopia\Exception;
use Utopia\Response;
use Utopia\Config\Config;
use Utopia\Validator\Assoc;
use Utopia\Validator\Text;
@ -25,6 +24,7 @@ use Appwrite\Database\Validator\Authorization;
use Appwrite\Template\Template;
use Appwrite\OpenSSL\OpenSSL;
use Appwrite\URL\URL as URLParser;
use Appwrite\Utopia\Response;
use DeviceDetector\DeviceDetector;
use GeoIp2\Database\Reader;
use Utopia\Validator\ArrayList;
@ -132,17 +132,8 @@ $utopia->post('/v1/account')
->setParam('resource', 'users/'.$user->getId())
;
$response
->setStatusCode(Response::STATUS_CODE_CREATED)
->json(\array_merge($user->getArrayCopy(\array_merge(
[
'$id',
'email',
'registration',
'name',
],
$oauth2Keys
)), ['roles' => Authorization::getRoles()]));
$response->setStatusCode(Response::STATUS_CODE_CREATED);
$response->dynamic($user->setAttribute('roles', Authorization::getRoles()), Response::MODEL_USER);
}
);
@ -232,8 +223,9 @@ $utopia->post('/v1/account/sessions')
->addCookie(Auth::$cookieName.'_legacy', Auth::encodeSession($profile->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $protocol), true, null)
->addCookie(Auth::$cookieName, Auth::encodeSession($profile->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $protocol), true, COOKIE_SAMESITE)
->setStatusCode(Response::STATUS_CODE_CREATED)
->json($session->getArrayCopy(['$id', 'type', 'expire']))
;
$response->dynamic($session, Response::MODEL_SESSION);
}
);
@ -541,16 +533,7 @@ $utopia->get('/v1/account')
->label('sdk.response', ['200' => 'user'])
->action(
function () use ($response, &$user, $oauth2Keys) {
$response->json(\array_merge($user->getArrayCopy(\array_merge(
[
'$id',
'email',
'emailVerification',
'registration',
'name',
],
$oauth2Keys
)), ['roles' => Authorization::getRoles()]));
$response->dynamic($user->setAttribute('roles', Authorization::getRoles()), Response::MODEL_USER);
}
);
@ -735,15 +718,7 @@ $utopia->patch('/v1/account/name')
->setParam('resource', 'users/'.$user->getId())
;
$response->json(\array_merge($user->getArrayCopy(\array_merge(
[
'$id',
'email',
'registration',
'name',
],
$oauth2Keys
)), ['roles' => Authorization::getRoles()]));
$response->dynamic($user->setAttribute('roles', Authorization::getRoles()), Response::MODEL_USER);
}
);
@ -778,15 +753,7 @@ $utopia->patch('/v1/account/password')
->setParam('resource', 'users/'.$user->getId())
;
$response->json(\array_merge($user->getArrayCopy(\array_merge(
[
'$id',
'email',
'registration',
'name',
],
$oauth2Keys
)), ['roles' => Authorization::getRoles()]));
$response->dynamic($user->setAttribute('roles', Authorization::getRoles()), Response::MODEL_USER);
}
);
@ -837,15 +804,7 @@ $utopia->patch('/v1/account/email')
->setParam('resource', 'users/'.$user->getId())
;
$response->json(\array_merge($user->getArrayCopy(\array_merge(
[
'$id',
'email',
'registration',
'name',
],
$oauth2Keys
)), ['roles' => Authorization::getRoles()]));
$response->dynamic($user->setAttribute('roles', Authorization::getRoles()), Response::MODEL_USER);
}
);

View file

@ -113,25 +113,6 @@ $utopia->get('/v1/database/collections')
->param('orderType', 'ASC', function () { return new WhiteList(['ASC', 'DESC']); }, 'Order result by ASC or DESC order.', true)
->action(
function ($search, $limit, $offset, $orderType) use ($response, $projectDB) {
/*$vl = new Structure($projectDB);
var_dump($vl->isValid(new Document([
'$collection' => Database::SYSTEM_COLLECTION_RULES,
'$permissions' => [
'read' => ['*'],
'write' => ['*'],
],
'label' => 'Platforms',
'key' => 'platforms',
'type' => 'document',
'default' => [],
'required' => false,
'array' => true,
'options' => [Database::SYSTEM_COLLECTION_PLATFORMS],
])));
var_dump($vl->getDescription());*/
$results = $projectDB->getCollection([
'limit' => $limit,
'offset' => $offset,
@ -360,7 +341,7 @@ $utopia->post('/v1/database/collections/:collectionId/documents')
->param('write', [], function () { return new ArrayList(new Text(64)); }, 'An array of strings with write permissions. By default no user is granted with any write permissions. [learn more about permissions](/docs/permissions) and get a full list of available permissions.')
->param('parentDocument', '', function () { return new UID(); }, 'Parent document unique ID. Use when you want your new document to be a child of a parent document.', true)
->param('parentProperty', '', function () { return new Key(); }, 'Parent document property name. Use when you want your new document to be a child of a parent document.', true)
->param('parentPropertyType', Document::SET_TYPE_ASSIGN, function () { return new WhiteList([Document::SET_TYPE_ASSIGN, Document::SET_TYPE_APPEND, Document::SET_TYPE_PREPEND]); }, 'Parent document property connection type. You can set this value to **assign**, **append** or **prepend**, default value is assign. Use when you want your new document to be a child of a parent document.', true)
->param('parentPropertyType', Document::SET_TYPE_ASSIGN, function () { return new WhiteList([Document::SET_TYPE_ASSIGN, Document::SET_TYPE_APPEND, Document::SET_TYPE_PREPEND]); }, 'Parent document property connection type. You can set this value to **assign**, **append** or **prepend**, default value is assign. **append** or **prepend** should be set when the parent property is array. Use when you want your new document to be a child of a parent document.', true)
->action(
function ($collectionId, $data, $read, $write, $parentDocument, $parentProperty, $parentPropertyType) use ($response, $projectDB, $webhook, $audit) {
$data = (\is_string($data)) ? \json_decode($data, true) : $data; // Cast to JSON array

View file

@ -2,6 +2,8 @@
global $utopia, $register, $request, $response, $projectDB, $project, $user, $audit;
use Appwrite\Database\Document;
use Appwrite\Utopia\Response;
use Utopia\App;
use Utopia\Locale\Locale;
use GeoIp2\Database\Reader;
@ -42,7 +44,7 @@ $utopia->get('/v1/locale')
$output['continentCode'] = $record->continent->code;
$output['eu'] = (\in_array($record->country->isoCode, $eu)) ? true : false;
foreach ($currencies as $code => $element) {
foreach ($currencies as $element) {
if (isset($element['locations']) && isset($element['code']) && \in_array($record->country->isoCode, $element['locations'])) {
$currency = $element['code'];
}
@ -61,7 +63,9 @@ $utopia->get('/v1/locale')
$response
->addHeader('Cache-Control', 'public, max-age='.$time)
->addHeader('Expires', \date('D, d M Y H:i:s', \time() + $time).' GMT') // 45 days cache
->json($output);
;
$response->dynamic(new Document($output), Response::MODEL_LOCALE);
}
);

View file

@ -3,7 +3,6 @@
global $utopia, $register, $request, $response, $projectDB, $project, $user, $audit, $mail, $mode, $clients;
use Utopia\Exception;
use Utopia\Response;
use Utopia\Config\Config;
use Utopia\Validator\Email;
use Utopia\Validator\Text;
@ -19,6 +18,7 @@ use Appwrite\Database\Validator\UID;
use Appwrite\Database\Validator\Authorization;
use Appwrite\Database\Exception\Duplicate;
use Appwrite\Template\Template;
use Appwrite\Utopia\Response;
$utopia->post('/v1/teams')
->desc('Create Team')
@ -77,10 +77,8 @@ $utopia->post('/v1/teams')
}
}
$response
->setStatusCode(Response::STATUS_CODE_CREATED)
->json($team->getArrayCopy())
;
$response->setStatusCode(Response::STATUS_CODE_CREATED);
$response->dynamic($team, Response::MODEL_TEAM);
}
);
@ -110,7 +108,10 @@ $utopia->get('/v1/teams')
],
]);
$response->json(['sum' => $projectDB->getSum(), 'teams' => $results]);
$response->dynamic(new Document([
'sum' => $projectDB->getSum(),
'teams' => $results
]), Response::MODEL_TEAM_LIST);
}
);
@ -131,7 +132,7 @@ $utopia->get('/v1/teams/:teamId')
throw new Exception('Team not found', 404);
}
$response->json($team->getArrayCopy([]));
$response->dynamic($team, Response::MODEL_TEAM);
}
);
@ -161,7 +162,7 @@ $utopia->put('/v1/teams/:teamId')
throw new Exception('Failed saving team to DB', 500);
}
$response->json($team->getArrayCopy());
$response->dynamic($team, Response::MODEL_TEAM);
}
);
@ -364,21 +365,12 @@ $utopia->post('/v1/teams/:teamId/memberships')
->setParam('resource', 'teams/'.$teamId)
;
$response
->setStatusCode(Response::STATUS_CODE_CREATED) // TODO change response of this endpoint
->json(\array_merge($membership->getArrayCopy([
'$id',
'userId',
'teamId',
'roles',
'invited',
'joined',
'confirm',
]), [
'email' => $email,
'name' => $name,
]))
;
$response->setStatusCode(Response::STATUS_CODE_CREATED); // TODO change response of this endpoint
$response->dynamic(new Document(\array_merge($membership->getArrayCopy(), [
'email' => $email,
'name' => $name,
])), Response::MODEL_MEMBERSHIP);
}
);
@ -425,18 +417,10 @@ $utopia->get('/v1/teams/:teamId/memberships')
$temp = $projectDB->getDocument($membership->getAttribute('userId', null))->getArrayCopy(['email', 'name']);
$users[] = \array_merge($temp, $membership->getArrayCopy([
'$id',
'userId',
'teamId',
'roles',
'invited',
'joined',
'confirm',
]));
$users[] = new Document(\array_merge($temp, $membership->getArrayCopy()));
}
$response->json(['sum' => $projectDB->getSum(), 'memberships' => $users]);
$response->dynamic(new Document(['sum' => $projectDB->getSum(), 'memberships' => $users]), Response::MODEL_MEMBERSHIP_LIST);
}
);
@ -557,19 +541,12 @@ $utopia->patch('/v1/teams/:teamId/memberships/:inviteId/status')
$response
->addCookie(Auth::$cookieName.'_legacy', Auth::encodeSession($user->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $protocol), true, null)
->addCookie(Auth::$cookieName, Auth::encodeSession($user->getId(), $secret), $expiry, '/', COOKIE_DOMAIN, ('https' == $protocol), true, COOKIE_SAMESITE)
->json(\array_merge($membership->getArrayCopy([
'$id',
'userId',
'teamId',
'roles',
'invited',
'joined',
'confirm',
]), [
'email' => $user->getAttribute('email'),
'name' => $user->getAttribute('name'),
]))
;
$response->dynamic(new Document(\array_merge($membership->getArrayCopy(), [
'email' => $user->getAttribute('email'),
'name' => $user->getAttribute('name'),
])), Response::MODEL_MEMBERSHIP);
}
);
@ -623,4 +600,4 @@ $utopia->delete('/v1/teams/:teamId/memberships/:inviteId')
$response->noContent();
}
);
);

View file

@ -3,7 +3,6 @@
global $utopia, $response, $projectDB;
use Utopia\Exception;
use Utopia\Response;
use Utopia\Validator\Assoc;
use Utopia\Validator\WhiteList;
use Utopia\Validator\Email;
@ -18,6 +17,7 @@ use Appwrite\Auth\Validator\Password;
use Appwrite\Database\Database;
use Appwrite\Database\Exception\Duplicate;
use Appwrite\Database\Validator\UID;
use Appwrite\Utopia\Response;
use DeviceDetector\DeviceDetector;
use GeoIp2\Database\Reader;
@ -78,16 +78,8 @@ $utopia->post('/v1/users')
$oauth2Keys[] = 'oauth2'.\ucfirst($key).'AccessToken';
}
$response
->setStatusCode(Response::STATUS_CODE_CREATED)
->json(\array_merge($user->getArrayCopy(\array_merge([
'$id',
'status',
'email',
'registration',
'emailVerification',
'name',
], $oauth2Keys)), ['roles' => []]));
$response->setStatusCode(Response::STATUS_CODE_CREATED);
$response->dynamic($user, Response::MODEL_USER);
}
);

View file

@ -307,27 +307,27 @@ $utopia->get('/open-api-2.json')
'securityDefinitions' => $keys[$platform],
'paths' => [],
'definitions' => [
// 'Pet' => [
// 'required' => ['id', 'name'],
// 'properties' => [
// 'id' => [
// 'type' => 'integer',
// 'format' => 'int64',
// ],
// 'name' => [
// 'type' => 'string',
// ],
// 'tag' => [
// 'type' => 'string',
// ],
// ],
// ],
// 'Pets' => array(
// 'type' => 'array',
// 'items' => array(
// '$ref' => '#/definitions/Pet',
// ),
// ),
'Pet' => [
'required' => ['id', 'name'],
'properties' => [
'id' => [
'type' => 'integer',
'format' => 'int64',
],
'name' => [
'type' => 'string',
],
'tag' => [
'type' => 'string',
],
],
],
'Pets' => array(
'type' => 'array',
'items' => array(
'$ref' => '#/definitions/Pet',
),
),
'Error' => array(
'required' => array(
0 => 'code',
@ -400,14 +400,14 @@ $utopia->get('/open-api-2.json')
'tags' => [$route->getLabel('sdk.namespace', 'default')],
'description' => ($desc) ? \file_get_contents($desc) : '',
// 'responses' => [
// 200 => [
// 'description' => 'An paged array of pets',
// 'schema' => [
// '$ref' => '#/definitions/Pet',
// ],
// ],
// ],
'responses' => [
200 => [
'description' => 'An paged array of pets',
'schema' => [
'$ref' => '#/definitions/Pet',
],
],
],
];
if ($extensions) {
@ -550,10 +550,6 @@ $utopia->get('/open-api-2.json')
}
}
/*foreach ($consoleDB->getMocks() as $mock) {
var_dump($mock['name']);
}*/
\ksort($output['paths']);
$response

View file

@ -13,7 +13,6 @@ if (\file_exists(__DIR__.'/../vendor/autoload.php')) {
use Utopia\App;
use Utopia\Request;
use Utopia\Response;
use Utopia\Config\Config;
use Utopia\Locale\Locale;
use Utopia\Registry\Registry;
@ -23,6 +22,7 @@ use Appwrite\Database\Document;
use Appwrite\Database\Validator\Authorization;
use Appwrite\Database\Adapter\MySQL as MySQLAdapter;
use Appwrite\Database\Adapter\Redis as RedisAdapter;
use Appwrite\Utopia\Response;
use PHPMailer\PHPMailer\PHPMailer;
const APP_NAME = 'Appwrite';

View file

@ -23,6 +23,7 @@
"ext-imagick": "*",
"ext-mbstring": "*",
"ext-json": "*",
"ext-yaml": "*",
"ext-dom": "*",
"ext-redis": "*",
"ext-pdo": "*",

View file

@ -320,7 +320,7 @@
var _date = function (format, timestamp) {
jsdate = (timestamp === undefined ? new Date() // Not provided
: (timestamp instanceof Date) ? new Date(timestamp) // JS Date()
: new Date(timestamp * 1000) // UNIX timestamp (auto-convert to int)
: new Date(timestamp * 1000) // Unix timestamp (auto-convert to int)
)
return format.replace(formatChr, formatChrCb)
}

View file

@ -127,7 +127,7 @@ abstract class Adapter
/**
* Last Modified.
*
* Return unix timestamp of last time a node queried in corrent session has been changed
* Return Unix timestamp of last time a node queried in corrent session has been changed
*
* @return int
*/

View file

@ -774,7 +774,7 @@ class MySQL extends Adapter
/**
* Last Modified.
*
* Return unix timestamp of last time a node queried in corrent session has been changed
* Return Unix timestamp of last time a node queried in corrent session has been changed
*
* @return int
*/

View file

@ -221,7 +221,7 @@ class Redis extends Adapter
/**
* Last Modified.
*
* Return unix timestamp of last time a node queried in current session has been changed
* Return Unix timestamp of last time a node queried in current session has been changed
*
* @return int
*/

View file

@ -367,7 +367,7 @@ class Database
/**
* Get Last Modified.
*
* Return unix timestamp of last time a node queried in current session has been changed
* Return Unix timestamp of last time a node queried in current session has been changed
*
* @return int
*/

View file

@ -25,11 +25,11 @@ class Document extends ArrayObject
{
foreach ($input as $key => &$value) {
if (\is_array($value)) {
if (isset($value['$id']) || isset($value['$collection'])) {
if ((isset($value['$id']) || isset($value['$collection'])) && (!$value instanceof self)) {
$input[$key] = new self($value);
} else {
foreach ($value as $childKey => $child) {
if (isset($child['$id']) || isset($child['$collection'])) {
if ((isset($child['$id']) || isset($child['$collection'])) && (!$child instanceof self)) {
$value[$childKey] = new self($child);
}
}
@ -193,6 +193,18 @@ class Document extends ArrayObject
return empty($this->getId());
}
/**
* Checks if a document key is set.
*
* @param $key
*
* @return bool
*/
public function isSet($key)
{
return isset($this[$key]);
}
/**
* Get Array Copy.
*

View file

@ -0,0 +1,171 @@
<?php
namespace Appwrite\Utopia;
use Exception;
use Appwrite\Database\Document;
use Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response\Model\Error;
use Appwrite\Utopia\Response\Model\ErrorDev;
use Appwrite\Utopia\Response\Model\User;
use Appwrite\Utopia\Response\Model\Session;
use Appwrite\Utopia\Response\Model\Team;
use Appwrite\Utopia\Response\Model\TeamList;
use Appwrite\Utopia\Response\Model\Locale;
use Appwrite\Utopia\Response\Model\Membership;
use Appwrite\Utopia\Response\Model\MembershipList;
use Utopia\Response as UtopiaResponse;
class Response extends UtopiaResponse
{
// General
const MODEL_LOG = 'log'; // - Missing
const MODEL_ERROR = 'error';
const MODEL_ERROR_DEV = 'errorDev';
const MODEL_BASE_LIST = 'baseList';
// Users
const MODEL_USER = 'user';
const MODEL_SESSION = 'session';
const MODEL_TOKEN = 'token'; // - Missing
// Database
const MODEL_COLLECTION = 'collection'; // - Missing
// Locale
const MODEL_LOCALE = 'locale';
const MODEL_COUNTRY = 'country'; // - Missing
const MODEL_CONTINENT = 'continent'; // - Missing
const MODEL_CURRENCY = 'currency'; // - Missing
const MODEL_LANGUAGE = 'langauge'; // - Missing
const MODEL_PHONE = 'phone'; // - Missing
// Storage
const MODEL_FILE = 'file'; // - Missing
const MODEL_BUCKET = 'bucket'; // - Missing
// Teams
const MODEL_TEAM = 'team';
const MODEL_TEAM_LIST = 'teamList';
const MODEL_MEMBERSHIP = 'membership';
const MODEL_MEMBERSHIP_LIST = 'membershipList';
public function __construct()
{
$this
->setModel(new Error())
->setModel(new ErrorDev())
->setModel(new User())
->setModel(new Session())
->setModel(new Locale())
->setModel(new Team())
->setModel(new TeamList())
->setModel(new Membership())
->setModel(new MembershipList())
;
}
/**
* HTTP content types
*/
const CONTENT_TYPE_YAML = 'application/x-yaml';
/**
* List of defined output objects
*/
protected $models = [];
/**
* Set Model Object
*
* @return self
*/
public function setModel(Model $instance): self
{
$this->models[$instance->getType()] = $instance;
return $this;
}
/**
* Get Model Object
*
* @return Model
*/
public function getModel(string $key): Model
{
if(!isset($this->models[$key])) {
throw new Exception('Undefined model: '.$key);
}
return $this->models[$key];
}
/**
* Validate response objects and outputs
* the response according to given format type
*/
public function dynamic(Document $document, string $model)
{
return $this->json($this->output($document, $model));
}
/**
* Generate valid response object from document data
*/
protected function output(Document $document, string $model): array
{
$data = $document;
$model = $this->getModel($model);
$output = [];
foreach($model->getRules() as $key => $rule) {
if(!$document->isSet($key)) {
if(!is_null($rule['default'])) {
$document->setAttribute($key, $rule['default']);
}
else {
throw new Exception('Missing response key: '.$key);
}
}
if($rule['array']) {
if(!is_array($data[$key])) {
throw new Exception($key.' must be an array of '.$rule['type'].' types');
}
foreach ($data[$key] as &$item) {
if(array_key_exists($rule['type'], $this->models) && $item instanceof Document) {
$item = $this->output($item, $rule['type']);
}
}
}
$output[$key] = $data[$key];
}
return $output;
}
/**
* YAML
*
* This helper is for sending YAML HTTP response.
* It sets relevant content type header ('application/x-yaml') and convert a PHP array ($data) to valid YAML using native yaml_parse
*
* @see https://en.wikipedia.org/wiki/YAML
*
* @param array $data
*/
public function yaml(array $data)
{
if(!extension_loaded('yaml')) {
throw new Exception('Missing yaml extension. Learn more at: https://www.php.net/manual/en/book.yaml.php');
}
$this
->setContentType(Response::CONTENT_TYPE_YAML)
->send(yaml_emit($data, YAML_UTF8_ENCODING))
;
}
}

View file

@ -0,0 +1,48 @@
<?php
namespace Appwrite\Utopia\Response;
abstract class Model
{
protected $rules = [];
/**
* Get Name
*
* @return string
*/
abstract public function getName():string;
/**
* Get Collection
*
* @return string
*/
abstract public function getType():string;
/**
* Get Rules
*
* @return string
*/
public function getRules(): array
{
return $this->rules;
}
/**
* Add a New Rule
*/
protected function addRule(string $key, array $options): self
{
$this->rules[$key] = array_merge([
'type' => '',
'description' => '',
'default' => null,
'example' => '',
'array' => false,
], $options);
return $this;
}
}

View file

@ -0,0 +1,40 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
abstract class BaseList extends Model
{
public function __construct()
{
$this
->addRule('sum', [
'type' => 'integer',
'description' => 'Total sum of items in the list.',
'example' => '5',
])
;
}
/**
* Get Name
*
* @return string
*/
public function getName():string
{
return 'Base List';
}
/**
* Get Collection
*
* @return string
*/
public function getType():string
{
return Response::MODEL_BASE_LIST;
}
}

View file

@ -0,0 +1,50 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
class Error extends Model
{
public function __construct()
{
$this
->addRule('message', [
'type' => 'string',
'description' => 'Error message.',
'example' => 'Not found',
])
->addRule('code', [
'type' => 'string',
'description' => 'Error code.',
'example' => '404',
])
->addRule('version', [
'type' => 'string',
'description' => 'Server version number.',
'example' => APP_VERSION_STABLE,
])
;
}
/**
* Get Name
*
* @return string
*/
public function getName():string
{
return 'Error';
}
/**
* Get Collection
*
* @return string
*/
public function getType():string
{
return Response::MODEL_ERROR;
}
}

View file

@ -0,0 +1,43 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
class ErrorDev extends Error
{
public function __construct()
{
parent::__construct();
$this
->addRule('file', [
'type' => 'string',
'description' => 'File path.',
'example' => '/usr/share/nginx/html/vendor/utopia-php/framework/src/App.php',
])
->addRule('line', [
'type' => 'integer',
'description' => 'Line number.',
'example' => 209,
])
// ->addRule('trace', [
// 'type' => 'string',
// 'description' => 'Error trace.',
// 'example' => [
// ''
// ],
// ])
;
}
/**
* Get Collection
*
* @return string
*/
public function getType():string
{
return Response::MODEL_ERROR_DEV;
}
}

View file

@ -0,0 +1,34 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
class File extends Model
{
public function __construct()
{
}
/**
* Get Name
*
* @return string
*/
public function getName():string
{
return 'File';
}
/**
* Get Collection
*
* @return string
*/
public function getType():string
{
return Response::MODEL_LOCALE;
}
}

View file

@ -0,0 +1,72 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
class Locale extends Model
{
public function __construct()
{
$this
->addRule('ip', [
'type' => 'string',
'description' => 'User IP address.',
'example' => '127.0.0.1',
])
->addRule('countryCode', [
'type' => 'string',
'description' => 'Country code in [ISO 3166-1](http://en.wikipedia.org/wiki/ISO_3166-1) two-character format',
'example' => 'US',
])
->addRule('country', [
'type' => 'string',
'description' => 'Country name. This field support localization.',
'example' => 'United States',
])
->addRule('continentCode', [
'type' => 'string',
'description' => 'Continent code. A two character continent code "AF" for Africa, "AN" for Antarctica, "AS" for Asia, "EU" for Europe, "NA" for North America, "OC" for Oceania, and "SA" for South America.',
'example' => 'NA',
])
->addRule('continent', [
'type' => 'string',
'description' => 'Continent name. This field support localization.',
'example' => 'North America',
])
->addRule('eu', [
'type' => 'Boolean',
'description' => 'True if country is part of the Europian Union.',
'default' => false,
'example' => false,
])
->addRule('currency', [
'type' => 'string',
'description' => 'ISO 4217 Email verification status.',
'description' => 'Currency code in [ISO 4217-1](http://en.wikipedia.org/wiki/ISO_4217) three-character format',
'example' => 'USD',
])
;
}
/**
* Get Name
*
* @return string
*/
public function getName():string
{
return 'Locale';
}
/**
* Get Collection
*
* @return string
*/
public function getType():string
{
return Response::MODEL_LOCALE;
}
}

View file

@ -0,0 +1,33 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
class Log extends Model
{
public function __construct()
{
}
/**
* Get Name
*
* @return string
*/
public function getName():string
{
return 'Session';
}
/**
* Get Collection
*
* @return string
*/
public function getType():string
{
return Response::MODEL_LOCALE;
}
}

View file

@ -0,0 +1,84 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
class Membership extends Model
{
public function __construct()
{
$this
->addRule('$id', [
'type' => 'string',
'description' => 'Membership ID.',
'example' => '5e5ea5c16897e',
])
->addRule('userId', [
'type' => 'string',
'description' => 'User ID.',
'example' => '5e5ea5c16897e',
])
->addRule('teamId', [
'type' => 'string',
'description' => 'Team ID.',
'example' => '5e5ea5c16897e',
])
->addRule('name', [
'type' => 'string',
'description' => 'User name.',
'default' => '',
'example' => 'VIP',
])
->addRule('email', [
'type' => 'string',
'description' => 'User email address.',
'default' => '',
'example' => 'john@appwrite.io',
])
->addRule('invited', [
'type' => 'integer',
'description' => 'Date, the user has been invited to join the team in Unix timestamp.',
'example' => 1592981250,
])
->addRule('joined', [
'type' => 'integer',
'description' => 'Date, the user has accepted the invitation to join the team in Unix timestamp.',
'example' => 1592981250,
])
->addRule('confirm', [
'type' => 'boolean',
'description' => 'User confirmation status, true if the user has joined the team or false otherwise.',
'example' => false,
])
->addRule('roles', [
'type' => 'string',
'description' => 'User list of roles',
'default' => [],
'example' => [],
'array' => true,
])
;
}
/**
* Get Name
*
* @return string
*/
public function getName():string
{
return 'Membership';
}
/**
* Get Collection
*
* @return string
*/
public function getType():string
{
return Response::MODEL_MEMBERSHIP;
}
}

View file

@ -0,0 +1,41 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
class MembershipList extends BaseList
{
public function __construct()
{
parent::__construct();
$this
->addRule('memberships', [
'type' => Response::MODEL_MEMBERSHIP,
'description' => 'List of memberships.',
'example' => [],
'array' => true,
])
;
}
/**
* Get Name
*
* @return string
*/
public function getName():string
{
return 'Membership List';
}
/**
* Get Collection
*
* @return string
*/
public function getType():string
{
return Response::MODEL_MEMBERSHIP_LIST;
}
}

View file

@ -0,0 +1,50 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
class Session extends Model
{
public function __construct()
{
$this
->addRule('$id', [
'type' => 'string',
'description' => 'Session ID.',
'example' => '5e5ea5c16897e',
])
->addRule('expire', [
'type' => 'string',
'description' => 'Session expiration date in Unix timestamp.',
'example' => 1592981250,
])
->addRule('ip', [
'type' => 'string',
'description' => 'IP session in use when the session was created.',
'example' => '127.0.0.1',
])
;
}
/**
* Get Name
*
* @return string
*/
public function getName():string
{
return 'Session';
}
/**
* Get Collection
*
* @return string
*/
public function getType():string
{
return Response::MODEL_SESSION;
}
}

View file

@ -0,0 +1,56 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
class Team extends Model
{
public function __construct()
{
$this
->addRule('$id', [
'type' => 'string',
'description' => 'Team ID.',
'example' => '5e5ea5c16897e',
])
->addRule('name', [
'type' => 'string',
'description' => 'Team name.',
'default' => '',
'example' => 'VIP',
])
->addRule('dateCreated', [
'type' => 'integer',
'description' => 'Team creation date in Unix timestamp.',
'example' => 1592981250,
])
->addRule('sum', [ // TODO change key name?
'type' => 'integer',
'description' => 'Total sum of team members.',
'example' => 7,
])
;
}
/**
* Get Name
*
* @return string
*/
public function getName():string
{
return 'Team';
}
/**
* Get Collection
*
* @return string
*/
public function getType():string
{
return Response::MODEL_TEAM;
}
}

View file

@ -0,0 +1,41 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
class TeamList extends BaseList
{
public function __construct()
{
parent::__construct();
$this
->addRule('teams', [
'type' => Response::MODEL_TEAM,
'description' => 'List of teams.',
'example' => [],
'array' => true,
])
;
}
/**
* Get Name
*
* @return string
*/
public function getName():string
{
return 'Team List';
}
/**
* Get Collection
*
* @return string
*/
public function getType():string
{
return Response::MODEL_TEAM_LIST;
}
}

View file

@ -0,0 +1,33 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
class Token extends Model
{
public function __construct()
{
}
/**
* Get Name
*
* @return string
*/
public function getName():string
{
return 'User';
}
/**
* Get Collection
*
* @return string
*/
public function getType():string
{
return Response::MODEL_LOCALE;
}
}

View file

@ -0,0 +1,82 @@
<?php
namespace Appwrite\Utopia\Response\Model;
use Appwrite\Utopia\Response;
use Appwrite\Utopia\Response\Model;
class User extends Model
{
public function __construct()
{
$this
->addRule('$id', [
'type' => 'string',
'description' => 'User ID.',
'example' => '5e5ea5c16897e',
])
->addRule('name', [
'type' => 'string',
'description' => 'User name.',
'default' => '',
'example' => 'John Doe',
])
->addRule('registration', [
'type' => 'integer',
'description' => 'User registration date in Unix timestamp.',
'example' => 1592981250,
])
->addRule('status', [
'type' => 'integer',
'description' => 'User status. 0 for Unavtivated, 1 for active and 2 is blocked.',
'default' => false,
'example' => true,
])
->addRule('email', [
'type' => 'string',
'description' => 'User email address.',
'default' => '',
'example' => 'john@appwrite.io',
])
->addRule('emailVerification', [
'type' => 'boolean',
'description' => 'Email verification status.',
'default' => false,
'example' => true,
])
->addRule('prefs', [
'type' => 'json',
'description' => 'User preferences as a key-value object',
'default' => new \stdClass,
'example' => ['theme' => 'dark', 'timezone' => 'UTC'],
])
->addRule('roles', [
'type' => 'string',
'description' => 'User list of roles',
'default' => [],
'example' => [],
'array' => true,
])
;
}
/**
* Get Name
*
* @return string
*/
public function getName():string
{
return 'User';
}
/**
* Get Collection
*
* @return string
*/
public function getType():string
{
return Response::MODEL_USER;
}
}