                 console.log("server deleting")
                 #TODO implement
                 return
-
+ 
     return InvisibleModel
 
 if isClient()

                        #TODO handle error
                        console.log("deleted")

                    http.request({path: "/models/#{@_modelName}/#{@id}/", method: "DELETE"}, 
                        cb).end()
                return


        return InvisibleModel


handleResponse = (cb) ->
    ###
    Collects the response body, parses it as JSON and passes it to the callback.
    ###
    return (res) ->
        fullBody = ''
        res.on 'data', (chunk) -> 
            fullBody += chunk
        res.on 'end', () ->
            data = JSON.parse(fullBody)
            cb(data)


buildClientModel = (modelName, BaseModel) ->
    class InvisibleModel extends BaseModel
            _modelName: modelName
            @_modelName: modelName #FIXME ugly
            
            @query: (opts, cb) -> 
                console.log("querying")
                http.request(
                        {path: "/invisible/#{@_modelName}/", method: "GET"}, 
                        handleResponse(cb)).end()

            save: () -> 
                console.log("saving")
                model = this
                
                update = (data) ->
                    console.log("updating model with" + JSON.stringify(data))
                    _.extend(model, data)

                if @id?
                    req = http.request(
                        {path: "/invisible/#{@_modelName}/#{@_id}/", method: "PUT",
                        headers: { 'content-type': "application/json" }}, 
                        handleResponse(update))
                else
                    req = http.request(
                        {path: "/invisible/#{@_modelName}/", method: "POST", 
                        headers: { 'content-type': "application/json" }}, 
                        handleResponse(update))
                
                req.write(JSON.stringify(this))
                req.end()
                return
            
            delete: ()-> 
