| 
									
										
										
										
											2024-11-07 19:00:20 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2024, stelar7 <dudedbz@gmail.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <LibGC/Ptr.h>
 | 
					
						
							|  |  |  | #include <LibWeb/Bindings/IDBDatabasePrototype.h>
 | 
					
						
							|  |  |  | #include <LibWeb/Bindings/IDBTransactionPrototype.h>
 | 
					
						
							|  |  |  | #include <LibWeb/DOM/Event.h>
 | 
					
						
							|  |  |  | #include <LibWeb/DOM/EventTarget.h>
 | 
					
						
							|  |  |  | #include <LibWeb/IndexedDB/IDBDatabase.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace Web::IndexedDB { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // https://w3c.github.io/IndexedDB/#transaction
 | 
					
						
							|  |  |  | class IDBTransaction : public DOM::EventTarget { | 
					
						
							|  |  |  |     WEB_PLATFORM_OBJECT(IDBTransaction, DOM::EventTarget); | 
					
						
							|  |  |  |     GC_DECLARE_ALLOCATOR(IDBTransaction); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     enum TransactionState { | 
					
						
							|  |  |  |         Active, | 
					
						
							|  |  |  |         Inactive, | 
					
						
							|  |  |  |         Committing, | 
					
						
							|  |  |  |         Finished | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     virtual ~IDBTransaction() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     [[nodiscard]] static GC::Ref<IDBTransaction> create(JS::Realm&, GC::Ref<IDBDatabase>); | 
					
						
							|  |  |  |     [[nodiscard]] Bindings::IDBTransactionMode mode() const { return m_mode; } | 
					
						
							|  |  |  |     [[nodiscard]] TransactionState state() const { return m_state; } | 
					
						
							|  |  |  |     [[nodiscard]] GC::Ptr<WebIDL::DOMException> error() const { return m_error; } | 
					
						
							|  |  |  |     [[nodiscard]] GC::Ref<IDBDatabase> connection() const { return m_connection; } | 
					
						
							|  |  |  |     [[nodiscard]] Bindings::IDBTransactionDurability durability() const { return m_durability; } | 
					
						
							| 
									
										
										
										
											2024-12-01 21:57:32 +01:00
										 |  |  |     [[nodiscard]] GC::Ptr<IDBRequest> associated_request() const { return m_associated_request; } | 
					
						
							| 
									
										
										
										
											2024-11-07 19:00:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void set_mode(Bindings::IDBTransactionMode mode) { m_mode = mode; } | 
					
						
							|  |  |  |     void set_state(TransactionState state) { m_state = state; } | 
					
						
							|  |  |  |     void set_error(GC::Ptr<WebIDL::DOMException> error) { m_error = error; } | 
					
						
							| 
									
										
										
										
											2024-12-01 21:57:32 +01:00
										 |  |  |     void set_associated_request(GC::Ptr<IDBRequest> request) { m_associated_request = request; } | 
					
						
							| 
									
										
										
										
											2024-11-07 19:00:20 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     [[nodiscard]] bool is_upgrade_transaction() const { return m_mode == Bindings::IDBTransactionMode::Versionchange; } | 
					
						
							|  |  |  |     [[nodiscard]] bool is_readonly() const { return m_mode == Bindings::IDBTransactionMode::Readonly; } | 
					
						
							|  |  |  |     [[nodiscard]] bool is_readwrite() const { return m_mode == Bindings::IDBTransactionMode::Readwrite; } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-12-01 21:58:42 +01:00
										 |  |  |     WebIDL::ExceptionOr<void> abort(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-07 19:00:20 +01:00
										 |  |  |     void set_onabort(WebIDL::CallbackType*); | 
					
						
							|  |  |  |     WebIDL::CallbackType* onabort(); | 
					
						
							|  |  |  |     void set_oncomplete(WebIDL::CallbackType*); | 
					
						
							|  |  |  |     WebIDL::CallbackType* oncomplete(); | 
					
						
							|  |  |  |     void set_onerror(WebIDL::CallbackType*); | 
					
						
							|  |  |  |     WebIDL::CallbackType* onerror(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | protected: | 
					
						
							|  |  |  |     explicit IDBTransaction(JS::Realm&, GC::Ref<IDBDatabase>); | 
					
						
							|  |  |  |     virtual void initialize(JS::Realm&) override; | 
					
						
							|  |  |  |     virtual void visit_edges(Visitor& visitor) override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     GC::Ref<IDBDatabase> m_connection; | 
					
						
							|  |  |  |     Bindings::IDBTransactionMode m_mode; | 
					
						
							|  |  |  |     Bindings::IDBTransactionDurability m_durability { Bindings::IDBTransactionDurability::Default }; | 
					
						
							|  |  |  |     TransactionState m_state; | 
					
						
							|  |  |  |     GC::Ptr<WebIDL::DOMException> m_error; | 
					
						
							| 
									
										
										
										
											2024-12-01 21:57:32 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     GC::Ptr<IDBRequest> m_associated_request; | 
					
						
							| 
									
										
										
										
											2024-11-07 19:00:20 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | } |