graphql-scalar
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -6,1 +6,2 @@ import { ValueNode } from 'graphql'; | ||
export declare const getValueFromValueNode: (ast: ValueNode) => any; | ||
//# sourceMappingURL=common.d.ts.map |
@@ -1,22 +0,20 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const graphql_1 = require("graphql"); | ||
const error_1 = require("graphql/error"); | ||
exports.defaultErrorHandler = ({ code, ast, }) => { | ||
throw new error_1.GraphQLError(`code=${code}`, ast ? [ast] : []); | ||
import { Kind, } from 'graphql'; | ||
import { GraphQLError } from 'graphql/error'; | ||
export const defaultErrorHandler = ({ code, ast, }) => { | ||
throw new GraphQLError(`code=${code}`, ast ? [ast] : []); | ||
}; | ||
exports.defaultSerialize = (x) => x; | ||
exports.getValueFromValueNode = (ast) => { | ||
export const defaultSerialize = (x) => x; | ||
export const getValueFromValueNode = (ast) => { | ||
switch (ast.kind) { | ||
case graphql_1.Kind.BOOLEAN: | ||
case Kind.BOOLEAN: | ||
return ast.value; | ||
case graphql_1.Kind.FLOAT: | ||
case Kind.FLOAT: | ||
return parseFloat(ast.value); | ||
case graphql_1.Kind.INT: | ||
case Kind.INT: | ||
return parseInt(ast.value, 10); | ||
case graphql_1.Kind.NULL: | ||
case Kind.NULL: | ||
return null; | ||
case graphql_1.Kind.STRING: | ||
case Kind.STRING: | ||
return ast.value; | ||
case graphql_1.Kind.ENUM: | ||
case Kind.ENUM: | ||
return ast.value; | ||
@@ -23,0 +21,0 @@ } |
@@ -10,1 +10,2 @@ import { GraphQLScalarType } from 'graphql'; | ||
export declare const createFloatScalar: <TInternal = string, TExternal = string>(config: IFloatScalarConfig<TInternal, TExternal>) => GraphQLScalarType; | ||
//# sourceMappingURL=float.d.ts.map |
@@ -1,20 +0,7 @@ | ||
"use strict"; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const graphql_1 = require("graphql"); | ||
const common_1 = require("./common"); | ||
exports.isSafeFloat = (n) => typeof n === 'number' && isFinite(n); | ||
exports.createFloatScalar = (config) => { | ||
const { coerce, errorHandler, maximum, minimum, parse, sanitize, validate, serialize } = config, scalarConfig = __rest(config, ["coerce", "errorHandler", "maximum", "minimum", "parse", "sanitize", "validate", "serialize"]); | ||
const handleError = errorHandler || common_1.defaultErrorHandler; | ||
import { GraphQLScalarType } from 'graphql'; | ||
import { defaultErrorHandler, defaultSerialize, getValueFromValueNode, } from './common'; | ||
export const isSafeFloat = (n) => typeof n === 'number' && isFinite(n); | ||
export const createFloatScalar = (config) => { | ||
const { coerce, errorHandler, maximum, minimum, parse, sanitize, validate, serialize, ...scalarConfig } = config; | ||
const handleError = errorHandler || defaultErrorHandler; | ||
const parseValue = (unknownValue, ast) => { | ||
@@ -25,3 +12,3 @@ if (unknownValue == null) { | ||
let value; | ||
if (exports.isSafeFloat(unknownValue)) { | ||
if (isSafeFloat(unknownValue)) { | ||
value = unknownValue; | ||
@@ -86,4 +73,9 @@ } | ||
}; | ||
return new graphql_1.GraphQLScalarType(Object.assign({}, scalarConfig, { serialize: serialize || common_1.defaultSerialize, parseValue, parseLiteral: (ast) => parseValue(common_1.getValueFromValueNode(ast), ast) })); | ||
return new GraphQLScalarType({ | ||
...scalarConfig, | ||
serialize: serialize || defaultSerialize, | ||
parseValue, | ||
parseLiteral: (ast) => parseValue(getValueFromValueNode(ast), ast), | ||
}); | ||
}; | ||
//# sourceMappingURL=float.js.map |
@@ -6,1 +6,2 @@ export * from './common'; | ||
export * from './ts'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -1,10 +0,5 @@ | ||
"use strict"; | ||
function __export(m) { | ||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p]; | ||
} | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
__export(require("./common")); | ||
__export(require("./float")); | ||
__export(require("./int")); | ||
__export(require("./string")); | ||
export * from './common'; | ||
export * from './float'; | ||
export * from './int'; | ||
export * from './string'; | ||
//# sourceMappingURL=index.js.map |
@@ -10,1 +10,2 @@ import { GraphQLScalarType } from 'graphql'; | ||
export declare const createIntScalar: <TInternal = string, TExternal = string>(config: IIntScalarConfig<TInternal, TExternal>) => GraphQLScalarType; | ||
//# sourceMappingURL=int.d.ts.map |
@@ -1,19 +0,6 @@ | ||
"use strict"; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const graphql_1 = require("graphql"); | ||
const common_1 = require("./common"); | ||
import { GraphQLScalarType } from 'graphql'; | ||
import { defaultErrorHandler, defaultSerialize, getValueFromValueNode, } from './common'; | ||
const MAX_INT = 2147483647; | ||
const MIN_INT = -2147483648; | ||
exports.isSafeInteger = (n) => typeof n === 'number' && | ||
export const isSafeInteger = (n) => typeof n === 'number' && | ||
isFinite(n) && | ||
@@ -23,5 +10,5 @@ Math.floor(n) === n && | ||
n >= MIN_INT; | ||
exports.createIntScalar = (config) => { | ||
const { coerce, errorHandler, maximum, minimum, parse, sanitize, validate, serialize } = config, scalarConfig = __rest(config, ["coerce", "errorHandler", "maximum", "minimum", "parse", "sanitize", "validate", "serialize"]); | ||
const handleError = errorHandler || common_1.defaultErrorHandler; | ||
export const createIntScalar = (config) => { | ||
const { coerce, errorHandler, maximum, minimum, parse, sanitize, validate, serialize, ...scalarConfig } = config; | ||
const handleError = errorHandler || defaultErrorHandler; | ||
const parseValue = (unknownValue, ast) => { | ||
@@ -32,3 +19,3 @@ if (unknownValue == null) { | ||
let value; | ||
if (exports.isSafeInteger(unknownValue)) { | ||
if (isSafeInteger(unknownValue)) { | ||
value = unknownValue; | ||
@@ -93,4 +80,9 @@ } | ||
}; | ||
return new graphql_1.GraphQLScalarType(Object.assign({}, scalarConfig, { serialize: serialize || common_1.defaultSerialize, parseValue, parseLiteral: (ast) => parseValue(common_1.getValueFromValueNode(ast), ast) })); | ||
return new GraphQLScalarType({ | ||
...scalarConfig, | ||
serialize: serialize || defaultSerialize, | ||
parseValue, | ||
parseLiteral: (ast) => parseValue(getValueFromValueNode(ast), ast), | ||
}); | ||
}; | ||
//# sourceMappingURL=int.js.map |
@@ -20,1 +20,2 @@ import { GraphQLScalarType } from 'graphql'; | ||
export declare const createStringScalar: <TInternal = string, TExternal = string>(config: IStringScalarConfig<TInternal, TExternal>) => GraphQLScalarType; | ||
//# sourceMappingURL=string.d.ts.map |
@@ -1,16 +0,3 @@ | ||
"use strict"; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const graphql_1 = require("graphql"); | ||
const common_1 = require("./common"); | ||
import { GraphQLScalarType } from 'graphql'; | ||
import { defaultErrorHandler, defaultSerialize, getValueFromValueNode, } from './common'; | ||
const strToUpperCase = (str) => str.toUpperCase(); | ||
@@ -23,6 +10,6 @@ const wordRegex = /(?:^|\s)\S/g; | ||
const collapseWS = (str) => str.replace(whitespace, ' '); | ||
exports.createStringScalar = (config) => { | ||
const { capitalize, coerce, collapseWhitespace, errorHandler, lowercase, maxLength, minLength, nonEmpty, parse, pattern, sanitize, serialize, singleline, trim, trimLeft, trimRight, truncate, uppercase, validate } = config, scalarConfig = __rest(config, ["capitalize", "coerce", "collapseWhitespace", "errorHandler", "lowercase", "maxLength", "minLength", "nonEmpty", "parse", "pattern", "sanitize", "serialize", "singleline", "trim", "trimLeft", "trimRight", "truncate", "uppercase", "validate"]); | ||
export const createStringScalar = (config) => { | ||
const { capitalize, coerce, collapseWhitespace, errorHandler, lowercase, maxLength, minLength, nonEmpty, parse, pattern, sanitize, serialize, singleline, trim, trimLeft, trimRight, truncate, uppercase, validate, ...scalarConfig } = config; | ||
const regex = typeof pattern === 'string' ? new RegExp(pattern) : pattern; | ||
const handleError = errorHandler || common_1.defaultErrorHandler; | ||
const handleError = errorHandler || defaultErrorHandler; | ||
const parseValue = (unknownValue, ast) => { | ||
@@ -166,4 +153,9 @@ if (unknownValue == null) { | ||
}; | ||
return new graphql_1.GraphQLScalarType(Object.assign({}, scalarConfig, { serialize: serialize || common_1.defaultSerialize, parseValue, parseLiteral: (ast) => parseValue(common_1.getValueFromValueNode(ast), ast) })); | ||
return new GraphQLScalarType({ | ||
...scalarConfig, | ||
serialize: serialize || defaultSerialize, | ||
parseValue, | ||
parseLiteral: (ast) => parseValue(getValueFromValueNode(ast), ast), | ||
}); | ||
}; | ||
//# sourceMappingURL=string.js.map |
@@ -24,1 +24,2 @@ import { GraphQLScalarTypeConfig, ValueNode } from 'graphql'; | ||
} | ||
//# sourceMappingURL=ts.d.ts.map |
@@ -1,3 +0,1 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
//# sourceMappingURL=ts.js.map |
{ | ||
"name": "graphql-scalar", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Configurable custom GraphQL Scalars (string, number, date, etc) with sanitization / validation / transformation in TypeScript.", | ||
@@ -22,15 +22,19 @@ "keywords": [ | ||
], | ||
"main": "lib/index.js", | ||
"module": "lib/index.js", | ||
"main": "dist/node/index.js", | ||
"browser": "dist/browser/index.js", | ||
"types": "lib/index.d.ts", | ||
"scripts": { | ||
"all": "npm run clean && npm run format && npm run lint:fix && npm run test && npm run build && npm run build:es5", | ||
"build": "tsc -p ./tsconfig.json && tscpaths -p ./tsconfig.json -s ./src -o ./lib", | ||
"build:es5": "tsc -p ./tsconfig.es5.json && tscpaths -p ./tsconfig.es5.json -s ./src -o ./es5", | ||
"clean": "rm -rf ./lib ./es5 ./es6 ./coverage", | ||
"all": "npm run clean && npm run format && npm run lint:fix && npm run build:all && npm run test", | ||
"build:all": "npm run build:module && npm run build:node && npm run build:browser", | ||
"build:browser": "tsc -p ./tsconfig.browser.json && tscpaths -p ./tsconfig.browser.json -s ./src -o ./dist/browser", | ||
"build:module": "tsc -p ./tsconfig.module.json && tscpaths -p ./tsconfig.module.json -s ./src -o ./lib", | ||
"build:node": "tsc -p ./tsconfig.node.json && tscpaths -p ./tsconfig.node.json -s ./src -o ./dist/node", | ||
"clean": "rm -rf ./lib ./dist ./coverage", | ||
"format": "prettier --write \"./*.{js,jsx,ts,tsx}\" \"./src/**/*.{js,jsx,ts,tsx}\"", | ||
"lint": "tslint -c ./tslint.json \"src/**/*\"", | ||
"lint:fix": "tslint --fix -c ./tslint.json \"src/**/*\"", | ||
"lint": "tslint -c ./tslint.json \"src/**/*.ts\"", | ||
"lint:fix": "tslint --fix -c ./tslint.json \"src/**/*.ts\"", | ||
"precommit": "npm run all", | ||
"prepublish": "npm run all", | ||
"reinstall": "rm -rf ./node_modules ./package-lock.json ./yarn.lock && npm i", | ||
"reinstall": "rm -rf ./node_modules ./package-lock.json ./yarn.lock && yarn", | ||
"start": "npm run test", | ||
@@ -59,3 +63,3 @@ "test": "jest", | ||
"@types/jest": "^24.0.15", | ||
"@types/node": "^12.0.12", | ||
"@types/node": "^12.6.2", | ||
"coveralls": "^3.0.4", | ||
@@ -72,4 +76,4 @@ "graphql": "^14.4.0", | ||
"tslint-config-prettier": "^1.18.0", | ||
"typescript": "^3.5.2" | ||
"typescript": "^3.5.3" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
99902
75
1366
1