Merge branch 'feat-txn' of github.com:appwrite/appwrite into feat-txn

This commit is contained in:
Jake Barnby 2025-10-03 00:12:30 +13:00
commit 0aaa276f03
No known key found for this signature in database
GPG key ID: C437A8CC85B96E9C
4 changed files with 25 additions and 12 deletions

View file

@ -99,15 +99,15 @@ class TransactionState
switch ($action) {
case 'create':
if ($documentId) {
$state[$collectionId][$documentId] = [
$docId = $documentId ?? ($data['$id'] ?? null);
if ($docId) {
$state[$collectionId][$docId] = [
'action' => 'create',
'document' => new Document($data),
'exists' => true
];
}
break;
case 'update':
if (isset($state[$collectionId][$documentId])) {
// Update existing document in transaction state
@ -133,7 +133,9 @@ class TransactionState
break;
case 'upsert':
$state[$collectionId][$documentId] = [
$docId = $documentId ?? ($data['$id'] ?? null);
if (!$docId) { break; }
$state[$collectionId][$docId] = [
'action' => 'upsert',
'document' => new Document($data),
'exists' => true

View file

@ -124,7 +124,7 @@ class Upsert extends Action
if (($existing + 1) > $maxBatch) {
throw new Exception(
Exception::TRANSACTION_LIMIT_EXCEEDED,
'Transaction already has ' . $existing . ' operations, adding ' . \count($documents) . ' would exceed the maximum of ' . $maxBatch
'Transaction already has ' . $existing . ' operations, adding 1 would exceed the maximum of ' . $maxBatch
);
}
@ -144,7 +144,7 @@ class Upsert extends Action
'transactions',
$transactionId,
'operations',
\count($staged)
1
);
});

View file

@ -381,7 +381,7 @@ class Create extends Action
if (($existing + 1) > $maxBatch) {
throw new Exception(
Exception::TRANSACTION_LIMIT_EXCEEDED,
'Transaction already has ' . $existing . ' operations, adding ' . \count($documents) . ' would exceed the maximum of ' . $maxBatch
'Transaction already has ' . $existing . ' operations, adding 1 would exceed the maximum of ' . $maxBatch
);
}

View file

@ -127,14 +127,25 @@ class Operation extends Validator
}
// If action requires documentId, it must be present
if (
isset($this->requiresDocumentId[$value['action']]) &&
!\array_key_exists($this->documentIdName, $value)
) {
- if (
- isset($this->requiresDocumentId[$value['action']]) &&
- !\array_key_exists($this->documentIdName, $value)
- ) {
- $this->description = "Key '$this->documentIdName' is required for action '{$value['action']}'";
- return false;
$actionRequiresDocumentId = ($this->requiresDocumentId[$value['action']] ?? false) === true;
if ($actionRequiresDocumentId && !\array_key_exists($this->documentIdName, $value)) {
$this->description = "Key '$this->documentIdName' is required for action '{$value['action']}'";
return false;
}
if (\array_key_exists($this->documentIdName, $value)) {
if (!\is_string($value[$this->documentIdName]) || \trim($value[$this->documentIdName]) === '') {
$this->description = "Key '$this->documentIdName' must be a non-empty string";
return false;
}
}
// Data validation - only required for certain actions
if (isset($this->requiresData[$value['action']]) && $this->requiresData[$value['action']]) {
// Data is required for this action
@ -146,7 +157,7 @@ class Operation extends Validator
$this->description = "Key 'data' must be an array";
return false;
}
} elseif (\array_key_exists('data', $value)) {
} else if (\array_key_exists('data', $value)) {
// Data is optional but if provided, must be an array
if (!\is_array($value['data'])) {
$this->description = "Key 'data' must be an array";