| 
									
										
										
										
											2024-11-07 18:52:59 +01:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * Copyright (c) 2024, stelar7 <dudedbz@gmail.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <LibGC/Heap.h>
 | 
					
						
							|  |  |  | #include <LibWeb/Bindings/PlatformObject.h>
 | 
					
						
							| 
									
										
										
										
											2025-04-01 18:36:39 +02:00
										 |  |  | #include <LibWeb/IndexedDB/IDBObjectStore.h>
 | 
					
						
							|  |  |  | #include <LibWeb/IndexedDB/Internal/Index.h>
 | 
					
						
							| 
									
										
										
										
											2024-11-07 18:52:59 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::IndexedDB { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // https://w3c.github.io/IndexedDB/#index-interface
 | 
					
						
							|  |  |  | class IDBIndex : public Bindings::PlatformObject { | 
					
						
							|  |  |  |     WEB_PLATFORM_OBJECT(IDBIndex, Bindings::PlatformObject); | 
					
						
							|  |  |  |     GC_DECLARE_ALLOCATOR(IDBIndex); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     virtual ~IDBIndex() override; | 
					
						
							| 
									
										
										
										
											2025-04-01 18:36:39 +02:00
										 |  |  |     [[nodiscard]] static GC::Ref<IDBIndex> create(JS::Realm&, GC::Ref<Index>, GC::Ref<IDBObjectStore>); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<void> set_name(String const& value); | 
					
						
							|  |  |  |     String name() const { return m_name; } | 
					
						
							|  |  |  |     GC::Ref<IDBObjectStore> object_store() { return m_object_store_handle; } | 
					
						
							|  |  |  |     JS::Value key_path() const; | 
					
						
							|  |  |  |     bool multi_entry() const { return m_index->multi_entry(); } | 
					
						
							|  |  |  |     bool unique() const { return m_index->unique(); } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-13 22:18:14 +02:00
										 |  |  |     [[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> get(JS::Value); | 
					
						
							| 
									
										
										
										
											2025-05-13 22:21:57 +02:00
										 |  |  |     [[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> get_key(JS::Value); | 
					
						
							| 
									
										
										
										
											2025-05-13 22:41:18 +02:00
										 |  |  |     [[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> get_all(Optional<JS::Value>, Optional<WebIDL::UnsignedLong>); | 
					
						
							| 
									
										
										
										
											2025-05-13 22:46:23 +02:00
										 |  |  |     [[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> get_all_keys(Optional<JS::Value>, Optional<WebIDL::UnsignedLong>); | 
					
						
							| 
									
										
										
										
											2025-05-13 22:54:08 +02:00
										 |  |  |     [[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> count(JS::Value); | 
					
						
							| 
									
										
										
										
											2025-05-13 22:18:14 +02:00
										 |  |  |     [[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> open_cursor(JS::Value, Bindings::IDBCursorDirection = Bindings::IDBCursorDirection::Next); | 
					
						
							| 
									
										
										
										
											2025-05-13 22:59:45 +02:00
										 |  |  |     [[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> open_key_cursor(JS::Value, Bindings::IDBCursorDirection = Bindings::IDBCursorDirection::Next); | 
					
						
							| 
									
										
										
										
											2025-05-13 22:18:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-01 18:36:39 +02:00
										 |  |  |     // The transaction of an index handle is the transaction of its associated object store handle.
 | 
					
						
							|  |  |  |     GC::Ref<IDBTransaction> transaction() { return m_object_store_handle->transaction(); } | 
					
						
							|  |  |  |     GC::Ref<Index> index() { return m_index; } | 
					
						
							| 
									
										
										
										
											2025-04-29 17:37:16 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-07 18:52:59 +01:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2025-04-01 18:36:39 +02:00
										 |  |  |     explicit IDBIndex(JS::Realm&, GC::Ref<Index>, GC::Ref<IDBObjectStore>); | 
					
						
							| 
									
										
										
										
											2024-11-07 18:52:59 +01:00
										 |  |  |     virtual void initialize(JS::Realm&) override; | 
					
						
							| 
									
										
										
										
											2025-04-01 18:36:39 +02:00
										 |  |  |     virtual void visit_edges(Visitor& visitor) override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     // An index handle has an associated index and an associated object store handle.
 | 
					
						
							|  |  |  |     GC::Ref<Index> m_index; | 
					
						
							|  |  |  |     GC::Ref<IDBObjectStore> m_object_store_handle; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // An index handle has a name, which is initialized to the name of the associated index when the index handle is created.
 | 
					
						
							|  |  |  |     String m_name; | 
					
						
							| 
									
										
										
										
											2024-11-07 18:52:59 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |