all files / collab/ ServerResponse.js

0% Statements 0/11
100% Branches 0/0
0% Functions 0/5
0% Lines 0/11
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48                                                                                               
class ServerResponse {
  constructor() {
    this.isReady = false // once the response has been set using send
    this.isEnhanced = false // after response has been enhanced by enhancer
    this.isSent = false // after response has been sent
    this.err = null
    this.data = null
  }
 
  /*
    Sends an error response
 
    @example
 
    ```js
    res.error({
      type: 'syncError',
      errorName: 'AuthenticationError',
      documentId: 'doc-1'
    });
    ```
  */
  error(err) {
    this.err = err
    this.isReady = true
  }
 
  /*
    Send response data
  */
  send(data) {
    this.data = data
    this.isReady = true
  }
 
  /*
    Sets the isEnhanced flag
  */
  setEnhanced() {
    this.isEnhanced = true
  }
 
  setSent() {
    this.isSent = true
  }
}
 
export default ServerResponse