# Path: chat/asset.py
# def sign_asset_url(name):
#     signer = get_signer()
#     return signer.sign(name)
# 
# Path: chat/exc.py
# class SkygearChatException(SkygearException):
#     pass


from skygear.encoding import deserialize_record, serialize_record
from skygear.models import Record
from .asset import sign_asset_url
from .exc import SkygearChatException

    def query(self, query):
        include = {v: {"$type": "keypath", "$val": v}
                   for v in list(set(query.include))}

        payload = {'database_id': self.database_id,
                   'record_type': query.record_type,
                   'predicate': query.predicate.to_dict(),
                   'count': query.count,
                   'sort': query.sort,
                   'include': include}

        if query.offset is not None:
            payload['offset'] = query.offset
        if query.limit is not None:
            payload['limit'] = query.limit
        result = self.container.send_action('record:query', payload)
        if 'error' in result:
            raise SkygearChatException(result['error']['message'])
        result = result['result']
        output = []
        for r in result:
            record = deserialize_record(r)
            if '_transient' in r:
                t = r['_transient']
                record['_transient'] = {k: deserialize_record(t[k])
                                        for k in t.keys()}
            if 'attachment' in r:
                record['attachment'] = r['attachment'].copy()
                record['attachment']['$url'] =\

# Path: chat/asset.py
# def sign_asset_url(name):
#     signer = get_signer()
#     return signer.sign(name)
# 
# Path: chat/exc.py
# class SkygearChatException(SkygearException):
#     pass


# Path: chat/database.py
from skygear.encoding import deserialize_record, serialize_record
from skygear.models import Record
from .asset import sign_asset_url
from .exc import SkygearChatException


    def query(self, query):
        include = {v: {"$type": "keypath", "$val": v}
                   for v in list(set(query.include))}

        payload = {'database_id': self.database_id,
                   'record_type': query.record_type,
                   'predicate': query.predicate.to_dict(),
                   'count': query.count,
                   'sort': query.sort,
                   'include': include}

        if query.offset is not None:
            payload['offset'] = query.offset
        if query.limit is not None:
            payload['limit'] = query.limit
        result = self.container.send_action('record:query', payload)
        if 'error' in result:
            raise SkygearChatException(result['error']['message'])
        result = result['result']
        output = []
        for r in result:
            record = deserialize_record(r)
            if '_transient' in r:
                t = r['_transient']
                record['_transient'] = {k: deserialize_record(t[k])
                                        for k in t.keys()}
            if 'attachment' in r:
                record['attachment'] = r['attachment'].copy()
                record['attachment']['$url'] =\

                    sign_asset_url(r['attachment']['$name'])