mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
fix(executions): localize query attributes
Co-authored-by: Torsten Dittmann <TorstenDittmann@users.noreply.github.com>
This commit is contained in:
1 parent
484b8b5aa2
commit
52a1d0bfb6
3 files changed
+73
-25
No files matched your search
@@ -18,24 +18,22 @@ class Base extends Queries
|
||||
/**
|
||||
* Expression constructor
|
||||
*
|
||||
* @param string|array<string, mixed> $collection
|
||||
* @param string $collection
|
||||
* @param string[] $allowedAttributes
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function __construct(string|array $collection, array $allowedAttributes)
|
||||
public function __construct(string $collection, array $allowedAttributes)
|
||||
{
|
||||
if (\is_string($collection)) {
|
||||
$config = Config::getParam('collections', []);
|
||||
$config = Config::getParam('collections', []);
|
||||
|
||||
$collections = \array_merge(
|
||||
$config['projects'],
|
||||
$config['buckets'],
|
||||
$config['databases'],
|
||||
$config['console']
|
||||
);
|
||||
$collections = \array_merge(
|
||||
$config['projects'],
|
||||
$config['buckets'],
|
||||
$config['databases'],
|
||||
$config['console']
|
||||
);
|
||||
|
||||
$collection = $collections[$collection];
|
||||
}
|
||||
$collection = $collections[$collection];
|
||||
|
||||
$allowedAttributesLookup = [];
|
||||
foreach ($allowedAttributes as $attribute) {
|
||||
|
||||
@@ -3,17 +3,24 @@
|
||||
namespace Appwrite\Utopia\Database\Validator\Queries;
|
||||
|
||||
use Utopia\Database\Database;
|
||||
use Utopia\Database\Document;
|
||||
use Utopia\Database\Validator\Queries;
|
||||
use Utopia\Database\Validator\Query\Cursor;
|
||||
use Utopia\Database\Validator\Query\Filter;
|
||||
use Utopia\Database\Validator\Query\Limit;
|
||||
use Utopia\Database\Validator\Query\Offset;
|
||||
use Utopia\Database\Validator\Query\Order;
|
||||
|
||||
class Executions extends Base
|
||||
class Executions extends Queries
|
||||
{
|
||||
public const ATTRIBUTES = [
|
||||
['$id' => 'trigger', 'type' => Database::VAR_STRING, 'array' => false],
|
||||
['$id' => 'status', 'type' => Database::VAR_STRING, 'array' => false],
|
||||
['$id' => 'responseStatusCode', 'type' => Database::VAR_INTEGER, 'array' => false],
|
||||
['$id' => 'duration', 'type' => Database::VAR_FLOAT, 'array' => false],
|
||||
['$id' => 'requestMethod', 'type' => Database::VAR_STRING, 'array' => false],
|
||||
['$id' => 'requestPath', 'type' => Database::VAR_STRING, 'array' => false],
|
||||
['$id' => 'deploymentId', 'type' => Database::VAR_STRING, 'array' => false],
|
||||
protected const ATTRIBUTE_TYPES = [
|
||||
'trigger' => Database::VAR_STRING,
|
||||
'status' => Database::VAR_STRING,
|
||||
'responseStatusCode' => Database::VAR_INTEGER,
|
||||
'duration' => Database::VAR_FLOAT,
|
||||
'requestMethod' => Database::VAR_STRING,
|
||||
'requestPath' => Database::VAR_STRING,
|
||||
'deploymentId' => Database::VAR_STRING,
|
||||
];
|
||||
|
||||
public const ALLOWED_ATTRIBUTES = [
|
||||
@@ -30,8 +37,51 @@ class Executions extends Base
|
||||
* Expression constructor
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
public function __construct(array $allowedAttributes = self::ALLOWED_ATTRIBUTES)
|
||||
{
|
||||
parent::__construct(['attributes' => self::ATTRIBUTES], self::ALLOWED_ATTRIBUTES);
|
||||
$attributes = [];
|
||||
foreach ($allowedAttributes as $attribute) {
|
||||
$attributes[] = new Document([
|
||||
'key' => $attribute,
|
||||
'type' => self::ATTRIBUTE_TYPES[$attribute],
|
||||
'array' => false,
|
||||
]);
|
||||
}
|
||||
|
||||
$attributes = [
|
||||
...$attributes,
|
||||
new Document([
|
||||
'key' => '$id',
|
||||
'type' => Database::VAR_STRING,
|
||||
'array' => false,
|
||||
]),
|
||||
new Document([
|
||||
'key' => '$createdAt',
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'array' => false,
|
||||
]),
|
||||
new Document([
|
||||
'key' => '$updatedAt',
|
||||
'type' => Database::VAR_DATETIME,
|
||||
'array' => false,
|
||||
]),
|
||||
new Document([
|
||||
'key' => '$sequence',
|
||||
'type' => Database::VAR_INTEGER,
|
||||
'array' => false,
|
||||
]),
|
||||
];
|
||||
|
||||
parent::__construct([
|
||||
new Limit(),
|
||||
new Offset(),
|
||||
new Cursor(),
|
||||
new Filter(
|
||||
attributes: $attributes,
|
||||
idAttributeType: Database::VAR_INTEGER,
|
||||
maxValuesCount: APP_DATABASE_QUERY_MAX_VALUES
|
||||
),
|
||||
new Order($attributes),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
namespace Appwrite\Utopia\Database\Validator\Queries;
|
||||
|
||||
class Logs extends Base
|
||||
class Logs extends Executions
|
||||
{
|
||||
public const ALLOWED_ATTRIBUTES = [
|
||||
'status',
|
||||
@@ -19,6 +19,6 @@ class Logs extends Base
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct(['attributes' => Executions::ATTRIBUTES], self::ALLOWED_ATTRIBUTES);
|
||||
parent::__construct(self::ALLOWED_ATTRIBUTES);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user