From 86d195c1c0a49d7c351dac4e9dfd9be4defb9f7c Mon Sep 17 00:00:00 2001 From: Darshan Date: Tue, 6 May 2025 11:31:35 +0530 Subject: [PATCH] update: request, response filters. --- src/Appwrite/Utopia/Request/Filters/V19.php | 32 +++++++++++++++----- src/Appwrite/Utopia/Response/Filters/V19.php | 2 ++ 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/src/Appwrite/Utopia/Request/Filters/V19.php b/src/Appwrite/Utopia/Request/Filters/V19.php index ee04cea038..01d2da01a2 100644 --- a/src/Appwrite/Utopia/Request/Filters/V19.php +++ b/src/Appwrite/Utopia/Request/Filters/V19.php @@ -6,20 +6,36 @@ use Appwrite\Utopia\Request\Filter; class V19 extends Filter { + // Map old params to new + private const PARAMS_MAP = [ + 'documentId' => 'rowId', + 'attributes' => 'columns', + 'collectionId' => 'tableId', + 'attributeId' => 'columnId', + '$collectionId' => '$tableId', + 'relatedCollection' => 'relatedTable', + 'relatedCollectionId' => 'relatedTableId', + ]; + // Convert 1.6 params to 1.7 public function parse(array $content, string $model): array { - return match ($model) { - 'databases.createRelationshipColumn' => $this->convertV16RelationshipParams($content), - default => $content - }; + $content = $this->overrideDatabaseParams($content, $model); + + return $content; } - protected function convertV16RelationshipParams(array $content): array + protected function overrideDatabaseParams(array $content, string $model): array { - if (isset($content['relatedCollectionId'])) { - $content['relatedTableId'] = $content['relatedCollectionId']; - unset($content['relatedCollectionId']); + if (!str_starts_with($model, 'databases.')) { + return $content; + } + + $intersect = array_intersect_key(self::PARAMS_MAP, $content); + + foreach ($intersect as $oldKey => $newKey) { + $content[$newKey] = $content[$oldKey]; + unset($content[$oldKey]); } return $content; diff --git a/src/Appwrite/Utopia/Response/Filters/V19.php b/src/Appwrite/Utopia/Response/Filters/V19.php index 5e1a7e40e7..24cb07889f 100644 --- a/src/Appwrite/Utopia/Response/Filters/V19.php +++ b/src/Appwrite/Utopia/Response/Filters/V19.php @@ -10,8 +10,10 @@ class V19 extends Filter private const DATABASE_MAPPINGS = [ 'table' => 'collection', 'tables' => 'collections', + '$tableId' => '$collectionId', 'tablesTotal' => 'collectionsTotal', 'relatedTable' => 'relatedCollection', + 'relatedTableId' => 'relatedCollectionId', 'column' => 'attribute', 'columns' => 'attributes',