diff --git a/packages/errors/dist/jsonql-errors.cjs.js b/packages/errors/dist/jsonql-errors.cjs.js index 6a743a126c2239eb7c7a9f4501aa27147b7af0e8..93be29ec0e0bbac849a8e4db6aba39c7588d7919 100644 --- a/packages/errors/dist/jsonql-errors.cjs.js +++ b/packages/errors/dist/jsonql-errors.cjs.js @@ -1,2 +1,2 @@ -"use strict";function getErrorByStatus(r,o){switch(void 0===o&&(o=!1),r){case 401:return o?"JsonqlContractAuthError":"JsonqlAuthorisationError";case 403:return"JsonqlForbiddenError";case 404:return"JsonqlResolverNotFoundError";case 406:return"Jsonql406Error";case 500:return"Jsonql500Error";default:return"JsonqlError"}}Object.defineProperty(exports,"__esModule",{value:!0});var Jsonql406Error=function(r){function o(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=o.name,r.captureStackTrace&&r.captureStackTrace(this,o)}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 406},e.name.get=function(){return"Jsonql406Error"},Object.defineProperties(o,e),o}(Error),Jsonql500Error=function(r){function o(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=o.name,r.captureStackTrace&&r.captureStackTrace(this,o)}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 500},e.name.get=function(){return"Jsonql500Error"},Object.defineProperties(o,e),o}(Error),JsonqlAuthorisationError=function(r){function o(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=o.name,r.captureStackTrace&&r.captureStackTrace(this,o)}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 401},e.name.get=function(){return"JsonqlAuthorisationError"},Object.defineProperties(o,e),o}(Error),JsonqlContractAuthError=function(r){function o(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=o.name,r.captureStackTrace&&r.captureStackTrace(this,o)}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 401},e.name.get=function(){return"JsonqlContractAuthError"},Object.defineProperties(o,e),o}(Error),JsonqlResolverAppError=function(r){function o(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=o.name,r.captureStackTrace&&r.captureStackTrace(this,o)}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 500},e.name.get=function(){return"JsonqlResolverAppError"},Object.defineProperties(o,e),o}(Error),global$1="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},isBrowser=function(){try{if(window||document)return!0}catch(r){}return!1},isNode=function(){try{if(!isBrowser()&&global$1)return!0}catch(r){}return!1};function whereAmI(){return isBrowser()?"browser":isNode()?"node":"unknown"}var JsonqlBaseError=function(r){function o(){for(var o=[],e=arguments.length;e--;)o[e]=arguments[e];r.apply(this,o)}return r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o,o.where=function(){return whereAmI()},o}(Error),JsonqlResolverNotFoundError=function(r){function o(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=o.name,Error.captureStackTrace&&Error.captureStackTrace(this,o)}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 404},e.name.get=function(){return"JsonqlResolverNotFoundError"},Object.defineProperties(o,e),o}(JsonqlBaseError),JsonqlEnumError=function(r){function o(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=o.name,r.captureStackTrace&&r.captureStackTrace(this,o)}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlEnumError"},Object.defineProperties(o,e),o}(Error),JsonqlTypeError=function(r){function o(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=o.name,r.captureStackTrace&&r.captureStackTrace(this,o)}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlTypeError"},Object.defineProperties(o,e),o}(Error),JsonqlCheckerError=function(r){function o(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=o.name,r.captureStackTrace&&r.captureStackTrace(this,o)}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlCheckerError"},Object.defineProperties(o,e),o}(Error),JsonqlValidationError=function(r){function o(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=o.name,Error.captureStackTrace&&Error.captureStackTrace(this,o)}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlValidationError"},Object.defineProperties(o,e),o}(JsonqlBaseError),NO_ERROR_MSG="No message",NO_STATUS_CODE=-1,JsonqlError=function(r){function o(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=o.name,Error.captureStackTrace&&Error.captureStackTrace(this,o)}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={name:{configurable:!0},statusCode:{configurable:!0}};return e.name.get=function(){return"JsonqlError"},e.statusCode.get=function(){return NO_STATUS_CODE},Object.defineProperties(o,e),o}(JsonqlBaseError),JsonqlServerError=function(r){function o(e,t){r.call(this,t),this.statusCode=e,this.className=o.name}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlServerError"},Object.defineProperties(o,e),o}(Error),errors=Object.freeze({Jsonql406Error:Jsonql406Error,Jsonql500Error:Jsonql500Error,JsonqlAuthorisationError:JsonqlAuthorisationError,JsonqlContractAuthError:JsonqlContractAuthError,JsonqlResolverAppError:JsonqlResolverAppError,JsonqlResolverNotFoundError:JsonqlResolverNotFoundError,JsonqlEnumError:JsonqlEnumError,JsonqlTypeError:JsonqlTypeError,JsonqlCheckerError:JsonqlCheckerError,JsonqlValidationError:JsonqlValidationError,JsonqlError:JsonqlError,JsonqlServerError:JsonqlServerError}),JsonqlError$1=JsonqlError,isKeyInObject=function(r,o){return!!Object.keys(r).filter(function(r){return o===r}).length};function clientErrorsHandler(r){if(isKeyInObject(r,"error")){var o=r.error,e=o.className,t=o.name,n=e||t,s=o.message||NO_ERROR_MSG,a=o.detail||o;if(n&&errors[n])throw new errors[e](s,a);throw new JsonqlError$1(s,a)}return r}var UNKNOWN_ERROR="unknown";function mapErrToName(r,o){return r.filter(function(r){return o instanceof r}).map(function(r){return r.name})}function getErrorNameByInstance(r,o){var e=mapErrToName(r,o);return e.length?e[0]:UNKNOWN_ERROR}function finalCatch(r){if(Array.isArray(r))throw new JsonqlValidationError("",r);var o=r.message||NO_ERROR_MSG,e=r.detail||r;switch(!0){case r instanceof Jsonql406Error:throw new Jsonql406Error(o,e);case r instanceof Jsonql500Error:throw new Jsonql500Error(o,e);case r instanceof JsonqlAuthorisationError:throw new JsonqlAuthorisationError(o,e);case r instanceof JsonqlContractAuthError:throw new JsonqlContractAuthError(o,e);case r instanceof JsonqlResolverAppError:throw new JsonqlResolverAppError(o,e);case r instanceof JsonqlResolverNotFoundError:throw new JsonqlResolverNotFoundError(o,e);case r instanceof JsonqlEnumError:throw new JsonqlEnumError(o,e);case r instanceof JsonqlTypeError:throw new JsonqlTypeError(o,e);case r instanceof JsonqlCheckerError:throw new JsonqlCheckerError(o,e);case r instanceof JsonqlValidationError:throw new JsonqlValidationError(o,e);case r instanceof JsonqlServerError:throw new JsonqlServerError(o,e);default:throw new JsonqlError(o,e)}}var JSONQL_ERRORS_INFO="version: 1.1.2 module: cjs";exports.JSONQL_ERRORS_INFO=JSONQL_ERRORS_INFO,exports.Jsonql406Error=Jsonql406Error,exports.Jsonql500Error=Jsonql500Error,exports.JsonqlAuthorisationError=JsonqlAuthorisationError,exports.JsonqlCheckerError=JsonqlCheckerError,exports.JsonqlContractAuthError=JsonqlContractAuthError,exports.JsonqlEnumError=JsonqlEnumError,exports.JsonqlError=JsonqlError,exports.JsonqlResolverAppError=JsonqlResolverAppError,exports.JsonqlResolverNotFoundError=JsonqlResolverNotFoundError,exports.JsonqlServerError=JsonqlServerError,exports.JsonqlTypeError=JsonqlTypeError,exports.JsonqlValidationError=JsonqlValidationError,exports.UNKNOWN_ERROR=UNKNOWN_ERROR,exports.clientErrorsHandler=clientErrorsHandler,exports.finalCatch=finalCatch,exports.getErrorByStatus=getErrorByStatus,exports.getErrorNameByInstance=getErrorNameByInstance; +"use strict";function getErrorByStatus(r,o){switch(void 0===o&&(o=!1),r){case 401:return o?"JsonqlContractAuthError":"JsonqlAuthorisationError";case 403:return"JsonqlForbiddenError";case 404:return"JsonqlResolverNotFoundError";case 406:return"Jsonql406Error";case 500:return"Jsonql500Error";default:return"JsonqlError"}}Object.defineProperty(exports,"__esModule",{value:!0});var Jsonql406Error=function(r){function o(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=o.name,r.captureStackTrace&&r.captureStackTrace(this,o)}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 406},e.name.get=function(){return"Jsonql406Error"},Object.defineProperties(o,e),o}(Error),Jsonql500Error=function(r){function o(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=o.name,r.captureStackTrace&&r.captureStackTrace(this,o)}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 500},e.name.get=function(){return"Jsonql500Error"},Object.defineProperties(o,e),o}(Error),JsonqlAuthorisationError=function(r){function o(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=o.name,r.captureStackTrace&&r.captureStackTrace(this,o)}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 401},e.name.get=function(){return"JsonqlAuthorisationError"},Object.defineProperties(o,e),o}(Error),JsonqlContractAuthError=function(r){function o(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=o.name,r.captureStackTrace&&r.captureStackTrace(this,o)}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 401},e.name.get=function(){return"JsonqlContractAuthError"},Object.defineProperties(o,e),o}(Error),JsonqlResolverAppError=function(r){function o(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=o.name,r.captureStackTrace&&r.captureStackTrace(this,o)}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 500},e.name.get=function(){return"JsonqlResolverAppError"},Object.defineProperties(o,e),o}(Error),global$1="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},isBrowser=function(){try{if(window||document)return!0}catch(r){}return!1},isNode=function(){try{if(!isBrowser()&&global$1)return!0}catch(r){}return!1};function whereAmI(){return isBrowser()?"browser":isNode()?"node":"unknown"}var JsonqlBaseError=function(r){function o(){for(var o=[],e=arguments.length;e--;)o[e]=arguments[e];r.apply(this,o)}return r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o,o.where=function(){return whereAmI()},o}(Error),JsonqlResolverNotFoundError=function(r){function o(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=o.name,Error.captureStackTrace&&Error.captureStackTrace(this,o)}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 404},e.name.get=function(){return"JsonqlResolverNotFoundError"},Object.defineProperties(o,e),o}(JsonqlBaseError),JsonqlEnumError=function(r){function o(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=o.name,r.captureStackTrace&&r.captureStackTrace(this,o)}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlEnumError"},Object.defineProperties(o,e),o}(Error),JsonqlTypeError=function(r){function o(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=o.name,r.captureStackTrace&&r.captureStackTrace(this,o)}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlTypeError"},Object.defineProperties(o,e),o}(Error),JsonqlCheckerError=function(r){function o(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=o.name,r.captureStackTrace&&r.captureStackTrace(this,o)}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlCheckerError"},Object.defineProperties(o,e),o}(Error),JsonqlValidationError=function(r){function o(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=o.name,Error.captureStackTrace&&Error.captureStackTrace(this,o)}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlValidationError"},Object.defineProperties(o,e),o}(JsonqlBaseError),NO_ERROR_MSG="No message",NO_STATUS_CODE=-1,JsonqlError=function(r){function o(){for(var e=[],t=arguments.length;t--;)e[t]=arguments[t];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=o.name,Error.captureStackTrace&&Error.captureStackTrace(this,o)}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={name:{configurable:!0},statusCode:{configurable:!0}};return e.name.get=function(){return"JsonqlError"},e.statusCode.get=function(){return NO_STATUS_CODE},Object.defineProperties(o,e),o}(JsonqlBaseError),JsonqlServerError=function(r){function o(e,t){r.call(this,t),this.statusCode=e,this.className=o.name}r&&(o.__proto__=r),o.prototype=Object.create(r&&r.prototype),o.prototype.constructor=o;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlServerError"},Object.defineProperties(o,e),o}(Error),errors=Object.freeze({Jsonql406Error:Jsonql406Error,Jsonql500Error:Jsonql500Error,JsonqlAuthorisationError:JsonqlAuthorisationError,JsonqlContractAuthError:JsonqlContractAuthError,JsonqlResolverAppError:JsonqlResolverAppError,JsonqlResolverNotFoundError:JsonqlResolverNotFoundError,JsonqlEnumError:JsonqlEnumError,JsonqlTypeError:JsonqlTypeError,JsonqlCheckerError:JsonqlCheckerError,JsonqlValidationError:JsonqlValidationError,JsonqlError:JsonqlError,JsonqlServerError:JsonqlServerError}),JsonqlError$1=JsonqlError,isKeyInObject=function(r,o){return!!Object.keys(r).filter(function(r){return o===r}).length};function clientErrorsHandler(r){if(isKeyInObject(r,"error")){var o=r.error,e=o.className,t=o.name,n=e||t,s=o.message||NO_ERROR_MSG,a=o.detail||o;if(n&&errors[n])throw new errors[e](s,a);throw new JsonqlError$1(s,a)}return r}var UNKNOWN_ERROR="unknown";function mapErrToName(r,o){return r.filter(function(r){return o instanceof r}).map(function(r){return r.name})}function getErrorNameByInstance(r,o){var e=mapErrToName(r,o);return e.length?e[0]:UNKNOWN_ERROR}function getErrorNameByInstanceWithDefault(r,o){var e=getErrorNameByInstance(r,o);return e===UNKNOWN_ERROR?"JsonqlError":e}function finalCatch(r){if(Array.isArray(r))throw new JsonqlValidationError("",r);var o=r.message||NO_ERROR_MSG,e=r.detail||r;switch(!0){case r instanceof Jsonql406Error:throw new Jsonql406Error(o,e);case r instanceof Jsonql500Error:throw new Jsonql500Error(o,e);case r instanceof JsonqlAuthorisationError:throw new JsonqlAuthorisationError(o,e);case r instanceof JsonqlContractAuthError:throw new JsonqlContractAuthError(o,e);case r instanceof JsonqlResolverAppError:throw new JsonqlResolverAppError(o,e);case r instanceof JsonqlResolverNotFoundError:throw new JsonqlResolverNotFoundError(o,e);case r instanceof JsonqlEnumError:throw new JsonqlEnumError(o,e);case r instanceof JsonqlTypeError:throw new JsonqlTypeError(o,e);case r instanceof JsonqlCheckerError:throw new JsonqlCheckerError(o,e);case r instanceof JsonqlValidationError:throw new JsonqlValidationError(o,e);case r instanceof JsonqlServerError:throw new JsonqlServerError(o,e);default:throw new JsonqlError(o,e)}}var JSONQL_ERRORS_INFO="version: 1.1.3 module: cjs";exports.JSONQL_ERRORS_INFO=JSONQL_ERRORS_INFO,exports.Jsonql406Error=Jsonql406Error,exports.Jsonql500Error=Jsonql500Error,exports.JsonqlAuthorisationError=JsonqlAuthorisationError,exports.JsonqlCheckerError=JsonqlCheckerError,exports.JsonqlContractAuthError=JsonqlContractAuthError,exports.JsonqlEnumError=JsonqlEnumError,exports.JsonqlError=JsonqlError,exports.JsonqlResolverAppError=JsonqlResolverAppError,exports.JsonqlResolverNotFoundError=JsonqlResolverNotFoundError,exports.JsonqlServerError=JsonqlServerError,exports.JsonqlTypeError=JsonqlTypeError,exports.JsonqlValidationError=JsonqlValidationError,exports.UNKNOWN_ERROR=UNKNOWN_ERROR,exports.clientErrorsHandler=clientErrorsHandler,exports.finalCatch=finalCatch,exports.getErrorByStatus=getErrorByStatus,exports.getErrorNameByInstance=getErrorNameByInstance,exports.getErrorNameByInstanceWithDefault=getErrorNameByInstanceWithDefault; //# sourceMappingURL=jsonql-errors.cjs.js.map diff --git a/packages/errors/dist/jsonql-errors.umd.js b/packages/errors/dist/jsonql-errors.umd.js index 314ae83f0c76ded85296011648188c9302bdb4b9..a40b26a370950bca7926ec7baaef7d9b75fe72c5 100644 --- a/packages/errors/dist/jsonql-errors.umd.js +++ b/packages/errors/dist/jsonql-errors.umd.js @@ -1,2 +1,2 @@ -!function(r,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((r=r||self).jsonqlErrors={})}(this,function(r){"use strict";var t=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 406},e.name.get=function(){return"Jsonql406Error"},Object.defineProperties(t,e),t}(Error),e=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 500},e.name.get=function(){return"Jsonql500Error"},Object.defineProperties(t,e),t}(Error),o=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 401},e.name.get=function(){return"JsonqlAuthorisationError"},Object.defineProperties(t,e),t}(Error),n=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 401},e.name.get=function(){return"JsonqlContractAuthError"},Object.defineProperties(t,e),t}(Error),a=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 500},e.name.get=function(){return"JsonqlResolverAppError"},Object.defineProperties(t,e),t}(Error),c="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},s=function(){try{if(window||document)return!0}catch(r){}return!1},i=function(){try{if(!s()&&c)return!0}catch(r){}return!1};var u=function(r){function t(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];r.apply(this,t)}return r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t,t.where=function(){return s()?"browser":i()?"node":"unknown"},t}(Error),p=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,Error.captureStackTrace&&Error.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 404},e.name.get=function(){return"JsonqlResolverNotFoundError"},Object.defineProperties(t,e),t}(u),l=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlEnumError"},Object.defineProperties(t,e),t}(Error),f=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlTypeError"},Object.defineProperties(t,e),t}(Error),h=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlCheckerError"},Object.defineProperties(t,e),t}(Error),d=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,Error.captureStackTrace&&Error.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlValidationError"},Object.defineProperties(t,e),t}(u),m="No message",g=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,Error.captureStackTrace&&Error.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0},statusCode:{configurable:!0}};return e.name.get=function(){return"JsonqlError"},e.statusCode.get=function(){return-1},Object.defineProperties(t,e),t}(u),y=function(r){function t(e,o){r.call(this,o),this.statusCode=e,this.className=t.name}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlServerError"},Object.defineProperties(t,e),t}(Error),E=Object.freeze({Jsonql406Error:t,Jsonql500Error:e,JsonqlAuthorisationError:o,JsonqlContractAuthError:n,JsonqlResolverAppError:a,JsonqlResolverNotFoundError:p,JsonqlEnumError:l,JsonqlTypeError:f,JsonqlCheckerError:h,JsonqlValidationError:d,JsonqlError:g,JsonqlServerError:y}),_=g,b=function(r,t){return!!Object.keys(r).filter(function(r){return t===r}).length};var q="unknown";r.JSONQL_ERRORS_INFO="version: 1.1.2 module: umd",r.Jsonql406Error=t,r.Jsonql500Error=e,r.JsonqlAuthorisationError=o,r.JsonqlCheckerError=h,r.JsonqlContractAuthError=n,r.JsonqlEnumError=l,r.JsonqlError=g,r.JsonqlResolverAppError=a,r.JsonqlResolverNotFoundError=p,r.JsonqlServerError=y,r.JsonqlTypeError=f,r.JsonqlValidationError=d,r.UNKNOWN_ERROR=q,r.clientErrorsHandler=function(r){if(b(r,"error")){var t=r.error,e=t.className,o=t.name,n=e||o,a=t.message||m,c=t.detail||t;if(n&&E[n])throw new E[e](a,c);throw new _(a,c)}return r},r.finalCatch=function(r){if(Array.isArray(r))throw new d("",r);var c=r.message||m,s=r.detail||r;switch(!0){case r instanceof t:throw new t(c,s);case r instanceof e:throw new e(c,s);case r instanceof o:throw new o(c,s);case r instanceof n:throw new n(c,s);case r instanceof a:throw new a(c,s);case r instanceof p:throw new p(c,s);case r instanceof l:throw new l(c,s);case r instanceof f:throw new f(c,s);case r instanceof h:throw new h(c,s);case r instanceof d:throw new d(c,s);case r instanceof y:throw new y(c,s);default:throw new g(c,s)}},r.getErrorByStatus=function(r,t){switch(void 0===t&&(t=!1),r){case 401:return t?"JsonqlContractAuthError":"JsonqlAuthorisationError";case 403:return"JsonqlForbiddenError";case 404:return"JsonqlResolverNotFoundError";case 406:return"Jsonql406Error";case 500:return"Jsonql500Error";default:return"JsonqlError"}},r.getErrorNameByInstance=function(r,t){var e=function(r,t){return r.filter(function(r){return t instanceof r}).map(function(r){return r.name})}(r,t);return e.length?e[0]:q},Object.defineProperty(r,"__esModule",{value:!0})}); +!function(r,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((r=r||self).jsonqlErrors={})}(this,function(r){"use strict";var t=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 406},e.name.get=function(){return"Jsonql406Error"},Object.defineProperties(t,e),t}(Error),e=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 500},e.name.get=function(){return"Jsonql500Error"},Object.defineProperties(t,e),t}(Error),o=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 401},e.name.get=function(){return"JsonqlAuthorisationError"},Object.defineProperties(t,e),t}(Error),n=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 401},e.name.get=function(){return"JsonqlContractAuthError"},Object.defineProperties(t,e),t}(Error),a=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 500},e.name.get=function(){return"JsonqlResolverAppError"},Object.defineProperties(t,e),t}(Error),c="undefined"!=typeof global?global:"undefined"!=typeof self?self:"undefined"!=typeof window?window:{},s=function(){try{if(window||document)return!0}catch(r){}return!1},i=function(){try{if(!s()&&c)return!0}catch(r){}return!1};var u=function(r){function t(){for(var t=[],e=arguments.length;e--;)t[e]=arguments[e];r.apply(this,t)}return r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t,t.where=function(){return s()?"browser":i()?"node":"unknown"},t}(Error),p=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,Error.captureStackTrace&&Error.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={statusCode:{configurable:!0},name:{configurable:!0}};return e.statusCode.get=function(){return 404},e.name.get=function(){return"JsonqlResolverNotFoundError"},Object.defineProperties(t,e),t}(u),l=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlEnumError"},Object.defineProperties(t,e),t}(Error),f=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlTypeError"},Object.defineProperties(t,e),t}(Error),h=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,r.captureStackTrace&&r.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlCheckerError"},Object.defineProperties(t,e),t}(Error),m=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,Error.captureStackTrace&&Error.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlValidationError"},Object.defineProperties(t,e),t}(u),d="No message",g=function(r){function t(){for(var e=[],o=arguments.length;o--;)e[o]=arguments[o];r.apply(this,e),this.message=e[0],this.detail=e[1],this.className=t.name,Error.captureStackTrace&&Error.captureStackTrace(this,t)}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0},statusCode:{configurable:!0}};return e.name.get=function(){return"JsonqlError"},e.statusCode.get=function(){return-1},Object.defineProperties(t,e),t}(u),E=function(r){function t(e,o){r.call(this,o),this.statusCode=e,this.className=t.name}r&&(t.__proto__=r),t.prototype=Object.create(r&&r.prototype),t.prototype.constructor=t;var e={name:{configurable:!0}};return e.name.get=function(){return"JsonqlServerError"},Object.defineProperties(t,e),t}(Error),y=Object.freeze({Jsonql406Error:t,Jsonql500Error:e,JsonqlAuthorisationError:o,JsonqlContractAuthError:n,JsonqlResolverAppError:a,JsonqlResolverNotFoundError:p,JsonqlEnumError:l,JsonqlTypeError:f,JsonqlCheckerError:h,JsonqlValidationError:m,JsonqlError:g,JsonqlServerError:E}),_=g,b=function(r,t){return!!Object.keys(r).filter(function(r){return t===r}).length};var q="unknown";function J(r,t){var e=function(r,t){return r.filter(function(r){return t instanceof r}).map(function(r){return r.name})}(r,t);return e.length?e[0]:q}r.JSONQL_ERRORS_INFO="version: 1.1.3 module: umd",r.Jsonql406Error=t,r.Jsonql500Error=e,r.JsonqlAuthorisationError=o,r.JsonqlCheckerError=h,r.JsonqlContractAuthError=n,r.JsonqlEnumError=l,r.JsonqlError=g,r.JsonqlResolverAppError=a,r.JsonqlResolverNotFoundError=p,r.JsonqlServerError=E,r.JsonqlTypeError=f,r.JsonqlValidationError=m,r.UNKNOWN_ERROR=q,r.clientErrorsHandler=function(r){if(b(r,"error")){var t=r.error,e=t.className,o=t.name,n=e||o,a=t.message||d,c=t.detail||t;if(n&&y[n])throw new y[e](a,c);throw new _(a,c)}return r},r.finalCatch=function(r){if(Array.isArray(r))throw new m("",r);var c=r.message||d,s=r.detail||r;switch(!0){case r instanceof t:throw new t(c,s);case r instanceof e:throw new e(c,s);case r instanceof o:throw new o(c,s);case r instanceof n:throw new n(c,s);case r instanceof a:throw new a(c,s);case r instanceof p:throw new p(c,s);case r instanceof l:throw new l(c,s);case r instanceof f:throw new f(c,s);case r instanceof h:throw new h(c,s);case r instanceof m:throw new m(c,s);case r instanceof E:throw new E(c,s);default:throw new g(c,s)}},r.getErrorByStatus=function(r,t){switch(void 0===t&&(t=!1),r){case 401:return t?"JsonqlContractAuthError":"JsonqlAuthorisationError";case 403:return"JsonqlForbiddenError";case 404:return"JsonqlResolverNotFoundError";case 406:return"Jsonql406Error";case 500:return"Jsonql500Error";default:return"JsonqlError"}},r.getErrorNameByInstance=J,r.getErrorNameByInstanceWithDefault=function(r,t){var e=J(r,t);return e===q?"JsonqlError":e},Object.defineProperty(r,"__esModule",{value:!0})}); //# sourceMappingURL=jsonql-errors.umd.js.map diff --git a/packages/errors/index.js b/packages/errors/index.js index 123c463fa7296ce262e40c085650906f0259e945..68727e95acb35e968c2125037019e0785f61fee7 100644 --- a/packages/errors/index.js +++ b/packages/errors/index.js @@ -1,7 +1,11 @@ // jsonql-errors main interface import getErrorByStatus from './src/get-error-by-status'; import clientErrorsHandler from './src/client-errors-handler'; -import { getErrorNameByInstance, UNKNOWN_ERROR } from './src/get-error-name-by-instance'; +import { + getErrorNameByInstance, + getErrorNameByInstanceWithDefault, + UNKNOWN_ERROR +} from './src/get-error-name-by-instance'; import finalCatch from './src/final-catch.js'; const JSONQL_ERRORS_INFO = '__PLACEHOLDER__'; import { @@ -22,12 +26,13 @@ import { export { JSONQL_ERRORS_INFO, UNKNOWN_ERROR, - + getErrorByStatus, clientErrorsHandler, finalCatch, getErrorNameByInstance, - + getErrorNameByInstanceWithDefault, + Jsonql406Error, Jsonql500Error, JsonqlAuthorisationError, diff --git a/packages/errors/package.json b/packages/errors/package.json index fa3d6bdd34e2f739bf17e58fa54d2ddb865385d1..bc6e40930d5a0bce102489b0dfaa1b19fd1c3039 100644 --- a/packages/errors/package.json +++ b/packages/errors/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-errors", - "version": "1.1.2", + "version": "1.1.3", "description": "Jsonql js error classes use across the projects", "main": "dist/jsonql-errors.cjs.js", "module": "index.js", @@ -29,14 +29,14 @@ "debug": "^4.1.1", "esm": "^3.2.25", "fs-extra": "^8.1.0", - "koa": "^2.7.0", + "koa": "^2.8.1", "koa-bodyparser": "^4.2.1", - "rollup": "^1.19.4", - "rollup-plugin-alias": "^1.5.2", + "rollup": "^1.20.3", + "rollup-plugin-alias": "^2.0.0", "rollup-plugin-async": "^1.2.0", "rollup-plugin-buble": "^0.19.8", "rollup-plugin-bundle-size": "^1.0.3", - "rollup-plugin-commonjs": "^10.0.2", + "rollup-plugin-commonjs": "^10.1.0", "rollup-plugin-copy": "^3.1.0", "rollup-plugin-json": "^4.0.0", "rollup-plugin-node-builtins": "^2.1.2", @@ -74,6 +74,6 @@ "author": "Joel Chu ", "license": "ISC", "dependencies": { - "jsonql-constants": "^1.7.9" + "jsonql-constants": "^1.8.3" } } diff --git a/packages/errors/src/get-error-name-by-instance.js b/packages/errors/src/get-error-name-by-instance.js index e724ce0c8946fadacc48176f49b51ba442da53f4..9dcbbb2be03fda8eac08ee87a13b1f9d56173b6f 100644 --- a/packages/errors/src/get-error-name-by-instance.js +++ b/packages/errors/src/get-error-name-by-instance.js @@ -20,7 +20,20 @@ function getErrorNameByInstance(errs, e) { return error.length ? error[0] : UNKNOWN_ERROR } +/** + * the same as above with a default JsonqlError as default + * @param {array} errs same + * @param {object} e error itself + * @return {string} the name of the error + */ +function getErrorNameByInstanceWithDefault(errs, e) { + let name = getErrorNameByInstance(errs, e) + return name === UNKNOWN_ERROR ? 'JsonqlError' : name; +} + + export { + getErrorNameByInstanceWithDefault, getErrorNameByInstance, UNKNOWN_ERROR } diff --git a/packages/node-client/package.json b/packages/node-client/package.json index d021d6ca9b275c80bc9218424607b4100e639ad9..0f93fa51b40fa9d5fcc486f027ffbb34125aa60c 100755 --- a/packages/node-client/package.json +++ b/packages/node-client/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-node-client", - "version": "1.1.7", + "version": "1.1.8", "description": "jsonql node.js client using request", "main": "index.js", "scripts": { @@ -35,12 +35,12 @@ "dependencies": { "debug": "^4.1.1", "fs-extra": "^8.1.0", - "jsonql-constants": "^1.8.2", + "jsonql-constants": "^1.8.3", "jsonql-contract": "^1.7.8", - "jsonql-errors": "^1.1.2", + "jsonql-errors": "^1.1.3", "jsonql-jwt": "^1.3.1", "jsonql-params-validator": "^1.4.8", - "jsonql-utils": "^0.4.8", + "jsonql-utils": "^0.4.9", "lodash.merge": "^4.6.2", "node-cache": "^4.2.1", "request": "^2.88.0" diff --git a/packages/node-client/src/jsonql/get-remote-contract.js b/packages/node-client/src/base/get-remote-contract.js similarity index 100% rename from packages/node-client/src/jsonql/get-remote-contract.js rename to packages/node-client/src/base/get-remote-contract.js diff --git a/packages/node-client/src/jsonql/index.js b/packages/node-client/src/base/index.js similarity index 100% rename from packages/node-client/src/jsonql/index.js rename to packages/node-client/src/base/index.js diff --git a/packages/node-client/src/jsonql/jsonql-base-cls.js b/packages/node-client/src/base/jsonql-base-cls.js similarity index 100% rename from packages/node-client/src/jsonql/jsonql-base-cls.js rename to packages/node-client/src/base/jsonql-base-cls.js diff --git a/packages/node-client/src/jsonql/jsonql-cache-class.js b/packages/node-client/src/base/jsonql-cache-class.js similarity index 100% rename from packages/node-client/src/jsonql/jsonql-cache-class.js rename to packages/node-client/src/base/jsonql-cache-class.js diff --git a/packages/node-client/src/jsonql/request-client.js b/packages/node-client/src/base/request-client.js similarity index 100% rename from packages/node-client/src/jsonql/request-client.js rename to packages/node-client/src/base/request-client.js diff --git a/packages/node-client/src/index.js b/packages/node-client/src/index.js index ca53b9ea7f23a4a8427864b23279c13e5751cbde..f5136cef27deafa5bac123c593f1f12d087383a5 100644 --- a/packages/node-client/src/index.js +++ b/packages/node-client/src/index.js @@ -1,7 +1,7 @@ // main export interface -const JsonqlRequestClient = require('./jsonql') +const JsonqlRequestClient = require('./base') const { getContract, generator } = require('./generator') -const checkOptions = require('./check-options') +const checkOptions = require('./options') const { getDebug } = require('./utils') // export diff --git a/packages/node-client/src/check-options.js b/packages/node-client/src/options/index.js similarity index 96% rename from packages/node-client/src/check-options.js rename to packages/node-client/src/options/index.js index 1fc942daaa2d3a8bc7675cfb44aff57ba7ee7589..64ce7ab061dae7e76f54a9f74396267a2dac84d3 100755 --- a/packages/node-client/src/check-options.js +++ b/packages/node-client/src/options/index.js @@ -5,8 +5,8 @@ const { createConfig, checkConfigAsync } = require('jsonql-params-validator') -const { getDebug } = require('./utils') -const debug = getDebug('check-options') +const { getDebug } = require('../utils') +const debug = getDebug('options') const { JSONQL_PATH, CONTENT_TYPE, diff --git a/packages/node-client/tests/validation.test.js b/packages/node-client/tests/validation.test.js index 90d4f620e41662c0594192db5d008228ae5c4824..9afa7b004fb69212fe08b35d29fa0ce31772e6d1 100644 --- a/packages/node-client/tests/validation.test.js +++ b/packages/node-client/tests/validation.test.js @@ -13,9 +13,9 @@ const { test.before(async t => { // we need to start a server - const { stop } = await server(3456); + const { stop } = await server(3456) t.context.stop = stop; - const contract = await contractApi(); + const contract = await contractApi() t.context.client = await nodeClient({ hostname: 'http://localhost:3456', contract, diff --git a/packages/resolver/package.json b/packages/resolver/package.json index 55d1bb64b48edfb4b4eb7de38541c35c7af0957e..f7aae6cae8a3f12ca103cfcccce7b7f60ac9507f 100644 --- a/packages/resolver/package.json +++ b/packages/resolver/package.json @@ -22,12 +22,12 @@ "url": "https://gitee.com/to1source/jsonql/issues" }, "dependencies": { - "jsonql-constants": "^1.8.2", - "jsonql-errors": "^1.1.2", + "jsonql-constants": "^1.8.3", + "jsonql-errors": "^1.1.3", "jsonql-jwt": "^1.3.1", "jsonql-node-client": "^1.1.7", "jsonql-params-validator": "^1.4.8", - "jsonql-utils": "^0.4.8", + "jsonql-utils": "^0.4.9", "lodash.merge": "^4.6.2" }, "devDependencies": { diff --git a/packages/resolver/src/client/inject-node-clients.js b/packages/resolver/src/client/inject-node-clients.js index 4762d602a7634ecc686ab4acc7094eef3f4e371a..c5269be4d23231552d16a5016c287b9a6d09f2f9 100644 --- a/packages/resolver/src/client/inject-node-clients.js +++ b/packages/resolver/src/client/inject-node-clients.js @@ -1,7 +1,9 @@ -const { getDebug } = require('../utils') +// injecting the clients into the resolver const { injectToFn } = require('jsonql-utils') +const CLIENT_PROP_NAME = require('jsonql-constants') + +const { getDebug } = require('../utils') const debug = getDebug(`inject-node-clients`) -const PROP_NAME = 'client'; /** * kind of curry the function back to inject into the resolver * @param {array} clients the node clients @@ -38,5 +40,5 @@ function resolveClients(clients) { * @return {function} the injected resolver */ module.exports = function injectNodeClient(resolver, clients) { - return injectToFn(resolver, PROP_NAME, resolveClients(clients)) + return injectToFn(resolver, CLIENT_PROP_NAME, resolveClients(clients)) } diff --git a/packages/resolver/src/validate-and-call.js b/packages/resolver/src/validate-and-call.js index 7d675267c15e7cfebfc6ad9421ecfd8448186694..2b596e04d8167c8e5faba2a140a0c5b9cfbb8c35 100644 --- a/packages/resolver/src/validate-and-call.js +++ b/packages/resolver/src/validate-and-call.js @@ -59,6 +59,12 @@ module.exports = function validateAndCall(fn, args, contract, type, name, opts) debug(`validation failed on client side`, args, params) throw new JsonqlValidationError(name, errors) } - return Promise.resolve(fn.apply(null, args)) + // fn.apply(null, args) + return Promise + .resolve(Reflect.apply(fn, null, args)) .then(applyJwtMethod(type, name, opts, contract)) + .catch(e => { + debug(`error throw inside the promise`, e) + throw e; + }) } diff --git a/packages/utils/package.json b/packages/utils/package.json index 8f7408b3725dd05c4d07f30a2485f47334c16b0d..8c7385c17cb0642d17315a4b67e06eb450c86fbf 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -1,6 +1,6 @@ { "name": "jsonql-utils", - "version": "0.4.8", + "version": "0.4.9", "description": "This is a jsonql dependency module, not for generate use.", "main": "main.js", "module": "es.js", diff --git a/packages/utils/src/koa.js b/packages/utils/src/koa.js index a81df504314a9896b705f3e1e31d1c6310f5329c..f4bd879577d8e69c41945dca82b946f7f4d08555 100644 --- a/packages/utils/src/koa.js +++ b/packages/utils/src/koa.js @@ -1,5 +1,9 @@ // koa specific methods -import { CONTENT_TYPE, SUCCESS_STATUS, FORBIDDEN_STATUS } from 'jsonql-constants' +import { + CONTENT_TYPE, + SUCCESS_STATUS, + FORBIDDEN_STATUS +} from 'jsonql-constants' // fix the default is not export by module error import * as jsonqlErrors from 'jsonql-errors' import { @@ -11,8 +15,8 @@ import { packResult, packError } from './middleware' -import { dasherize } from './generic' - +import { dasherize, getDebug } from './generic' +const debug = getDebug(`koa`, `jsonql-utils`) /** * @TODO need to be more flexible * @param {object} ctx koa @@ -84,13 +88,16 @@ export const handleHtmlOutput = function(ctx, body) { */ export const ctxErrorHandler = function(ctx, code, e, message = '') { const render = handleOutput({contentType: CONTENT_TYPE}) + debug('[ctxErrorHandler]', code, e, message) let name; if (typeof code === 'string') { name = code; code = jsonqlErrors[name] ? jsonqlErrors[name].statusCode : -1; } else { + debug(`[ctxErrorHandler] using getErrorByStatus`) name = jsonqlErrors.getErrorByStatus(code) } + debug(`[ctxErrorHandler.name]`, name) // preserve the message if (!message && e && e.message) { message = e.message;