6.1. Object store storage operation
To store a record into an object store with store, value, an optional key, and a no-overwrite flag, run these steps:
If store uses a key generator, then:
If key is undefined, then:
Let key be the result of running generate a key for store.
If key is failure, then this operation failed with a “
[ConstraintError](https://heycam.github.io/webidl/#constrainterror)
“[DOMException](https://heycam.github.io/webidl/#idl-DOMException)
. Abort this algorithm without taking any further steps.If store also uses in-line keys, then run inject a key into a value using a key path with value, key and store’s key path.
Otherwise, run possibly update the key generator for store with key.
If the no-overwrite flag was given to these steps and is true, and a record already exists in store with its key equal to key, then this operation failed with a “
[ConstraintError](https://heycam.github.io/webidl/#constrainterror)
“[DOMException](https://heycam.github.io/webidl/#idl-DOMException)
. Abort this algorithm without taking any further steps.If a record already exists in store with its key equal to key, then remove the record from store using delete records from an object store.
Store a record in store containing key as its key and ! StructuredSerializeForStorage(value) as its value. The record is stored in the object store’s list of records such that the list is sorted according to the key of the records in ascending order.
For each index which references store:
Let index key be the result of running extract a key from a value using a key path with value, index’s key path, and index’s multiEntry flag.
If index key is an exception, or invalid, or failure, take no further actions for index, and continue these steps for the next index.
An exception thrown in this step is not rethrown.
If index’s multiEntry flag is false, or if index key is not an array key, and if index already contains a record with key equal to index key, and index’s unique flag is true, then this operation failed with a “
[ConstraintError](https://heycam.github.io/webidl/#constrainterror)
“[DOMException](https://heycam.github.io/webidl/#idl-DOMException)
. Abort this algorithm without taking any further steps.If index’s multiEntry flag is true and index key is an array key, and if index already contains a record with key equal to any of the subkeys of index key, and index’s unique flag is true, then this operation failed with a “
[ConstraintError](https://heycam.github.io/webidl/#constrainterror)
“[DOMException](https://heycam.github.io/webidl/#idl-DOMException)
. Abort this algorithm without taking any further steps.If index’s multiEntry flag is false, or if index key is not an array key then store a record in index containing index key as its key and key as its value. The record is stored in index’s list of records such that the list is sorted primarily on the records keys, and secondarily on the records values, in ascending order.
If index’s multiEntry flag is true and index key is an array key, then for each subkey of the subkeys of index key store a record in index containing subkey as its key and key as its value. The records are stored in index’s list of records such that the list is sorted primarily on the records keys, and secondarily on the records values, in ascending order.
It is valid for there to be no subkeys. In this case no records are added to the index.
Even if any member of subkeys is itself an array key, the member is used directly as the key for the index record. Nested array keys are not flattened or “unpacked” to produce multiple rows; only the outer-most array key is.
Return key.