diff --git a/app/config/events.php b/app/config/events.php index b551e2d6e9..b9eb849688 100644 --- a/app/config/events.php +++ b/app/config/events.php @@ -311,6 +311,152 @@ return [ '$description' => 'This event triggers when a database is deleted.', ], ], + 'documentsdb' => [ + '$model' => Response::MODEL_DATABASE, + '$resource' => true, + '$description' => 'This event triggers on any DocumentsDB database event.', + 'collections' => [ + '$model' => Response::MODEL_COLLECTION, + '$resource' => true, + '$description' => 'This event triggers on any collection event.', + 'documents' => [ + '$model' => Response::MODEL_DOCUMENT, + '$resource' => true, + '$description' => 'This event triggers on any documents event.', + 'create' => [ + '$description' => 'This event triggers when a document is created.', + ], + 'update' => [ + '$description' => 'This event triggers when a document is updated.' + ], + 'upsert' => [ + '$description' => 'This event triggers when a document is upserted.', + ], + 'delete' => [ + '$description' => 'This event triggers when a document is deleted.' + ], + ], + 'indexes' => [ + '$model' => Response::MODEL_INDEX, + '$resource' => true, + '$description' => 'This event triggers on any indexes event.', + 'create' => [ + '$description' => 'This event triggers when an index is created.', + ], + 'delete' => [ + '$description' => 'This event triggers when an index is deleted.' + ], + 'update' => [ + '$description' => 'This event triggers when an index is updated.', + ], + ], + 'attributes' => [ + '$model' => Response::MODEL_ATTRIBUTE, + '$resource' => true, + '$description' => 'This event triggers on any attributes event.', + 'create' => [ + '$description' => 'This event triggers when an attribute is created.', + ], + 'update' => [ + '$description' => 'This event triggers when an attribute is updated.', + ], + 'delete' => [ + '$description' => 'This event triggers when an attribute is deleted.' + ] + ], + 'create' => [ + '$description' => 'This event triggers when a collection is created.' + ], + 'update' => [ + '$description' => 'This event triggers when a collection is updated.', + ], + 'delete' => [ + '$description' => 'This event triggers when a collection is deleted.', + ], + ], + 'create' => [ + '$description' => 'This event triggers when a database is created.' + ], + 'update' => [ + '$description' => 'This event triggers when a database is updated.', + ], + 'delete' => [ + '$description' => 'This event triggers when a database is deleted.', + ], + ], + 'vectorsdb' => [ + '$model' => Response::MODEL_DATABASE, + '$resource' => true, + '$description' => 'This event triggers on any VectorsDB database event.', + 'collections' => [ + '$model' => Response::MODEL_COLLECTION, + '$resource' => true, + '$description' => 'This event triggers on any collection event.', + 'documents' => [ + '$model' => Response::MODEL_DOCUMENT, + '$resource' => true, + '$description' => 'This event triggers on any documents event.', + 'create' => [ + '$description' => 'This event triggers when a document is created.', + ], + 'update' => [ + '$description' => 'This event triggers when a document is updated.' + ], + 'upsert' => [ + '$description' => 'This event triggers when a document is upserted.', + ], + 'delete' => [ + '$description' => 'This event triggers when a document is deleted.' + ], + ], + 'indexes' => [ + '$model' => Response::MODEL_INDEX, + '$resource' => true, + '$description' => 'This event triggers on any indexes event.', + 'create' => [ + '$description' => 'This event triggers when an index is created.', + ], + 'delete' => [ + '$description' => 'This event triggers when an index is deleted.' + ], + 'update' => [ + '$description' => 'This event triggers when an index is updated.', + ], + ], + 'attributes' => [ + '$model' => Response::MODEL_ATTRIBUTE, + '$resource' => true, + '$description' => 'This event triggers on any attributes event.', + 'create' => [ + '$description' => 'This event triggers when an attribute is created.', + ], + 'update' => [ + '$description' => 'This event triggers when an attribute is updated.', + ], + 'delete' => [ + '$description' => 'This event triggers when an attribute is deleted.' + ] + ], + 'create' => [ + '$description' => 'This event triggers when a collection is created.' + ], + 'update' => [ + '$description' => 'This event triggers when a collection is updated.', + ], + 'delete' => [ + '$description' => 'This event triggers when a collection is deleted.', + ], + ], + 'create' => [ + '$description' => 'This event triggers when a database is created.' + ], + 'update' => [ + '$description' => 'This event triggers when a database is updated.', + ], + 'delete' => [ + '$description' => 'This event triggers when a database is deleted.', + ], + ], 'buckets' => [ '$model' => Response::MODEL_BUCKET, '$resource' => true, diff --git a/tests/unit/Event/EventTest.php b/tests/unit/Event/EventTest.php index 6f15c80b9a..04f3f7749f 100644 --- a/tests/unit/Event/EventTest.php +++ b/tests/unit/Event/EventTest.php @@ -216,5 +216,15 @@ final class EventTest extends TestCase $this->assertContains('documentsdb.factory-db.collections.assembly.documents.doc-123.update', $documentsDbEvents); $this->assertNotContains('documentsdb.factory-db.tables.assembly.rows.doc-123.update', $documentsDbEvents); $this->assertNotContains('databases.factory-db.collections.assembly.documents.doc-123.update', $documentsDbEvents); + + $vectorsDb = new Document(['type' => 'vectorsdb']); + $vectorsDbEvents = Event::generateEvents('databases.[databaseId].collections.[collectionId].documents.[documentId].update', [ + 'databaseId' => 'factory-db', + 'collectionId' => 'assembly', + 'documentId' => 'doc-123', + ], $vectorsDb); + $this->assertContains('vectorsdb.factory-db.collections.assembly.documents.doc-123.update', $vectorsDbEvents); + $this->assertNotContains('vectorsdb.factory-db.tables.assembly.rows.doc-123.update', $vectorsDbEvents); + $this->assertNotContains('databases.factory-db.collections.assembly.documents.doc-123.update', $vectorsDbEvents); } } diff --git a/tests/unit/Event/Validator/EventValidatorTest.php b/tests/unit/Event/Validator/EventValidatorTest.php index 3af99bc3c2..ab95e1c7b8 100644 --- a/tests/unit/Event/Validator/EventValidatorTest.php +++ b/tests/unit/Event/Validator/EventValidatorTest.php @@ -79,6 +79,50 @@ final class EventValidatorTest extends TestCase $this->assertTrue($this->object->isValid('tablesdb.books.tables.chapters')); $this->assertTrue($this->object->isValid('tablesdb.books.tables.*')); $this->assertTrue($this->object->isValid('tablesdb.books.tables.chapters.columns.name.create')); + $this->assertTrue($this->object->isValid('documentsdb.books.collections.chapters.documents.prolog.create')); + $this->assertTrue($this->object->isValid('documentsdb.books.collections.chapters.documents.prolog')); + $this->assertTrue($this->object->isValid('documentsdb.books.collections.chapters.documents.*.create')); + $this->assertTrue($this->object->isValid('documentsdb.books.collections.chapters.documents.*')); + $this->assertTrue($this->object->isValid('documentsdb.books.collections.*.documents.prolog.create')); + $this->assertTrue($this->object->isValid('documentsdb.books.collections.*.documents.prolog')); + $this->assertTrue($this->object->isValid('documentsdb.books.collections.*.documents.*.create')); + $this->assertTrue($this->object->isValid('documentsdb.books.collections.*.documents.*')); + $this->assertTrue($this->object->isValid('documentsdb.*.collections.chapters.documents.prolog.create')); + $this->assertTrue($this->object->isValid('documentsdb.*.collections.chapters.documents.prolog')); + $this->assertTrue($this->object->isValid('documentsdb.*.collections.chapters.documents.*.create')); + $this->assertTrue($this->object->isValid('documentsdb.*.collections.chapters.documents.*')); + $this->assertTrue($this->object->isValid('documentsdb.*.collections.*.documents.prolog.create')); + $this->assertTrue($this->object->isValid('documentsdb.*.collections.*.documents.prolog')); + $this->assertTrue($this->object->isValid('documentsdb.*.collections.*.documents.*.create')); + $this->assertTrue($this->object->isValid('documentsdb.*.collections.*.documents.*')); + $this->assertTrue($this->object->isValid('documentsdb.*.collections.*')); + $this->assertTrue($this->object->isValid('documentsdb.*')); + $this->assertTrue($this->object->isValid('documentsdb.books')); + $this->assertTrue($this->object->isValid('documentsdb.books.collections.chapters')); + $this->assertTrue($this->object->isValid('documentsdb.books.collections.*')); + $this->assertTrue($this->object->isValid('documentsdb.books.collections.chapters.attributes.name.create')); + $this->assertTrue($this->object->isValid('vectorsdb.books.collections.chapters.documents.prolog.create')); + $this->assertTrue($this->object->isValid('vectorsdb.books.collections.chapters.documents.prolog')); + $this->assertTrue($this->object->isValid('vectorsdb.books.collections.chapters.documents.*.create')); + $this->assertTrue($this->object->isValid('vectorsdb.books.collections.chapters.documents.*')); + $this->assertTrue($this->object->isValid('vectorsdb.books.collections.*.documents.prolog.create')); + $this->assertTrue($this->object->isValid('vectorsdb.books.collections.*.documents.prolog')); + $this->assertTrue($this->object->isValid('vectorsdb.books.collections.*.documents.*.create')); + $this->assertTrue($this->object->isValid('vectorsdb.books.collections.*.documents.*')); + $this->assertTrue($this->object->isValid('vectorsdb.*.collections.chapters.documents.prolog.create')); + $this->assertTrue($this->object->isValid('vectorsdb.*.collections.chapters.documents.prolog')); + $this->assertTrue($this->object->isValid('vectorsdb.*.collections.chapters.documents.*.create')); + $this->assertTrue($this->object->isValid('vectorsdb.*.collections.chapters.documents.*')); + $this->assertTrue($this->object->isValid('vectorsdb.*.collections.*.documents.prolog.create')); + $this->assertTrue($this->object->isValid('vectorsdb.*.collections.*.documents.prolog')); + $this->assertTrue($this->object->isValid('vectorsdb.*.collections.*.documents.*.create')); + $this->assertTrue($this->object->isValid('vectorsdb.*.collections.*.documents.*')); + $this->assertTrue($this->object->isValid('vectorsdb.*.collections.*')); + $this->assertTrue($this->object->isValid('vectorsdb.*')); + $this->assertTrue($this->object->isValid('vectorsdb.books')); + $this->assertTrue($this->object->isValid('vectorsdb.books.collections.chapters')); + $this->assertTrue($this->object->isValid('vectorsdb.books.collections.*')); + $this->assertTrue($this->object->isValid('vectorsdb.books.collections.chapters.attributes.name.create')); $this->assertTrue($this->object->isValid('functions.*')); $this->assertTrue($this->object->isValid('buckets.*')); $this->assertTrue($this->object->isValid('teams.*')); @@ -97,6 +141,10 @@ final class EventValidatorTest extends TestCase $this->assertFalse($this->object->isValid('tables.*.rows.*.unknown')); $this->assertFalse($this->object->isValid('tablesdb.books.collections.chapters.documents.prolog.create')); $this->assertFalse($this->object->isValid('tablesdb.books.tables.chapters.rows.prolog.unknown')); + $this->assertFalse($this->object->isValid('documentsdb.books.tables.chapters.rows.prolog.create')); + $this->assertFalse($this->object->isValid('documentsdb.books.collections.chapters.documents.prolog.unknown')); + $this->assertFalse($this->object->isValid('vectorsdb.books.tables.chapters.rows.prolog.create')); + $this->assertFalse($this->object->isValid('vectorsdb.books.collections.chapters.documents.prolog.unknown')); $this->assertFalse($this->object->isValid('users.torsten.unknown')); $this->assertFalse($this->object->isValid('users.torsten.delete.email')); $this->assertFalse($this->object->isValid('teams.*.memberships.*.update.unknown')); diff --git a/tests/unit/Event/Validator/FunctionEventValidatorTest.php b/tests/unit/Event/Validator/FunctionEventValidatorTest.php index 3fbbbb905b..59e08eb23a 100644 --- a/tests/unit/Event/Validator/FunctionEventValidatorTest.php +++ b/tests/unit/Event/Validator/FunctionEventValidatorTest.php @@ -62,6 +62,16 @@ final class FunctionEventValidatorTest extends TestCase $this->assertTrue($this->object->isValid('tablesdb.*.tables.*.rows.*.create')); $this->assertTrue($this->object->isValid('tablesdb.*.tables.*')); $this->assertTrue($this->object->isValid('tablesdb.*')); + $this->assertTrue($this->object->isValid('documentsdb.books.collections.chapters.documents.prolog.create')); + $this->assertTrue($this->object->isValid('documentsdb.books.collections.chapters.documents.*.create')); + $this->assertTrue($this->object->isValid('documentsdb.*.collections.*.documents.*.create')); + $this->assertTrue($this->object->isValid('documentsdb.*.collections.*')); + $this->assertTrue($this->object->isValid('documentsdb.*')); + $this->assertTrue($this->object->isValid('vectorsdb.books.collections.chapters.documents.prolog.create')); + $this->assertTrue($this->object->isValid('vectorsdb.books.collections.chapters.documents.*.create')); + $this->assertTrue($this->object->isValid('vectorsdb.*.collections.*.documents.*.create')); + $this->assertTrue($this->object->isValid('vectorsdb.*.collections.*')); + $this->assertTrue($this->object->isValid('vectorsdb.*')); $this->assertTrue($this->object->isValid('buckets.*')); $this->assertTrue($this->object->isValid('teams.*')); $this->assertTrue($this->object->isValid('users.*')); @@ -78,6 +88,8 @@ final class FunctionEventValidatorTest extends TestCase $this->assertFalse($this->object->isValid('tables.*.unknown')); $this->assertFalse($this->object->isValid('tables.*.rows.*.unknown')); $this->assertFalse($this->object->isValid('tablesdb.books.collections.chapters.documents.prolog.create')); + $this->assertFalse($this->object->isValid('documentsdb.books.tables.chapters.rows.prolog.create')); + $this->assertFalse($this->object->isValid('vectorsdb.books.tables.chapters.rows.prolog.create')); $this->assertFalse($this->object->isValid('users.torsten.unknown')); $this->assertFalse($this->object->isValid('users.torsten.delete.email')); $this->assertFalse($this->object->isValid('teams.*.memberships.*.update.unknown'));