/* * Copyright (c) 2025, stelar7 * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include namespace Web::IndexedDB { using KeyPath = Variant>; // https://w3c.github.io/IndexedDB/#index-list-of-records struct IndexRecord { GC::Ref key; GC::Ref value; }; // https://w3c.github.io/IndexedDB/#index-construct class Index : public JS::Cell { GC_CELL(Index, JS::Cell); GC_DECLARE_ALLOCATOR(Index); public: [[nodiscard]] static GC::Ref create(JS::Realm&, GC::Ref, String, KeyPath const&, bool, bool); virtual ~Index(); void set_name(String name); [[nodiscard]] String name() const { return m_name; } [[nodiscard]] bool unique() const { return m_unique; } [[nodiscard]] bool multi_entry() const { return m_multi_entry; } [[nodiscard]] GC::Ref object_store() const { return m_object_store; } [[nodiscard]] AK::ReadonlySpan records() const { return m_records; } [[nodiscard]] KeyPath const& key_path() const { return m_key_path; } [[nodiscard]] bool has_record_with_key(GC::Ref key); protected: virtual void visit_edges(Visitor&) override; private: Index(GC::Ref, String, KeyPath const&, bool, bool); // An index [...] has a referenced object store. GC::Ref m_object_store; // The index has a list of records which hold the data stored in the index. Vector m_records; // An index has a name, which is a name. At any one time, the name is unique within index’s referenced object store. String m_name; // An index has a unique flag. When true, the index enforces that no two records in the index has the same key. bool m_unique { false }; // An index has a multiEntry flag. This flag affects how the index behaves when the result of evaluating the index’s key path yields an array key. bool m_multi_entry { false }; // The keys are derived from the referenced object store’s values using a key path. KeyPath m_key_path; }; }