gromit
Advanced tools
Comparing version 0.0.3 to 0.0.4
@@ -58,4 +58,4 @@ 'use strict'; | ||
*/ | ||
/*:: export type GromitBodyData = string | Object | ArrayBuffer | $ArrayBufferView | URLSearchParams | FormData | File | Blob | stream$Readable | Buffer;*/ // @flow | ||
/** | ||
@@ -66,3 +66,2 @@ * HTTP method for a request | ||
*/ | ||
/*:: export type GromitParamData = Object | URLSearchParams;*/ | ||
@@ -75,3 +74,2 @@ | ||
*/ | ||
/*:: export type GromitMethod = 'get' | 'post' | 'put' | 'patch' | 'delete' | 'head' | 'options';*/ | ||
@@ -101,25 +99,2 @@ | ||
/*:: export type GromitResponseType = 'arraybuffer' | 'blob' | 'document' | 'json' | 'text' | 'stream';*/ | ||
/*:: export type GromitConfiguration = { | ||
method?: GromitMethod, | ||
path?: string, | ||
data?: GromitBodyData, | ||
params?: GromitParamData, | ||
headers?: Object, | ||
baseUrl?: string, | ||
timeout?: number, | ||
withCredentials?: bool, | ||
auth?: { | ||
username: string, | ||
password: string | ||
}, | ||
responseType?: GromitResponseType, | ||
maxContentLength?: number, | ||
maxRedirects?: number, | ||
onUploadProgress?: (progressEvent: ProgressEvent) => void, | ||
onDownloadProgress?: (progressEvent: ProgressEvent) => void, | ||
beforeResponse?: (response: GromitResponse) => any | ||
};*/ | ||
var defaultConfig = { | ||
@@ -164,3 +139,3 @@ method: 'get' | ||
var Gromit = exports.Gromit = function () { | ||
function Gromit(configuration /*: GromitConfiguration*/) { | ||
function Gromit(configuration) { | ||
(0, _classCallCheck3.default)(this, Gromit); | ||
@@ -178,3 +153,3 @@ | ||
key: 'unit', | ||
value: function unit(configuration /*: GromitConfiguration*/) /*: Gromit*/ { | ||
value: function unit(configuration) { | ||
return new Gromit((0, _extends3.default)({}, this.configuration, { | ||
@@ -195,3 +170,3 @@ configuration: configuration | ||
key: 'configure', | ||
value: function configure(configurator /*: (GromitConfiguration) => GromitConfiguration*/) /*: Gromit*/ { | ||
value: function configure(configurator) { | ||
return new Gromit(configurator(this.configuration)); | ||
@@ -208,3 +183,3 @@ } | ||
key: 'uploadProgress', | ||
value: function uploadProgress(cb /*: (progressEvent: ProgressEvent) => void*/) /*: Gromit*/ { | ||
value: function uploadProgress(cb) { | ||
return this.unit({ | ||
@@ -223,3 +198,3 @@ onUploadProgress: cb | ||
key: 'downloadProgress', | ||
value: function downloadProgress(cb /*: (progressEvent: ProgressEvent) => void*/) /*: Gromit*/ { | ||
value: function downloadProgress(cb) { | ||
return this.unit({ | ||
@@ -241,3 +216,3 @@ onDownloadProgress: cb | ||
key: 'request', | ||
value: function request(method /*: ?GromitMethod*/, path /*: ?string*/, data /*: ?GromitBodyData*/, params /*: ?GromitParamData*/) /*: Promise<GromitResponse>*/ { | ||
value: function request(method, path, data, params) { | ||
return this.unit({ | ||
@@ -260,3 +235,3 @@ method: method || this.configuration.method, | ||
key: 'get', | ||
value: function get(path /*:: ?: string*/, params /*:: ?: GromitParamData*/) /*: Promise<GromitResponse>*/ { | ||
value: function get(path, params) { | ||
return this.request('get', path, null, params); | ||
@@ -275,3 +250,3 @@ } | ||
key: 'post', | ||
value: function post(path /*:: ?: string*/, data /*:: ?: GromitBodyData*/, params /*:: ?: GromitParamData*/) /*: Promise<GromitResponse>*/ { | ||
value: function post(path, data, params) { | ||
return this.request('post', path, data, params); | ||
@@ -290,3 +265,3 @@ } | ||
key: 'put', | ||
value: function put(path /*:: ?: string*/, data /*:: ?: GromitBodyData*/, params /*:: ?: GromitParamData*/) /*: Promise<GromitResponse>*/ { | ||
value: function put(path, data, params) { | ||
return this.request('put', path, data, params); | ||
@@ -305,3 +280,3 @@ } | ||
key: 'patch', | ||
value: function patch(path /*:: ?: string*/, data /*:: ?: GromitBodyData*/, params /*:: ?: GromitParamData*/) /*: Promise<GromitResponse>*/ { | ||
value: function patch(path, data, params) { | ||
return this.request('patch', path, data, params); | ||
@@ -319,3 +294,3 @@ } | ||
key: 'delete', | ||
value: function _delete(path /*:: ?: string*/, params /*:: ?: GromitParamData*/) /*: Promise<GromitResponse>*/ { | ||
value: function _delete(path, params) { | ||
return this.request('delete', path, null, params); | ||
@@ -333,3 +308,3 @@ } | ||
key: 'head', | ||
value: function head(path /*:: ?: string*/, params /*:: ?: GromitParamData*/) /*: Promise<GromitResponse>*/ { | ||
value: function head(path, params) { | ||
return this.request('head', path, null, params); | ||
@@ -347,3 +322,3 @@ } | ||
key: 'options', | ||
value: function options(path /*:: ?: string*/, params /*:: ?: GromitParamData*/) /*: Promise<GromitResponse>*/ { | ||
value: function options(path, params) { | ||
return this.request('options', path, null, params); | ||
@@ -359,3 +334,3 @@ } | ||
key: 'fetch', | ||
value: function fetch() /*: Promise<GromitResponse>*/ { | ||
value: function fetch() { | ||
var _this = this; | ||
@@ -406,4 +381,4 @@ | ||
function GromitFactory(configuration /*: GromitConfiguration*/) /*: Gromit*/ { | ||
function GromitFactory(configuration) { | ||
return new Gromit(configuration); | ||
} |
@@ -89,5 +89,4 @@ 'use strict'; | ||
'511': { message: 'Network Authentication Required', name: 'NETWORK_AUTHENTICATION_REQUIRED' } | ||
}; //@flow | ||
}; | ||
/** | ||
@@ -107,9 +106,2 @@ * | ||
*/ | ||
/*:: export type GromitErrorResponseData = { | ||
statusCode: number, | ||
name: string, | ||
message: string, | ||
data: ?Object | ||
};*/ | ||
var GromitError = function (_Error) { | ||
@@ -129,3 +121,3 @@ (0, _inherits3.default)(GromitError, _Error); | ||
*/ | ||
function GromitError(error /*: Object*/, errorData /*: GromitErrorResponseData*/) { | ||
function GromitError(error, errorData) { | ||
(0, _classCallCheck3.default)(this, GromitError); | ||
@@ -174,3 +166,3 @@ | ||
key: 'serialize', | ||
value: function serialize() /*: GromitError*/ { | ||
value: function serialize() { | ||
var message = '[' + this.statusCode + '][' + this.name + '] ' + this.message; | ||
@@ -187,3 +179,3 @@ | ||
key: 'toJSON', | ||
value: function toJSON() /*: Object*/ { | ||
value: function toJSON() { | ||
return { | ||
@@ -208,3 +200,3 @@ stack: this.stack, | ||
key: 'deserialize', | ||
value: function deserialize(error /*: Object*/) /*: GromitError*/ { | ||
value: function deserialize(error) { | ||
var errData = error.message.match(/^\[(.+?)\]\[(.+?)\](.+$)/); | ||
@@ -233,3 +225,3 @@ if (!errData) return GromitError.wrap(error); | ||
key: 'wrap', | ||
value: function wrap(error /*: Object*/, statusCode /*: ?number*/, message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function wrap(error, statusCode, message, name, data) { | ||
var errorStatusCode = statusCode || parseInt(error.statusCode, 10) || 500; | ||
@@ -260,3 +252,3 @@ var defaultErrorData = STATUS_CODE_MAP[errorStatusCode]; | ||
key: 'create', | ||
value: function create(statusCode /*: ?number*/, message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function create(statusCode, message, name, data) { | ||
var errorStatusCode = statusCode || 500; | ||
@@ -291,3 +283,3 @@ var defaultErrorData = STATUS_CODE_MAP[errorStatusCode]; | ||
key: 'badRequest', | ||
value: function badRequest(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function badRequest(message, name, data) { | ||
return GromitError.create(400, message, name, data); | ||
@@ -306,3 +298,3 @@ } | ||
key: 'unauthorized', | ||
value: function unauthorized(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function unauthorized(message, name, data) { | ||
return GromitError.create(401, message, name, data); | ||
@@ -321,3 +313,3 @@ } | ||
key: 'paymentRequired', | ||
value: function paymentRequired(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function paymentRequired(message, name, data) { | ||
return GromitError.create(402, message, name, data); | ||
@@ -336,3 +328,3 @@ } | ||
key: 'forbidden', | ||
value: function forbidden(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function forbidden(message, name, data) { | ||
return GromitError.create(403, message, name, data); | ||
@@ -351,3 +343,3 @@ } | ||
key: 'notFound', | ||
value: function notFound(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function notFound(message, name, data) { | ||
return GromitError.create(404, message, name, data); | ||
@@ -366,3 +358,3 @@ } | ||
key: 'methodNotAllowed', | ||
value: function methodNotAllowed(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function methodNotAllowed(message, name, data) { | ||
return GromitError.create(405, message, name, data); | ||
@@ -381,3 +373,3 @@ } | ||
key: 'notAcceptable', | ||
value: function notAcceptable(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function notAcceptable(message, name, data) { | ||
return GromitError.create(406, message, name, data); | ||
@@ -396,3 +388,3 @@ } | ||
key: 'proxyAuthRequired', | ||
value: function proxyAuthRequired(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function proxyAuthRequired(message, name, data) { | ||
return GromitError.create(407, message, name, data); | ||
@@ -411,3 +403,3 @@ } | ||
key: 'clientTimeout', | ||
value: function clientTimeout(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function clientTimeout(message, name, data) { | ||
return GromitError.create(408, message, name, data); | ||
@@ -426,3 +418,3 @@ } | ||
key: 'conflict', | ||
value: function conflict(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function conflict(message, name, data) { | ||
return GromitError.create(409, message, name, data); | ||
@@ -441,3 +433,3 @@ } | ||
key: 'resourceGone', | ||
value: function resourceGone(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function resourceGone(message, name, data) { | ||
return GromitError.create(410, message, name, data); | ||
@@ -456,3 +448,3 @@ } | ||
key: 'lengthRequired', | ||
value: function lengthRequired(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function lengthRequired(message, name, data) { | ||
return GromitError.create(411, message, name, data); | ||
@@ -471,3 +463,3 @@ } | ||
key: 'preconditionFailed', | ||
value: function preconditionFailed(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function preconditionFailed(message, name, data) { | ||
return GromitError.create(412, message, name, data); | ||
@@ -486,3 +478,3 @@ } | ||
key: 'entityTooLarge', | ||
value: function entityTooLarge(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function entityTooLarge(message, name, data) { | ||
return GromitError.create(413, message, name, data); | ||
@@ -501,3 +493,3 @@ } | ||
key: 'uriTooLong', | ||
value: function uriTooLong(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function uriTooLong(message, name, data) { | ||
return GromitError.create(414, message, name, data); | ||
@@ -516,3 +508,3 @@ } | ||
key: 'unsupportedMediaType', | ||
value: function unsupportedMediaType(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function unsupportedMediaType(message, name, data) { | ||
return GromitError.create(415, message, name, data); | ||
@@ -531,3 +523,3 @@ } | ||
key: 'rangeNotSatisfiable', | ||
value: function rangeNotSatisfiable(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function rangeNotSatisfiable(message, name, data) { | ||
return GromitError.create(416, message, name, data); | ||
@@ -546,3 +538,3 @@ } | ||
key: 'expectationFailed', | ||
value: function expectationFailed(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function expectationFailed(message, name, data) { | ||
return GromitError.create(417, message, name, data); | ||
@@ -561,3 +553,3 @@ } | ||
key: 'teapot', | ||
value: function teapot(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function teapot(message, name, data) { | ||
return GromitError.create(418, message, name, data); | ||
@@ -576,3 +568,3 @@ } | ||
key: 'badData', | ||
value: function badData(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function badData(message, name, data) { | ||
return GromitError.create(422, message, name, data); | ||
@@ -591,3 +583,3 @@ } | ||
key: 'locked', | ||
value: function locked(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function locked(message, name, data) { | ||
return GromitError.create(423, message, name, data); | ||
@@ -606,3 +598,3 @@ } | ||
key: 'preconditionRequired', | ||
value: function preconditionRequired(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function preconditionRequired(message, name, data) { | ||
return GromitError.create(428, message, name, data); | ||
@@ -621,3 +613,3 @@ } | ||
key: 'tooManyRequests', | ||
value: function tooManyRequests(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function tooManyRequests(message, name, data) { | ||
return GromitError.create(429, message, name, data); | ||
@@ -636,3 +628,3 @@ } | ||
key: 'illegal', | ||
value: function illegal(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function illegal(message, name, data) { | ||
return GromitError.create(451, message, name, data); | ||
@@ -651,3 +643,3 @@ } | ||
key: 'notImplemented', | ||
value: function notImplemented(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function notImplemented(message, name, data) { | ||
return GromitError.create(501, message, name, data); | ||
@@ -666,3 +658,3 @@ } | ||
key: 'badGateway', | ||
value: function badGateway(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function badGateway(message, name, data) { | ||
return GromitError.create(502, message, name, data); | ||
@@ -681,3 +673,3 @@ } | ||
key: 'serverUnavailable', | ||
value: function serverUnavailable(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function serverUnavailable(message, name, data) { | ||
return GromitError.create(503, message, name, data); | ||
@@ -696,3 +688,3 @@ } | ||
key: 'gatewayTimeout', | ||
value: function gatewayTimeout(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function gatewayTimeout(message, name, data) { | ||
return GromitError.create(504, message, name, data); | ||
@@ -711,3 +703,3 @@ } | ||
key: 'httpVersionNotSupported', | ||
value: function httpVersionNotSupported(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function httpVersionNotSupported(message, name, data) { | ||
return GromitError.create(505, message, name, data); | ||
@@ -726,3 +718,3 @@ } | ||
key: 'variantAlsoNegotiates', | ||
value: function variantAlsoNegotiates(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function variantAlsoNegotiates(message, name, data) { | ||
return GromitError.create(506, message, name, data); | ||
@@ -741,3 +733,3 @@ } | ||
key: 'insufficientStorage', | ||
value: function insufficientStorage(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function insufficientStorage(message, name, data) { | ||
return GromitError.create(507, message, name, data); | ||
@@ -756,3 +748,3 @@ } | ||
key: 'bandwidthLimitExceeded', | ||
value: function bandwidthLimitExceeded(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function bandwidthLimitExceeded(message, name, data) { | ||
return GromitError.create(509, message, name, data); | ||
@@ -771,3 +763,3 @@ } | ||
key: 'notExtended', | ||
value: function notExtended(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function notExtended(message, name, data) { | ||
return GromitError.create(510, message, name, data); | ||
@@ -786,3 +778,3 @@ } | ||
key: 'networkAuthenticationRequired', | ||
value: function networkAuthenticationRequired(message /*: ?string*/, name /*: ?string*/, data /*: ?Object*/) /*: GromitError*/ { | ||
value: function networkAuthenticationRequired(message, name, data) { | ||
return GromitError.create(511, message, name, data); | ||
@@ -792,3 +784,3 @@ } | ||
key: 'fromAxiosError', | ||
value: function fromAxiosError(error /*: Object*/, requester /*: Gromit*/) /*: GromitError*/ { | ||
value: function fromAxiosError(error, requester) { | ||
var statusCode = error.response ? error.response.status : 500; | ||
@@ -795,0 +787,0 @@ return GromitError.wrap(error, statusCode, error.message, null, { |
@@ -24,17 +24,2 @@ 'use strict'; | ||
*/ | ||
/*:: export type GromitResponseResponseData = { | ||
statusCode: number, | ||
statusText: string, | ||
data: any, | ||
headers: Object, | ||
request: XMLHttpRequest | http$ClientRequest | ||
};*/ //@flow | ||
/** | ||
* | ||
* @module GromitResponse | ||
* | ||
*/ | ||
var GromitResponse = function () { | ||
@@ -53,3 +38,3 @@ | ||
*/ | ||
function GromitResponse(responseData /*: GromitResponseResponseData*/, requester /*: ?Gromit*/) { | ||
function GromitResponse(responseData, requester) { | ||
(0, _classCallCheck3.default)(this, GromitResponse); | ||
@@ -91,3 +76,3 @@ | ||
key: 'fromAxiosResponse', | ||
value: function fromAxiosResponse(response /*: Object*/, requester /*: Gromit*/) /*: GromitResponse*/ { | ||
value: function fromAxiosResponse(response, requester) { | ||
return new GromitResponse({ | ||
@@ -105,2 +90,8 @@ request: response.request, | ||
/** | ||
* | ||
* @module GromitResponse | ||
* | ||
*/ | ||
exports.default = GromitResponse; |
@@ -26,4 +26,2 @@ 'use strict'; | ||
//@flow | ||
exports.default = _Gromit2.default; | ||
@@ -30,0 +28,0 @@ exports.GromitError = _GromitError2.default; |
@@ -45,5 +45,5 @@ 'use strict'; | ||
*/ | ||
exports.default = function (url /*: string*/, getToken /*: () => Promise<string>*/) { | ||
exports.default = function (url, getToken) { | ||
return function () { | ||
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(query /*: string*/, variables /*: Object*/) /*: Promise<Object>*/ { | ||
var _ref = (0, _asyncToGenerator3.default)(_regenerator2.default.mark(function _callee(query, variables) { | ||
var token; | ||
@@ -77,2 +77,2 @@ return _regenerator2.default.wrap(function _callee$(_context) { | ||
}(); | ||
}; //@flow | ||
}; |
@@ -7,3 +7,3 @@ { | ||
"name": "gromit", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "", | ||
@@ -22,3 +22,3 @@ "license": "UNLICENSED", | ||
"watch": "rm -rf lib && babel src --out-dir lib -w", | ||
"build": "rm -rf lib && babel src --out-dir lib", | ||
"build": "rm -rf lib && babel src --out-dir lib && node ./scripts/flow", | ||
"build-examples": "cd example && yarn install && yarn run build && cd -", | ||
@@ -41,3 +41,2 @@ "deploy-to-gh-pages": "yarn run build && yarn run build-examples && yarn run docs && node scripts/publish.js", | ||
"babel-plugin-istanbul": "^4.1.4", | ||
"babel-plugin-transform-flow-comments": "^6.22.0", | ||
"babel-preset-blueflag": "^0.6.0", | ||
@@ -44,0 +43,0 @@ "babel-register": "^6.23.0", |
96269
20
12
1102