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-03-24 20:56:36 +01:00
|
|
|
|
// https://w3c.github.io/IndexedDB/#dom-idbobjectstore-autoincrement
|
|
|
|
|
// The autoIncrement getter steps are to return true if this’s object store has a key generator, and false otherwise.
|
2025-04-25 18:12:28 +02:00
|
|
|
|
bool auto_increment() const { return m_store->uses_a_key_generator(); }
|
2025-04-01 18:37:23 +02:00
|
|
|
|
JS::Value key_path() const;
|
2025-03-24 21:18:26 +01:00
|
|
|
|
String name() const { return m_name; }
|
|
|
|
|
WebIDL::ExceptionOr<void> set_name(String const& value);
|
2025-04-01 18:37:23 +02:00
|
|
|
|
GC::Ref<IDBTransaction> transaction() const { return m_transaction; }
|
|
|
|
|
GC::Ref<ObjectStore> store() const { return m_store; }
|
|
|
|
|
AK::HashMap<String, GC::Ref<Index>>& index_set() { return m_indexes; }
|
|
|
|
|
|
|
|
|
|
WebIDL::ExceptionOr<GC::Ref<IDBIndex>> create_index(String const&, KeyPath, IDBIndexParameters options);
|
2025-04-01 18:38:55 +02:00
|
|
|
|
[[nodiscard]] GC::Ref<HTML::DOMStringList> index_names();
|
2025-04-01 18:43:29 +02:00
|
|
|
|
WebIDL::ExceptionOr<GC::Ref<IDBIndex>> index(String const&);
|
2025-04-01 18:57:59 +02:00
|
|
|
|
WebIDL::ExceptionOr<void> delete_index(String const&);
|
2025-03-24 20:56:36 +01:00
|
|
|
|
|
2025-04-11 11:40:53 +02:00
|
|
|
|
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> add_or_put(GC::Ref<IDBObjectStore>, JS::Value, Optional<JS::Value> const&, bool);
|
2025-04-11 11:41:30 +02:00
|
|
|
|
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> add(JS::Value value, Optional<JS::Value> const& key);
|
2025-04-11 11:42:19 +02:00
|
|
|
|
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> put(JS::Value value, Optional<JS::Value> const& key);
|
2025-04-28 15:52:54 +02:00
|
|
|
|
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> count(Optional<JS::Value>);
|
2025-04-28 15:55:59 +02:00
|
|
|
|
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> get(JS::Value);
|
2025-04-29 17:37:40 +02:00
|
|
|
|
[[nodiscard]] WebIDL::ExceptionOr<GC::Ref<IDBRequest>> open_cursor(JS::Value, Bindings::IDBCursorDirection = Bindings::IDBCursorDirection::Next);
|
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
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|