 
   BatchGetItemResult
   (as-map [r]
-    (with-meta (utils/keyword-map as-map (.getResponses r))
-      {:unprocessed-keys  (utils/keyword-map as-map (.getUnprocessedKeys r))
-       :consumed-capacity (.getConsumedCapacity r)}))
+    {:items             (utils/keyword-map as-map (.getResponses r))
+     :unprocessed       (.getUnprocessedKeys r)
+     :consumed-capacity (cc-units (.getConsumedCapacity r))})
+
   BatchWriteItemResult
   (as-map [r]
-    {:unprocessed-items (utils/keyword-map as-map (.getUnprocessedItems r))
-     :consumed-capacity (.getConsumedCapacity r)})
+    {:unprocessed       (.getUnprocessedItems r)
+     :consumed-capacity (cc-units (.getConsumedCapacity r))})
 
   DescribeTableResult
-  (as-map [r] (let [t (.getTable r)]
-                {:name          (keyword (.getTableName t))
-                 :creation-date (.getCreationDateTime t)
-                 :item-count    (.getItemCount t)
-                 :size          (.getTableSizeBytes t)
-                 :throughput    (as-map (.getProvisionedThroughput t))
-                 :indexes       (as-map (.getLocalSecondaryIndexes t))
-                 :status        (utils/un-enum (.getTableStatus t))
-                 :prim-keys
-                 (let [schema (as-map (.getKeySchema t))
-                       defs   (as-map (.getAttributeDefinitions t))]
-                   (merge-with merge
-                     (reduce-kv (fn [m k v] (assoc m (:name v) {:key-type  (:type v)}))
-                                {} schema)
-                     (reduce-kv (fn [m k v] (assoc m (:name v) {:data-type (:type v)}))
-                                {} defs)))}))
+  (as-map [r]
+    (let [t (.getTable r)]
+      {:name          (keyword (.getTableName t))
+       :creation-date (.getCreationDateTime t)
+       :item-count    (.getItemCount t)
+       :size          (.getTableSizeBytes t)
+       :throughput    (as-map (.getProvisionedThroughput t))
+       :indexes       (as-map (.getLocalSecondaryIndexes t))
+       :status        (utils/un-enum (.getTableStatus t))
+       :prim-keys
+       (let [schema (as-map (.getKeySchema t))
+             defs   (as-map (.getAttributeDefinitions t))]
+         (merge-with merge
+           (reduce-kv (fn [m k v] (assoc m (:name v) {:key-type  (:type v)}))
+                      {} schema)
+           (reduce-kv (fn [m k v] (assoc m (:name v) {:data-type (:type v)}))
+                      {} defs)))}))
 
   LocalSecondaryIndexDescription
   (as-map [d] {:name       (keyword (.getIndexName d))

                       {:user-id 2 :username \"jane\"}]
              :delete [{:user-id [3 4 5]}]}})"
  [creds requests]
  (as-map
    (.batchWriteItem (db-client creds)
      (doto (BatchWriteItemRequest.)
        (.setRequestItems
         (utils/name-map
          ;; {<table> <table-reqs> ...} -> {<table> [WriteRequest ...] ...}
          (fn [table-request]
            (reduce into []
             (for [action (keys table-request)
                   :let [items (attr-multi-vs (table-request action))]]
               (mapv (partial write-request action) items))))
          requests))))))

;;;; API - queries & scans


                                                      :my-range ["0" "1"]}]
                                          :attrs []}}))

(defn- merge-unprocessed
  [creds more-f last-result]
  (loop [{:keys [items unprocessed consumed-capacity]} last-result]
    (when (seq unprocessed) (println "REPROCESSING!: " unprocessed))
    (if-not (seq unprocessed)
      (if items
        (with-meta items {:consumed-capacity consumed-capacity})
        last-result)

      (let [{items* :items unprocessed* :unprocessed
             consumed-capacity* :consumed-capacity}
            (more-f creds unprocessed)]

        (recur (merge {:unprocessed       unprocessed*
                       :consumed-capacity (when consumed-capacity
                                            (+ consumed-capacity
                                               consumed-capacity*))}
                      (when (or items items*)
                        {:items (into (or items []) items*)})))))))

(defn- batch-get-item* [creds raw-request]
  (merge-unprocessed creds batch-get-item*
   (as-map
    (.batchGetItem (db-client creds)
      (doto (BatchGetItemRequest.) ; {table-str KeysAndAttributes}
        (.setRequestItems raw-request))))))

(defn batch-get-item
  "Retrieves a batch of items in a single request.
