| 
									
										
										
										
											2024-11-07 18:56:26 +01:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2025-03-24 20:43:12 +01:00
										 |  |  |  * Copyright (c) 2024-2025, stelar7 <dudedbz@gmail.com> | 
					
						
							| 
									
										
										
										
											2024-11-07 18:56:26 +01:00
										 |  |  |  * | 
					
						
							|  |  |  |  * SPDX-License-Identifier: BSD-2-Clause | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #pragma once
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-01 18:37:23 +02:00
										 |  |  | #include <AK/HashMap.h>
 | 
					
						
							| 
									
										
										
										
											2024-11-07 18:56:26 +01:00
										 |  |  | #include <LibGC/Heap.h>
 | 
					
						
							| 
									
										
										
										
											2025-04-29 17:37:40 +02:00
										 |  |  | #include <LibWeb/Bindings/IDBCursorPrototype.h>
 | 
					
						
							| 
									
										
										
										
											2024-11-07 18:56:26 +01:00
										 |  |  | #include <LibWeb/Bindings/PlatformObject.h>
 | 
					
						
							| 
									
										
										
										
											2025-03-24 20:43:12 +01:00
										 |  |  | #include <LibWeb/IndexedDB/IDBTransaction.h>
 | 
					
						
							| 
									
										
										
										
											2025-04-29 17:37:16 +02:00
										 |  |  | #include <LibWeb/IndexedDB/Internal/Index.h>
 | 
					
						
							| 
									
										
										
										
											2025-03-24 20:43:12 +01:00
										 |  |  | #include <LibWeb/IndexedDB/Internal/ObjectStore.h>
 | 
					
						
							| 
									
										
										
										
											2024-11-07 18:56:26 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | namespace Web::IndexedDB { | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-01 18:37:23 +02:00
										 |  |  | struct IDBIndexParameters { | 
					
						
							|  |  |  |     bool unique { false }; | 
					
						
							|  |  |  |     bool multi_entry { false }; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-07 18:56:26 +01:00
										 |  |  | // https://w3c.github.io/IndexedDB/#object-store-interface
 | 
					
						
							| 
									
										
										
										
											2025-03-24 20:43:12 +01:00
										 |  |  | // https://w3c.github.io/IndexedDB/#object-store-handle-construct
 | 
					
						
							| 
									
										
										
										
											2024-11-07 18:56:26 +01:00
										 |  |  | class IDBObjectStore : public Bindings::PlatformObject { | 
					
						
							|  |  |  |     WEB_PLATFORM_OBJECT(IDBObjectStore, Bindings::PlatformObject); | 
					
						
							|  |  |  |     GC_DECLARE_ALLOCATOR(IDBObjectStore); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     virtual ~IDBObjectStore() override; | 
					
						
							| 
									
										
										
										
											2025-03-24 20:43:12 +01:00
										 |  |  |     [[nodiscard]] static GC::Ref<IDBObjectStore> create(JS::Realm&, GC::Ref<ObjectStore>, GC::Ref<IDBTransaction>); | 
					
						
							| 
									
										
										
										
											2024-11-07 18:56:26 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-05-08 23:55:30 +02:00
										 |  |  |     String name() const; | 
					
						
							| 
									
										
										
										
											2025-03-24 21:18:26 +01:00
										 |  |  |     WebIDL::ExceptionOr<void> set_name(String const& value); | 
					
						
							| 
									
										
										
										
											2025-05-08 23:55:30 +02:00
										 |  |  |     JS::Value key_path() const; | 
					
						
							| 
									
										
										
										
											2025-04-01 18:38:55 +02:00
										 |  |  |     [[nodiscard]] GC::Ref<HTML::DOMStringList> index_names(); | 
					
						
							| 
									
										
										
										
											2025-05-08 23:55:30 +02:00
										 |  |  |     GC::Ref<IDBTransaction> transaction() const; | 
					
						
							|  |  |  |     bool auto_increment() const; | 
					
						
							| 
									
										
										
										
											2025-03-24 20:56:36 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-04-11 11:42:19 +02:00
										 |  |  |     [[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> put(JS::Value value, Optional<JS::Value> const& key); | 
					
						
							| 
									
										
										
										
											2025-05-08 23:55:30 +02:00
										 |  |  |     [[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> add(JS::Value value, Optional<JS::Value> const& key); | 
					
						
							| 
									
										
										
										
											2025-05-08 09:59:13 +02:00
										 |  |  |     [[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> delete_(JS::Value); | 
					
						
							| 
									
										
										
										
											2025-05-08 10:04:53 +02:00
										 |  |  |     [[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> clear(); | 
					
						
							| 
									
										
										
										
											2025-05-08 23:55:30 +02:00
										 |  |  |     [[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> get(JS::Value); | 
					
						
							| 
									
										
										
										
											2025-05-08 15:27:59 +02:00
										 |  |  |     [[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> get_key(JS::Value); | 
					
						
							| 
									
										
										
										
											2025-05-08 23:36:31 +02:00
										 |  |  |     [[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> get_all(Optional<JS::Value>, Optional<WebIDL::UnsignedLong>); | 
					
						
							| 
									
										
										
										
											2025-05-08 23:47:49 +02:00
										 |  |  |     [[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> get_all_keys(Optional<JS::Value>, Optional<WebIDL::UnsignedLong>); | 
					
						
							| 
									
										
										
										
											2025-05-08 23:55:30 +02:00
										 |  |  |     [[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> count(Optional<JS::Value>); | 
					
						
							|  |  |  |     [[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> open_cursor(JS::Value, Bindings::IDBCursorDirection = Bindings::IDBCursorDirection::Next); | 
					
						
							|  |  |  |     [[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> open_key_cursor(JS::Value, Bindings::IDBCursorDirection = Bindings::IDBCursorDirection::Next); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<GC::Ref<IDBIndex>> index(String const&); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<GC::Ref<IDBIndex>> create_index(String const&, KeyPath, IDBIndexParameters options); | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<void> delete_index(String const&); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     AK::HashMap<String, GC::Ref<Index>>& index_set() { return m_indexes; } | 
					
						
							|  |  |  |     WebIDL::ExceptionOr<GC::Ref<IDBRequest>> add_or_put(GC::Ref<IDBObjectStore>, JS::Value, Optional<JS::Value> const&, bool); | 
					
						
							|  |  |  |     GC::Ref<ObjectStore> store() const { return m_store; } | 
					
						
							| 
									
										
										
										
											2025-04-11 11:40:53 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-11-07 18:56:26 +01:00
										 |  |  | protected: | 
					
						
							| 
									
										
										
										
											2025-03-24 20:43:12 +01:00
										 |  |  |     explicit IDBObjectStore(JS::Realm&, GC::Ref<ObjectStore>, GC::Ref<IDBTransaction>); | 
					
						
							| 
									
										
										
										
											2024-11-07 18:56:26 +01:00
										 |  |  |     virtual void initialize(JS::Realm&) override; | 
					
						
							| 
									
										
										
										
											2025-03-24 20:43:12 +01:00
										 |  |  |     virtual void visit_edges(Visitor& visitor) override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     // An object store handle has an associated object store and an associated transaction.
 | 
					
						
							|  |  |  |     GC::Ref<ObjectStore> m_store; | 
					
						
							|  |  |  |     GC::Ref<IDBTransaction> m_transaction; | 
					
						
							| 
									
										
										
										
											2025-03-24 21:18:26 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // An object store handle has a name, which is initialized to the name of the associated object store when the object store handle is created.
 | 
					
						
							|  |  |  |     String m_name; | 
					
						
							| 
									
										
										
										
											2025-04-01 18:37:23 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     // An object store handle has an index set
 | 
					
						
							|  |  |  |     AK::HashMap<String, GC::Ref<Index>> m_indexes; | 
					
						
							| 
									
										
										
										
											2024-11-07 18:56:26 +01:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | } |