/* * Copyright (c) 2024-2025, stelar7 * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include namespace Web::IndexedDB { struct IDBIndexParameters { bool unique { false }; bool multi_entry { false }; }; // https://w3c.github.io/IndexedDB/#object-store-interface // https://w3c.github.io/IndexedDB/#object-store-handle-construct class IDBObjectStore : public Bindings::PlatformObject { WEB_PLATFORM_OBJECT(IDBObjectStore, Bindings::PlatformObject); GC_DECLARE_ALLOCATOR(IDBObjectStore); public: virtual ~IDBObjectStore() override; [[nodiscard]] static GC::Ref create(JS::Realm&, GC::Ref, GC::Ref); String name() const; WebIDL::ExceptionOr set_name(String const& value); JS::Value key_path() const; [[nodiscard]] GC::Ref index_names(); GC::Ref transaction() const; bool auto_increment() const; [[nodiscard]] WebIDL::ExceptionOr> put(JS::Value value, Optional const& key); [[nodiscard]] WebIDL::ExceptionOr> add(JS::Value value, Optional const& key); [[nodiscard]] WebIDL::ExceptionOr> delete_(JS::Value); [[nodiscard]] WebIDL::ExceptionOr> clear(); [[nodiscard]] WebIDL::ExceptionOr> get(JS::Value); [[nodiscard]] WebIDL::ExceptionOr> get_key(JS::Value); [[nodiscard]] WebIDL::ExceptionOr> get_all(Optional, Optional); [[nodiscard]] WebIDL::ExceptionOr> get_all_keys(Optional, Optional); [[nodiscard]] WebIDL::ExceptionOr> count(Optional); [[nodiscard]] WebIDL::ExceptionOr> open_cursor(JS::Value, Bindings::IDBCursorDirection = Bindings::IDBCursorDirection::Next); [[nodiscard]] WebIDL::ExceptionOr> open_key_cursor(JS::Value, Bindings::IDBCursorDirection = Bindings::IDBCursorDirection::Next); WebIDL::ExceptionOr> index(String const&); WebIDL::ExceptionOr> create_index(String const&, KeyPath, IDBIndexParameters options); WebIDL::ExceptionOr delete_index(String const&); AK::HashMap>& index_set() { return m_indexes; } WebIDL::ExceptionOr> add_or_put(GC::Ref, JS::Value, Optional const&, bool); GC::Ref store() const { return m_store; } protected: explicit IDBObjectStore(JS::Realm&, GC::Ref, GC::Ref); virtual void initialize(JS::Realm&) override; virtual void visit_edges(Visitor& visitor) override; private: // An object store handle has an associated object store and an associated transaction. GC::Ref m_store; GC::Ref m_transaction; // 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; // An object store handle has an index set AK::HashMap> m_indexes; }; }