Class: persistenceUtils

QuickNav

persistenceUtils

Provide various utilities for converting Request/Response objects to JSON.

Methods

(static) buildEndpointKey(request) → {string}

helper function to build endpoint key to register options under. The option contains shredder/unshredder needed for cache to shred/unshredd responses. Ideally, we would like cache to be able to look up such information in the framework based on scope, but there is no central place for such information to reside, considering the facts that the framework should work in service worker case. So the solution is for cache to lookup the information based on request.url, thus we require (1) responseProxy needs to register/unregister the options so during which time period cache is able to look up shredder/unshredder (2) because of asynchronous nature, there could be multiple fetch events going on from the same url, while we don't want the registered shredder/unshredder to grow out of control, we create a unique key so we can use the same key to unreigster the shredder/unshredder (3) any cache operations needs to happen within defaultResponseProxy processRequest scope.
Parameters:
Name Type Description
request Request Request object to build the key for.
Returns:
A unique key that can by used to register option under.
Type
string

(static) isCachedResponse(response) → {boolean}

Return whether the Response is a cached Response
Parameters:
Name Type Description
response Response Response object
Returns:
Returns whether it's a cached Response
Type
boolean

(static) isGeneratedEtagResponse(response) → {boolean}

Return whether the Response has a generated ETag
Parameters:
Name Type Description
response Response Response object
Returns:
Returns whether it has a generated ETag
Type
boolean

(static) parseMultipartFormData(origbody, contentType) → {Array}

Parse multipart form data in the resquest/response body. Any binary data must be base64 encoded.
Parameters:
Name Type Description
origbody string request/response body as text
contentType string content type
Returns:
Array of the parts
Type
Array

(static) requestFromJSON(data) → {Promise}

Return a Request object constructed from the JSON object returned by requestToJSON
Parameters:
Name Type Description
data Object JSON object returned by requestToJSON
Returns:
Returns a Promise which resolves to the Request
Type
Promise

(static) requestToJSON(request) → {Promise}

Return a JSON object representing the Request object
Parameters:
Name Type Description
request Request Request object
Returns:
Returns a Promise which resolves to the JSON object representing the Request
Type
Promise

(static) responseFromJSON(data) → {Promise}

Return a Response object constructed from the JSON object returned by responseToJSON
Parameters:
Name Type Description
data Object JSON object returned by responseToJSON
Returns:
Returns a Promise which resolves to the Response
Type
Promise

(static) responseToJSON(response, options) → {Promise}

Return a JSON object representing the Response object
Parameters:
Name Type Argument Description
response Response Response object
options {excludeBody: boolean} <optional>
Options
  • options.excludeBody Whether to exclude body from generating the JSON object or not.
Returns:
Returns a Promise which resolves to the JSON object representing the Response
Type
Promise

(static) setResponsePayload(response, payload) → {Promise}

Update the Response object with the provided payload. The existing payload will be replaced
Parameters:
Name Type Description
response Response Response object
payload Object JSON payload data
Returns:
Returns a Promise which resolves to the updated Response object
Type
Promise