/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "nsISupports.idl"

interface nsIIDBIndex;
interface nsIIDBKeyRange;
interface nsIIDBRequest;
interface nsIIDBTransaction;
interface nsIDOMDOMStringList;

dictionary IDBIndexParameters
{
  boolean unique;
  boolean multiEntry;
};

/**
 * nsIIDBObjectStore interface.  See
 * http://dev.w3.org/2006/webapi/WebSimpleDB/#idl-def-nsIIDBObjectStore
 * for more information.
 */
[scriptable, builtinclass, uuid(dd189afd-e1b7-4496-bf8d-629c58709595)]
interface nsIIDBObjectStore : nsISupports
{
  readonly attribute DOMString name;

  [implicit_jscontext]
  readonly attribute jsval keyPath;

  readonly attribute nsIDOMDOMStringList indexNames;

  readonly attribute nsIIDBTransaction transaction;

  readonly attribute boolean autoIncrement;

  // Success fires IDBTransactionEvent, result == value for key
  [implicit_jscontext]
  nsIIDBRequest
  get(in jsval key);

  // Success fires IDBTransactionEvent, result == array of values for given keys
  [implicit_jscontext, optional_argc, binaryname(GetAll)]
  nsIIDBRequest
  mozGetAll([optional /* null */] in jsval key,
            [optional /* unlimited */] in unsigned long limit);

  // Success fires IDBTransactionEvent, result == key
  [implicit_jscontext, optional_argc]
  nsIIDBRequest
  add(in jsval value,
      [optional /* undefined */] in jsval key);

  // Success fires IDBTransactionEvent, result == key
  [implicit_jscontext, optional_argc]
  nsIIDBRequest
  put(in jsval value,
      [optional /* undefined */] in jsval key);

  // Success fires IDBTransactionEvent, result == null
  [implicit_jscontext]
  nsIIDBRequest
  delete(in jsval key);

  // Success fires IDBTransactionEvent, result == null
  [implicit_jscontext]
  nsIIDBRequest
  clear();

  // Success fires IDBTransactionEvent, result == IDBCursor or result == null if
  // no match.
  // direction can be "next", "nextunique", "prev" or "prevunique"
  [implicit_jscontext, optional_argc]
  nsIIDBRequest
  openCursor([optional /* null */] in jsval range,
             [optional /* "next" */] in DOMString direction);

  [implicit_jscontext]
  nsIIDBIndex
  createIndex([Null(Stringify)] in DOMString name,
              in jsval keyPath,
              /* nsIIDBIndexParameters */
              [optional /* none */] in jsval options);

  // Returns object immediately
  nsIIDBIndex
  index([Null(Stringify)] in DOMString name);

  void
  deleteIndex([Null(Stringify)] in DOMString name);

  // Accepts null, a key value, or a nsIIDBKeyRange object.
  [implicit_jscontext, optional_argc]
  nsIIDBRequest
  count([optional] in jsval key);
};
