From 5665a6afe51d579a4d55dc9c482c8188d566ca81 Mon Sep 17 00:00:00 2001 From: lakhansamani Date: Fri, 22 Sep 2017 10:26:18 +0530 Subject: [PATCH] * Removes build script from package.json * Adds build script in make file * Removes un-used modules from package.json * Changes type of time_thrown and _showLocation * Gives default type as string to name parameter in constructor and createError * Removes unsued configurations from tsconfig --- Makefile | 2 +- dist/index.js | 3 ++- dist/index.js.map | 2 +- package.json | 9 +++------ src/index.ts | 17 +++++++++++------ test/spec.js | 4 ++-- tsconfig.json | 2 -- 7 files changed, 20 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index e6404d5..8b3638a 100644 --- a/Makefile +++ b/Makefile @@ -13,7 +13,7 @@ endif .FORCE: all: clean - npm run build + tsc clean: .FORCE rimraf npm-debug.log dist diff --git a/dist/index.js b/dist/index.js index 3122edf..12bcca6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -25,7 +25,8 @@ var isObject = function (d) { return Object.prototype.toString.call(d) === '[obj var ApolloError = /** @class */ (function (_super) { __extends(ApolloError, _super); function ApolloError(name, config) { - var _this = _super.call(this, (config && config.message) || '') || this; + var _this = _super.call(this, (arguments[2] && arguments[2].message) || '') || this; + _this._showLocations = false; var t = (arguments[2] && arguments[2].time_thrown) || (new Date()).toISOString(); var m = (arguments[2] && arguments[2].message) || ''; var configData = (arguments[2] && arguments[2].data) || {}; diff --git a/dist/index.js.map b/dist/index.js.map index b0749a6..529bd5f 100644 --- a/dist/index.js.map +++ b/dist/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,+BAAiC;AACjC,qDAA+C;AAC/C,IAAM,QAAQ,GAAG,UAAA,CAAC,IAAI,OAAA,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,iBAAiB,EAAvD,CAAuD,CAAC;AAC9E,IAAM,QAAQ,GAAG,UAAA,CA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QAAQ,CAAC,MAAM,CAAC,EAAE,8DAA8D,CAAC,CAAC;IACzF,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,+FAA+F,CAAC,CAAC;IAClI,IAAM,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;IAC/C,MAAM,CAAC,CAAC,CAAC;AACX,CAAC,CAAC;AAEW,QAAA,WAAW,GAAG,UAAC,KAAK,EAAE,UAAkB;IAAlB,2BAAA,EAAA,kBAAkB;IACnD,IAAM,aAAa,GAAG,KAAK,GAAG,KAAK,CAAC,aAAa,IAAI,KAAK,GAAG,IAAI,CAAC;IAElE,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC;QAAC,MAAM,CAAC,UAAU,GAAG,IAAI,GAAG,KAAK,CAAC;IAE7C,IAAA,yBAAI,CAAmB;IAE/B,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,kBAAU,CAAC,aAAa,CAAC,CAAC;QAAC,MAAM,CAAC,UAAU,GAAG,IAAI,GAAG,KAAK,CAAC;IAElE,IAAA,uCAAW,EAAE,+BAAO,EAAE,yBAAI,EAAE,6CAAc,CAAmB;IAErE,EAAE,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC;QACX,IAAA,2BAAS,EAAE,iBAAI,CAAW;QAClC,aAAa,CAAC,SAAS,GAAG,SAAS,CAAC;QACpC,aAAa,CAAC,IAAI,GAAG,IAAI,CAAC;IAC5B,CAAC;IAED,MAAM,CAAC,aAAa,CAAC,SAAS,EAAE,CAAC;AACnC,CAAC,CAAC"} \ No newline at end of file diff --git a/package.json b/package.json index 3bdf4c0..eb3a19f 100644 --- a/package.json +++ b/package.json @@ -4,8 +4,7 @@ "description": "Machine-readable custom errors for Apollostack's GraphQL server", "main": "dist/index.js", "scripts": { - "test": "make test", - "build": "tsc" + "test": "make test" }, "repository": { "type": "git", @@ -27,8 +26,7 @@ "homepage": "https://github.com/thebigredgeek/apollo-errors#readme", "dependencies": { "assert": "^1.4.1", - "extendable-error": "^0.1.5", - "install": "^0.10.1" + "extendable-error": "^0.1.5" }, "devDependencies": { "babel-cli": "^6.18.0", @@ -41,7 +39,6 @@ "eslint-plugin-babel": "^3.3.0", "mocha": "^3.1.2", "rimraf": "^2.5.4", - "typescript": "^2.5.2", - "typings": "^2.1.1" + "typescript": "^2.5.2" } } diff --git a/src/index.ts b/src/index.ts index aeaa377..a2aec2f 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,23 +1,28 @@ import * as assert from 'assert'; import ExtendableError from 'extendable-error'; + const isString = d => Object.prototype.toString.call(d) === '[object String]'; const isObject = d => Object.prototype.toString.call(d) === '[object Object]'; + interface ErrorConfig { message: string; - time_thrown: any; + time_thrown: string; data: any, options: any, } + class ApolloError extends ExtendableError { name: string; message: string; - time_thrown: any; + time_thrown: string; data: any; path: any; locations: any; - _showLocations: any; - constructor (name, config: ErrorConfig) { - super((config && config.message) || ''); + _showLocations: boolean=false; + + constructor (name:string, config: ErrorConfig) { + super((arguments[2] && arguments[2].message) || ''); + const t = (arguments[2] && arguments[2].time_thrown) || (new Date()).toISOString(); const m = (arguments[2] && arguments[2].message) || ''; const configData = (arguments[2] && arguments[2].data) || {}; @@ -51,7 +56,7 @@ class ApolloError extends ExtendableError { export const isInstance = e => e instanceof ApolloError; -export const createError = (name, config: ErrorConfig) => { +export const createError = (name:string, config: ErrorConfig) => { assert(isObject(config), 'createError requires a config object as the second parameter'); assert(isString(config.message), 'createError requires a "message" property on the config object passed as the second parameter'); const e = ApolloError.bind(null, name, config); diff --git a/test/spec.js b/test/spec.js index 48dfee5..9036ac4 100644 --- a/test/spec.js +++ b/test/spec.js @@ -15,7 +15,7 @@ describe('createError', () => { }, options: { showLocations: false, - showPath: false, + showPath: true, }, }); const iso = new Date().toISOString(); @@ -27,7 +27,7 @@ describe('createError', () => { }, options: { showLocations: true, - showPath: true, + showPath: false, }, }); diff --git a/tsconfig.json b/tsconfig.json index c1e6bf1..f0b096c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -4,8 +4,6 @@ "module": "commonjs", "moduleResolution": "node", "sourceMap": true, - "emitDecoratorMetadata": true, - "experimentalDecorators": true, "removeComments": false, "noImplicitAny": false, "allowJs": true,