Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

graphql-scalars

Package Overview
Dependencies
Maintainers
5
Versions
1607
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-scalars - npm Package Compare versions

Comparing version 1.20.0 to 1.20.1-alpha-20221107155009-85a8c34

14

cjs/RegularExpression.js

@@ -15,3 +15,3 @@ "use strict";

if (value != null && !regex.test(value.toString())) {
throw new TypeError(errorMessage(regex, value));
throw new graphql_1.GraphQLError(errorMessage(regex, value));
}

@@ -22,3 +22,3 @@ return value;

if (value != null && !regex.test(value === null || value === void 0 ? void 0 : value.toString())) {
throw new TypeError(errorMessage(regex, value));
throw new graphql_1.GraphQLError(errorMessage(regex, value));
}

@@ -35,6 +35,8 @@ return value;

if (!('value' in ast) || ast.kind === graphql_1.Kind.ENUM) {
throw new graphql_1.GraphQLError(`Can only validate primitive values as ${name} but got a: ${ast.kind}`);
throw new graphql_1.GraphQLError(`Can only validate primitive values as ${name} but got a: ${ast.kind}`, {
nodes: [ast],
});
}
if (ast.value != null && !regex.test(ast.value.toString())) {
throw new TypeError(errorMessage(regex, ast.value));
throw new graphql_1.GraphQLError(errorMessage(regex, ast.value), { nodes: [ast] });
}

@@ -44,5 +46,3 @@ return ast.value;

extensions: {
codegenScalarType: options.stringOnly
? 'string'
: 'string | number | boolean',
codegenScalarType: options.stringOnly ? 'string' : 'string | number | boolean',
},

@@ -49,0 +49,0 @@ });

@@ -7,8 +7,12 @@ "use strict";

const validator = rtn => regexp.test(rtn);
const validate = (account) => {
const validate = (account, ast) => {
if (typeof account !== 'string') {
throw (0, graphql_1.locatedError)(new TypeError('can only parse String'), null);
throw new graphql_1.GraphQLError('can only parse String', {
nodes: ast ? [ast] : undefined,
});
}
if (!validator(account)) {
throw (0, graphql_1.locatedError)(new TypeError('must be alphanumeric between 5-17'), null);
throw new graphql_1.GraphQLError('must be alphanumeric between 5-17', {
nodes: ast ? [ast] : undefined,
});
}

@@ -28,5 +32,7 @@ return account;

if (ast.kind === graphql_1.Kind.STRING) {
return validate(ast.value);
return validate(ast.value, ast);
}
throw (0, graphql_1.locatedError)(new TypeError(`Account Number can only parse String but got '${ast.kind}'`), ast);
throw new graphql_1.GraphQLError(`Account Number can only parse String but got '${ast.kind}'`, {
nodes: [ast],
});
},

@@ -33,0 +39,0 @@ extensions: {

@@ -20,5 +20,7 @@ "use strict";

}
function validate(value) {
function validate(value, ast) {
if (typeof value !== 'string' && !(value instanceof global.Buffer)) {
throw new TypeError(`Value is not an instance of Buffer: ${JSON.stringify(value)}`);
throw new graphql_1.GraphQLError(`Value is not an instance of Buffer: ${JSON.stringify(value)}`, {
nodes: ast ? [ast] : undefined,
});
}

@@ -29,3 +31,5 @@ if (typeof value === 'string') {

if (!isBase64 && !isHex) {
throw new TypeError(`Value is not a valid base64 or hex encoded string: ${JSON.stringify(value)}`);
throw new graphql_1.GraphQLError(`Value is not a valid base64 or hex encoded string: ${JSON.stringify(value)}`, {
nodes: ast ? [ast] : undefined,
});
}

@@ -42,3 +46,5 @@ return global.Buffer.from(value, isHex ? 'hex' : 'base64');

}
throw new TypeError(`Value is not a JSON representation of Buffer: ${(0, graphql_1.print)(ast)}`);
throw new graphql_1.GraphQLError(`Value is not a JSON representation of Buffer: ${(0, graphql_1.print)(ast)}`, {
nodes: [ast],
});
}

@@ -53,7 +59,9 @@ exports.GraphQLByteConfig = {

case graphql_1.Kind.STRING:
return validate(ast.value);
return validate(ast.value, ast);
case graphql_1.Kind.OBJECT:
return parseObject(ast);
default:
throw new TypeError(`Can only parse base64 or hex encoded strings as Byte, but got a: ${ast.kind}`);
throw new graphql_1.GraphQLError(`Can only parse base64 or hex encoded strings as Byte, but got a: ${ast.kind}`, {
nodes: [ast],
});
}

@@ -60,0 +68,0 @@ },

@@ -6,8 +6,12 @@ "use strict";

const COUNTRY_CODE_REGEX = /^(AD|AE|AF|AG|AI|AL|AM|AO|AQ|AR|AS|AT|AU|AW|AX|AZ|BA|BB|BD|BE|BF|BG|BH|BI|BJ|BL|BM|BN|BO|BQ|BR|BS|BT|BV|BW|BY|BZ|CA|CC|CD|CF|CG|CH|CI|CK|CL|CM|CN|CO|CR|CU|CV|CW|CX|CY|CZ|DE|DJ|DK|DM|DO|DZ|EC|EE|EG|EH|ER|ES|ET|FI|FJ|FK|FM|FO|FR|GA|GB|GD|GE|GF|GG|GH|GI|GL|GM|GN|GP|GQ|GR|GS|GT|GU|GW|GY|HK|HM|HN|HR|HT|HU|ID|IE|IL|IM|IN|IO|IQ|IR|IS|IT|JE|JM|JO|JP|KE|KG|KH|KI|KM|KN|KP|KR|KW|KY|KZ|LA|LB|LC|LI|LK|LR|LS|LT|LU|LV|LY|MA|MC|MD|ME|MF|MG|MH|MK|ML|MM|MN|MO|MP|MQ|MR|MS|MT|MU|MV|MW|MX|MY|MZ|NA|NC|NE|NF|NG|NI|NL|NO|NP|NR|NU|NZ|OM|PA|PE|PF|PG|PH|PK|PL|PM|PN|PR|PS|PT|PW|PY|QA|RE|RO|RS|RU|RW|SA|SB|SC|SD|SE|SG|SH|SI|SJ|SK|SL|SM|SN|SO|SR|SS|ST|SV|SX|SY|SZ|TC|TD|TF|TG|TH|TJ|TK|TL|TM|TN|TO|TR|TT|TV|TW|TZ|UA|UG|UM|US|UY|UZ|VA|VC|VE|VG|VI|VN|VU|WF|WS|YE|YT|ZA|ZM|ZW)$/i;
const validate = (value) => {
const validate = (value, ast) => {
if (typeof value !== 'string') {
throw new TypeError(`Value is not string: ${value}`);
throw new graphql_1.GraphQLError(`Value is not string: ${value}`, {
nodes: ast ? [ast] : undefined,
});
}
if (!COUNTRY_CODE_REGEX.test(value)) {
throw new TypeError(`Value is not a valid country code: ${value}`);
throw new graphql_1.GraphQLError(`Value is not a valid country code: ${value}`, {
nodes: ast ? [ast] : undefined,
});
}

@@ -27,5 +31,7 @@ return value;

if (ast.kind !== graphql_1.Kind.STRING) {
throw new graphql_1.GraphQLError(`Can only validate strings as country codes but got a: ${ast.kind}`);
throw new graphql_1.GraphQLError(`Can only validate strings as country codes but got a: ${ast.kind}`, {
nodes: [ast],
});
}
return validate(ast.value);
return validate(ast.value, ast);
},

@@ -32,0 +38,0 @@ extensions: {

@@ -6,8 +6,12 @@ "use strict";

const CUID_REGEX = /^c[^\s-]{8,}$/i;
const validate = (value) => {
const validate = (value, ast) => {
if (typeof value !== 'string') {
throw new TypeError(`Value is not string: ${value}`);
throw new graphql_1.GraphQLError(`Value is not string: ${value}`, {
nodes: ast ? [ast] : undefined,
});
}
if (!CUID_REGEX.test(value)) {
throw new TypeError(`Value is not a valid cuid: ${value}`);
throw new graphql_1.GraphQLError(`Value is not a valid cuid: ${value}`, {
nodes: ast ? [ast] : undefined,
});
}

@@ -24,5 +28,7 @@ return value;

if (ast.kind !== graphql_1.Kind.STRING) {
throw new graphql_1.GraphQLError(`Can only validate strings as cuids but got a: ${ast.kind}`);
throw new graphql_1.GraphQLError(`Can only validate strings as cuids but got a: ${ast.kind}`, {
nodes: [ast],
});
}
return validate(ast.value);
return validate(ast.value, ast);
},

@@ -29,0 +35,0 @@ specifiedByURL,

@@ -10,5 +10,7 @@ "use strict";

// eslint-disable-next-line @typescript-eslint/ban-types
function ensureObject(value) {
function ensureObject(value, ast) {
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
throw new TypeError(`JSONObject cannot represent non-object value: ${value}`);
throw new graphql_1.GraphQLError(`JSONObject cannot represent non-object value: ${value}`, {
nodes: ast ? [ast] : undefined,
});
}

@@ -20,3 +22,3 @@ return value;

const value = Object.create(null);
ast.fields.forEach((field) => {
ast.fields.forEach(field => {
// eslint-disable-next-line no-use-before-define

@@ -39,3 +41,3 @@ value[field.name.value] = parseLiteral(field.value, variables);

case graphql_1.Kind.LIST:
return ast.values.map((n) => parseLiteral(n, variables));
return ast.values.map(n => parseLiteral(n, variables));
case graphql_1.Kind.NULL:

@@ -42,0 +44,0 @@ return null;

@@ -5,5 +5,7 @@ "use strict";

const graphql_1 = require("graphql");
const validateTimeZone = (str) => {
const validateTimeZone = (str, ast) => {
if (!(Intl === null || Intl === void 0 ? void 0 : Intl.DateTimeFormat().resolvedOptions().timeZone)) {
throw new Error('Time zones are not available in this environment');
throw new graphql_1.GraphQLError('Time zones are not available in this environment', {
nodes: ast ? [ast] : undefined,
});
}

@@ -16,6 +18,10 @@ try {

if (ex instanceof RangeError) {
throw new TypeError(`Value is not a valid IANA time zone: ${str}`);
throw new graphql_1.GraphQLError(`Value is not a valid IANA time zone: ${str}`, {
nodes: ast ? [ast] : undefined,
});
}
else {
throw new Error('Could not validate time zone.');
throw new graphql_1.GraphQLError('Could not validate time zone.', {
nodes: ast ? [ast] : undefined,
});
}

@@ -22,0 +28,0 @@ }

@@ -12,3 +12,3 @@ import { GraphQLError, GraphQLScalarType, Kind } from 'graphql';

if (value != null && !regex.test(value.toString())) {
throw new TypeError(errorMessage(regex, value));
throw new GraphQLError(errorMessage(regex, value));
}

@@ -19,3 +19,3 @@ return value;

if (value != null && !regex.test(value === null || value === void 0 ? void 0 : value.toString())) {
throw new TypeError(errorMessage(regex, value));
throw new GraphQLError(errorMessage(regex, value));
}

@@ -32,6 +32,8 @@ return value;

if (!('value' in ast) || ast.kind === Kind.ENUM) {
throw new GraphQLError(`Can only validate primitive values as ${name} but got a: ${ast.kind}`);
throw new GraphQLError(`Can only validate primitive values as ${name} but got a: ${ast.kind}`, {
nodes: [ast],
});
}
if (ast.value != null && !regex.test(ast.value.toString())) {
throw new TypeError(errorMessage(regex, ast.value));
throw new GraphQLError(errorMessage(regex, ast.value), { nodes: [ast] });
}

@@ -41,5 +43,3 @@ return ast.value;

extensions: {
codegenScalarType: options.stringOnly
? 'string'
: 'string | number | boolean',
codegenScalarType: options.stringOnly ? 'string' : 'string | number | boolean',
},

@@ -46,0 +46,0 @@ });

@@ -1,10 +0,14 @@

import { GraphQLScalarType, Kind, locatedError } from 'graphql';
import { GraphQLError, GraphQLScalarType, Kind } from 'graphql';
const regexp = /^([a-zA-Z0-9]){5,17}$/;
const validator = rtn => regexp.test(rtn);
const validate = (account) => {
const validate = (account, ast) => {
if (typeof account !== 'string') {
throw locatedError(new TypeError('can only parse String'), null);
throw new GraphQLError('can only parse String', {
nodes: ast ? [ast] : undefined,
});
}
if (!validator(account)) {
throw locatedError(new TypeError('must be alphanumeric between 5-17'), null);
throw new GraphQLError('must be alphanumeric between 5-17', {
nodes: ast ? [ast] : undefined,
});
}

@@ -24,5 +28,7 @@ return account;

if (ast.kind === Kind.STRING) {
return validate(ast.value);
return validate(ast.value, ast);
}
throw locatedError(new TypeError(`Account Number can only parse String but got '${ast.kind}'`), ast);
throw new GraphQLError(`Account Number can only parse String but got '${ast.kind}'`, {
nodes: [ast],
});
},

@@ -29,0 +35,0 @@ extensions: {

@@ -1,2 +0,2 @@

import { GraphQLScalarType, Kind, print, } from 'graphql';
import { GraphQLError, GraphQLScalarType, Kind, print, } from 'graphql';
const base64Validator = /^(?:[A-Za-z0-9+\/]{4})*(?:[A-Za-z0-9+\/]{2}==|[A-Za-z0-9+\/]{3}=)?$/;

@@ -17,5 +17,7 @@ function hexValidator(value) {

}
function validate(value) {
function validate(value, ast) {
if (typeof value !== 'string' && !(value instanceof global.Buffer)) {
throw new TypeError(`Value is not an instance of Buffer: ${JSON.stringify(value)}`);
throw new GraphQLError(`Value is not an instance of Buffer: ${JSON.stringify(value)}`, {
nodes: ast ? [ast] : undefined,
});
}

@@ -26,3 +28,5 @@ if (typeof value === 'string') {

if (!isBase64 && !isHex) {
throw new TypeError(`Value is not a valid base64 or hex encoded string: ${JSON.stringify(value)}`);
throw new GraphQLError(`Value is not a valid base64 or hex encoded string: ${JSON.stringify(value)}`, {
nodes: ast ? [ast] : undefined,
});
}

@@ -39,3 +43,5 @@ return global.Buffer.from(value, isHex ? 'hex' : 'base64');

}
throw new TypeError(`Value is not a JSON representation of Buffer: ${print(ast)}`);
throw new GraphQLError(`Value is not a JSON representation of Buffer: ${print(ast)}`, {
nodes: [ast],
});
}

@@ -50,7 +56,9 @@ export const GraphQLByteConfig = /*#__PURE__*/ {

case Kind.STRING:
return validate(ast.value);
return validate(ast.value, ast);
case Kind.OBJECT:
return parseObject(ast);
default:
throw new TypeError(`Can only parse base64 or hex encoded strings as Byte, but got a: ${ast.kind}`);
throw new GraphQLError(`Can only parse base64 or hex encoded strings as Byte, but got a: ${ast.kind}`, {
nodes: [ast],
});
}

@@ -57,0 +65,0 @@ },

import { Kind, GraphQLError, GraphQLScalarType } from 'graphql';
const COUNTRY_CODE_REGEX = /^(AD|AE|AF|AG|AI|AL|AM|AO|AQ|AR|AS|AT|AU|AW|AX|AZ|BA|BB|BD|BE|BF|BG|BH|BI|BJ|BL|BM|BN|BO|BQ|BR|BS|BT|BV|BW|BY|BZ|CA|CC|CD|CF|CG|CH|CI|CK|CL|CM|CN|CO|CR|CU|CV|CW|CX|CY|CZ|DE|DJ|DK|DM|DO|DZ|EC|EE|EG|EH|ER|ES|ET|FI|FJ|FK|FM|FO|FR|GA|GB|GD|GE|GF|GG|GH|GI|GL|GM|GN|GP|GQ|GR|GS|GT|GU|GW|GY|HK|HM|HN|HR|HT|HU|ID|IE|IL|IM|IN|IO|IQ|IR|IS|IT|JE|JM|JO|JP|KE|KG|KH|KI|KM|KN|KP|KR|KW|KY|KZ|LA|LB|LC|LI|LK|LR|LS|LT|LU|LV|LY|MA|MC|MD|ME|MF|MG|MH|MK|ML|MM|MN|MO|MP|MQ|MR|MS|MT|MU|MV|MW|MX|MY|MZ|NA|NC|NE|NF|NG|NI|NL|NO|NP|NR|NU|NZ|OM|PA|PE|PF|PG|PH|PK|PL|PM|PN|PR|PS|PT|PW|PY|QA|RE|RO|RS|RU|RW|SA|SB|SC|SD|SE|SG|SH|SI|SJ|SK|SL|SM|SN|SO|SR|SS|ST|SV|SX|SY|SZ|TC|TD|TF|TG|TH|TJ|TK|TL|TM|TN|TO|TR|TT|TV|TW|TZ|UA|UG|UM|US|UY|UZ|VA|VC|VE|VG|VI|VN|VU|WF|WS|YE|YT|ZA|ZM|ZW)$/i;
const validate = (value) => {
const validate = (value, ast) => {
if (typeof value !== 'string') {
throw new TypeError(`Value is not string: ${value}`);
throw new GraphQLError(`Value is not string: ${value}`, {
nodes: ast ? [ast] : undefined,
});
}
if (!COUNTRY_CODE_REGEX.test(value)) {
throw new TypeError(`Value is not a valid country code: ${value}`);
throw new GraphQLError(`Value is not a valid country code: ${value}`, {
nodes: ast ? [ast] : undefined,
});
}

@@ -23,5 +27,7 @@ return value;

if (ast.kind !== Kind.STRING) {
throw new GraphQLError(`Can only validate strings as country codes but got a: ${ast.kind}`);
throw new GraphQLError(`Can only validate strings as country codes but got a: ${ast.kind}`, {
nodes: [ast],
});
}
return validate(ast.value);
return validate(ast.value, ast);
},

@@ -28,0 +34,0 @@ extensions: {

import { Kind, GraphQLError, GraphQLScalarType } from 'graphql';
const CUID_REGEX = /^c[^\s-]{8,}$/i;
const validate = (value) => {
const validate = (value, ast) => {
if (typeof value !== 'string') {
throw new TypeError(`Value is not string: ${value}`);
throw new GraphQLError(`Value is not string: ${value}`, {
nodes: ast ? [ast] : undefined,
});
}
if (!CUID_REGEX.test(value)) {
throw new TypeError(`Value is not a valid cuid: ${value}`);
throw new GraphQLError(`Value is not a valid cuid: ${value}`, {
nodes: ast ? [ast] : undefined,
});
}

@@ -20,5 +24,7 @@ return value;

if (ast.kind !== Kind.STRING) {
throw new GraphQLError(`Can only validate strings as cuids but got a: ${ast.kind}`);
throw new GraphQLError(`Can only validate strings as cuids but got a: ${ast.kind}`, {
nodes: [ast],
});
}
return validate(ast.value);
return validate(ast.value, ast);
},

@@ -25,0 +31,0 @@ specifiedByURL,

@@ -1,2 +0,2 @@

import { Kind } from 'graphql';
import { Kind, GraphQLError } from 'graphql';
export function identity(value) {

@@ -6,5 +6,7 @@ return value;

// eslint-disable-next-line @typescript-eslint/ban-types
export function ensureObject(value) {
export function ensureObject(value, ast) {
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
throw new TypeError(`JSONObject cannot represent non-object value: ${value}`);
throw new GraphQLError(`JSONObject cannot represent non-object value: ${value}`, {
nodes: ast ? [ast] : undefined,
});
}

@@ -15,3 +17,3 @@ return value;

const value = Object.create(null);
ast.fields.forEach((field) => {
ast.fields.forEach(field => {
// eslint-disable-next-line no-use-before-define

@@ -33,3 +35,3 @@ value[field.name.value] = parseLiteral(field.value, variables);

case Kind.LIST:
return ast.values.map((n) => parseLiteral(n, variables));
return ast.values.map(n => parseLiteral(n, variables));
case Kind.NULL:

@@ -36,0 +38,0 @@ return null;

import { GraphQLScalarType, GraphQLError, Kind } from 'graphql';
const validateTimeZone = (str) => {
const validateTimeZone = (str, ast) => {
if (!(Intl === null || Intl === void 0 ? void 0 : Intl.DateTimeFormat().resolvedOptions().timeZone)) {
throw new Error('Time zones are not available in this environment');
throw new GraphQLError('Time zones are not available in this environment', {
nodes: ast ? [ast] : undefined,
});
}

@@ -12,6 +14,10 @@ try {

if (ex instanceof RangeError) {
throw new TypeError(`Value is not a valid IANA time zone: ${str}`);
throw new GraphQLError(`Value is not a valid IANA time zone: ${str}`, {
nodes: ast ? [ast] : undefined,
});
}
else {
throw new Error('Could not validate time zone.');
throw new GraphQLError('Could not validate time zone.', {
nodes: ast ? [ast] : undefined,
});
}

@@ -18,0 +24,0 @@ }

{
"name": "graphql-scalars",
"version": "1.20.0",
"version": "1.20.1-alpha-20221107155009-85a8c34",
"description": "A collection of scalar types not included in base GraphQL.",

@@ -5,0 +5,0 @@ "sideEffects": false,

import { ValueNode, ObjectValueNode } from 'graphql';
export declare function identity<T>(value: T): T;
export declare function ensureObject(value: any): object;
export declare function ensureObject(value: any, ast?: ValueNode): object;
export declare function parseObject(ast: ObjectValueNode, variables: any): any;
export declare function parseLiteral(ast: ValueNode, variables: any): any;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc