2025-03-24 20:29:33 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								/*
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  Copyright  ( c )  2025 ,  stelar7  < dudedbz @ gmail . com > 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 *  SPDX - License - Identifier :  BSD - 2 - Clause 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# pragma once 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <AK/Optional.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <AK/String.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <AK/Variant.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <AK/Vector.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <LibGC/Ptr.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <LibJS/Heap/Cell.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <LibJS/Runtime/Realm.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								# include  <LibWeb/IndexedDB/Internal/Algorithms.h> 
  
						 
					
						
							
								
									
										
										
										
											2025-03-24 21:18:26 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibWeb/IndexedDB/Internal/Database.h> 
  
						 
					
						
							
								
									
										
										
										
											2025-04-01 18:26:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								# include  <LibWeb/IndexedDB/Internal/Index.h> 
  
						 
					
						
							
								
									
										
										
										
											2025-03-24 20:29:33 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								# include  <LibWeb/IndexedDB/Internal/KeyGenerator.h> 
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								namespace  Web : : IndexedDB  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								using  KeyPath  =  Variant < String ,  Vector < String > > ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								// https://w3c.github.io/IndexedDB/#object-store-construct
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								class  ObjectStore  :  public  JS : : Cell  {  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    GC_CELL ( ObjectStore ,  JS : : Cell ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    GC_DECLARE_ALLOCATOR ( ObjectStore ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								public :  
						 
					
						
							
								
									
										
										
										
											2025-03-24 21:18:26 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    [ [ nodiscard ] ]  static  GC : : Ref < ObjectStore >  create ( JS : : Realm & ,  GC : : Ref < Database > ,  String ,  bool ,  Optional < KeyPath >  const & ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-24 20:29:33 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    virtual  ~ ObjectStore ( ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    String  name ( )  const  {  return  m_name ;  } 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-24 21:18:26 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    void  set_name ( String  name )  {  m_name  =  move ( name ) ;  } 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-24 20:29:33 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    Optional < KeyPath >  key_path ( )  const  {  return  m_key_path ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    bool  uses_inline_keys ( )  const  {  return  m_key_path . has_value ( ) ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    bool  uses_out_of_line_keys ( )  const  {  return  ! m_key_path . has_value ( ) ;  } 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-24 20:56:36 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    Optional < KeyGenerator >  key_generator ( )  const  {  return  m_key_generator ;  } 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-24 20:29:33 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-24 21:18:26 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    GC : : Ref < Database >  database ( )  const  {  return  m_database ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-01 18:26:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    void  add_index ( GC : : Ref < Index >  index )  {  m_indexes . append ( index ) ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    ReadonlySpan < GC : : Ref < Index > >  index_set ( )  const  {  return  m_indexes ;  } 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-24 21:18:26 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								protected :  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    virtual  void  visit_edges ( Visitor & )  override ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-24 20:29:33 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								private :  
						 
					
						
							
								
									
										
										
										
											2025-03-24 21:18:26 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    ObjectStore ( GC : : Ref < Database >  database ,  String  name ,  bool  auto_increment ,  Optional < KeyPath >  const &  key_path ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // AD-HOC: An ObjectStore needs to know what Database it belongs to...
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    GC : : Ref < Database >  m_database ; 
							 
						 
					
						
							
								
									
										
										
										
											2025-03-24 20:29:33 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-04-01 18:26:13 +02:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    // AD-HOC: An Index has referenced ObjectStores, we also need the reverse mapping
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Vector < GC : : Ref < Index > >  m_indexes ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2025-03-24 20:29:33 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								    // An object store has a name, which is a name. At any one time, the name is unique within the database to which it belongs.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    String  m_name ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // An object store optionally has a key path. If the object store has a key path it is said to use in-line keys. Otherwise it is said to use out-of-line keys.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Optional < KeyPath >  m_key_path ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    // An object store optionally has a key generator.
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    Optional < KeyGenerator >  m_key_generator ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								} ;  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}