@graphql-tools/wrap
Advanced tools
Comparing version 6.0.10 to 6.0.11-alpha-002e171.0
181
index.cjs.js
@@ -5,4 +5,2 @@ 'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
const graphql = require('graphql'); | ||
@@ -12,3 +10,2 @@ const utils = require('@graphql-tools/utils'); | ||
const schema = require('@graphql-tools/schema'); | ||
const AggregateError = _interopDefault(require('aggregate-error')); | ||
@@ -1183,2 +1180,180 @@ function generateProxyingResolvers(subschemaOrSubschemaConfig, transforms) { | ||
/** | ||
Escape RegExp special characters. | ||
You can also use this to escape a string that is inserted into the middle of a regex, for example, into a character class. | ||
@example | ||
``` | ||
import escapeStringRegexp = require('escape-string-regexp'); | ||
const escapedString = escapeStringRegexp('How much $ for a 🦄?'); | ||
//=> 'How much \\$ for a 🦄\\?' | ||
new RegExp(escapedString); | ||
``` | ||
*/ | ||
const escapeStringRegexp = (string) => { | ||
if (typeof string !== 'string') { | ||
throw new TypeError('Expected a string'); | ||
} | ||
// Escape characters with special meaning either inside or outside character sets. | ||
// Use a simple backslash escape when it’s always valid, and a `\xnn` escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar. | ||
return string | ||
.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&') | ||
.replace(/-/g, '\\x2d'); | ||
}; | ||
const extractPathRegex = /\s+at.*[(\s](.*)\)?/; | ||
const pathRegex = /^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:babel-polyfill|pirates)\/.*)?\w+)\.js:\d+:\d+)|native)/; | ||
/** | ||
Clean up error stack traces. Removes the mostly unhelpful internal Node.js entries. | ||
@param stack - The `stack` property of an `Error`. | ||
@example | ||
``` | ||
import cleanStack = require('clean-stack'); | ||
const error = new Error('Missing unicorn'); | ||
console.log(error.stack); | ||
// Error: Missing unicorn | ||
// at Object.<anonymous> (/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15) | ||
// at Module._compile (module.js:409:26) | ||
// at Object.Module._extensions..js (module.js:416:10) | ||
// at Module.load (module.js:343:32) | ||
// at Function.Module._load (module.js:300:12) | ||
// at Function.Module.runMain (module.js:441:10) | ||
// at startup (node.js:139:18) | ||
console.log(cleanStack(error.stack)); | ||
// Error: Missing unicorn | ||
// at Object.<anonymous> (/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15) | ||
``` | ||
*/ | ||
const cleanStack = (stack, basePath) => { | ||
const basePathRegex = basePath && new RegExp(`(at | \\()${escapeStringRegexp(basePath)}`, 'g'); | ||
return stack.replace(/\\/g, '/') | ||
.split('\n') | ||
.filter(line => { | ||
const pathMatches = line.match(extractPathRegex); | ||
if (pathMatches === null || !pathMatches[1]) { | ||
return true; | ||
} | ||
const match = pathMatches[1]; | ||
// Electron | ||
if (match.includes('.app/Contents/Resources/electron.asar') || | ||
match.includes('.app/Contents/Resources/default_app.asar')) { | ||
return false; | ||
} | ||
return !pathRegex.test(match); | ||
}) | ||
.filter(line => line.trim() !== '') | ||
.map(line => { | ||
if (basePathRegex) { | ||
line = line.replace(basePathRegex, '$1'); | ||
} | ||
return line; | ||
}) | ||
.join('\n'); | ||
}; | ||
const cleanInternalStack = (stack) => stack.replace(/\s+at .*aggregate-error\/index.js:\d+:\d+\)?/g, ''); | ||
/** | ||
Indent each line in a string. | ||
@param string - The string to indent. | ||
@param count - How many times you want `options.indent` repeated. Default: `1`. | ||
@example | ||
``` | ||
import indentString = require('indent-string'); | ||
indentString('Unicorns\nRainbows', 4); | ||
//=> ' Unicorns\n Rainbows' | ||
indentString('Unicorns\nRainbows', 4, {indent: '♥'}); | ||
//=> '♥♥♥♥Unicorns\n♥♥♥♥Rainbows' | ||
``` | ||
*/ | ||
const indentString = (string, count = 1, options) => { | ||
options = { | ||
indent: ' ', | ||
includeEmptyLines: false, | ||
...options | ||
}; | ||
if (typeof string !== 'string') { | ||
throw new TypeError(`Expected \`input\` to be a \`string\`, got \`${typeof string}\``); | ||
} | ||
if (typeof count !== 'number') { | ||
throw new TypeError(`Expected \`count\` to be a \`number\`, got \`${typeof count}\``); | ||
} | ||
if (count < 0) { | ||
throw new RangeError(`Expected \`count\` to be at least 0, got \`${count}\``); | ||
} | ||
if (typeof options.indent !== 'string') { | ||
throw new TypeError(`Expected \`options.indent\` to be a \`string\`, got \`${typeof options.indent}\``); | ||
} | ||
if (count === 0) { | ||
return string; | ||
} | ||
const regex = options.includeEmptyLines ? /^/gm : /^(?!\s*$)/gm; | ||
return string.replace(regex, options.indent.repeat(count)); | ||
}; | ||
class AggregateError extends Error { | ||
/** | ||
@param errors - If a string, a new `Error` is created with the string as the error message. If a non-Error object, a new `Error` is created with all properties from the object copied over. | ||
@returns An Error that is also an [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators#Iterables) for the individual errors. | ||
@example | ||
``` | ||
import AggregateError = require('aggregate-error'); | ||
const error = new AggregateError([new Error('foo'), 'bar', {message: 'baz'}]); | ||
throw error; | ||
// AggregateError: | ||
// Error: foo | ||
// at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:33) | ||
// Error: bar | ||
// at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:13) | ||
// Error: baz | ||
// at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:13) | ||
// at AggregateError (/Users/sindresorhus/dev/aggregate-error/index.js:19:3) | ||
// at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:13) | ||
// at Module._compile (module.js:556:32) | ||
// at Object.Module._extensions..js (module.js:565:10) | ||
// at Module.load (module.js:473:32) | ||
// at tryModuleLoad (module.js:432:12) | ||
// at Function.Module._load (module.js:424:3) | ||
// at Module.runMain (module.js:590:10) | ||
// at run (bootstrap_node.js:394:7) | ||
// at startup (bootstrap_node.js:149:9) | ||
for (const individualError of error) { | ||
console.log(individualError); | ||
} | ||
//=> [Error: foo] | ||
//=> [Error: bar] | ||
//=> [Error: baz] | ||
``` | ||
*/ | ||
constructor(errors) { | ||
if (!Array.isArray(errors)) { | ||
throw new TypeError(`Expected input to be an Array, got ${typeof errors}`); | ||
} | ||
const normalizedErrors = errors.map(error => { | ||
if (error instanceof Error) { | ||
return error; | ||
} | ||
if (error !== null && typeof error === 'object') { | ||
// Handle plain error objects with message property and/or possibly other metadata | ||
return Object.assign(new Error(error.message), error); | ||
} | ||
return new Error(error); | ||
}); | ||
let message = normalizedErrors | ||
.map(error => { | ||
// The `stack` property is not standardized, so we can't assume it exists | ||
return typeof error.stack === 'string' ? cleanInternalStack(cleanStack(error.stack)) : String(error); | ||
}) | ||
.join('\n'); | ||
message = '\n' + indentString(message, 4); | ||
super(message); | ||
this.name = 'AggregateError'; | ||
Object.defineProperty(this, '_errors', { value: normalizedErrors }); | ||
} | ||
*[Symbol.iterator]() { | ||
for (const error of this._errors) { | ||
yield error; | ||
} | ||
} | ||
} | ||
function getSchemaFromIntrospection(introspectionResult) { | ||
@@ -1185,0 +1360,0 @@ var _a, _b; |
179
index.esm.js
@@ -5,3 +5,2 @@ import { GraphQLObjectType, GraphQLInterfaceType, GraphQLUnionType, isSpecifiedScalarType, isScalarType, isObjectType, isInterfaceType, isUnionType, isInputObjectType, GraphQLInputObjectType, isEnumType, GraphQLEnumType, GraphQLScalarType, visit, Kind, TypeInfo, visitWithTypeInfo, extendSchema, parse, getNullableType, BREAK, buildSchema, getIntrospectionQuery, buildClientSchema } from 'graphql'; | ||
import { addResolversToSchema } from '@graphql-tools/schema'; | ||
import AggregateError from 'aggregate-error'; | ||
@@ -1176,2 +1175,180 @@ function generateProxyingResolvers(subschemaOrSubschemaConfig, transforms) { | ||
/** | ||
Escape RegExp special characters. | ||
You can also use this to escape a string that is inserted into the middle of a regex, for example, into a character class. | ||
@example | ||
``` | ||
import escapeStringRegexp = require('escape-string-regexp'); | ||
const escapedString = escapeStringRegexp('How much $ for a 🦄?'); | ||
//=> 'How much \\$ for a 🦄\\?' | ||
new RegExp(escapedString); | ||
``` | ||
*/ | ||
const escapeStringRegexp = (string) => { | ||
if (typeof string !== 'string') { | ||
throw new TypeError('Expected a string'); | ||
} | ||
// Escape characters with special meaning either inside or outside character sets. | ||
// Use a simple backslash escape when it’s always valid, and a `\xnn` escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar. | ||
return string | ||
.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&') | ||
.replace(/-/g, '\\x2d'); | ||
}; | ||
const extractPathRegex = /\s+at.*[(\s](.*)\)?/; | ||
const pathRegex = /^(?:(?:(?:node|(?:internal\/[\w/]*|.*node_modules\/(?:babel-polyfill|pirates)\/.*)?\w+)\.js:\d+:\d+)|native)/; | ||
/** | ||
Clean up error stack traces. Removes the mostly unhelpful internal Node.js entries. | ||
@param stack - The `stack` property of an `Error`. | ||
@example | ||
``` | ||
import cleanStack = require('clean-stack'); | ||
const error = new Error('Missing unicorn'); | ||
console.log(error.stack); | ||
// Error: Missing unicorn | ||
// at Object.<anonymous> (/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15) | ||
// at Module._compile (module.js:409:26) | ||
// at Object.Module._extensions..js (module.js:416:10) | ||
// at Module.load (module.js:343:32) | ||
// at Function.Module._load (module.js:300:12) | ||
// at Function.Module.runMain (module.js:441:10) | ||
// at startup (node.js:139:18) | ||
console.log(cleanStack(error.stack)); | ||
// Error: Missing unicorn | ||
// at Object.<anonymous> (/Users/sindresorhus/dev/clean-stack/unicorn.js:2:15) | ||
``` | ||
*/ | ||
const cleanStack = (stack, basePath) => { | ||
const basePathRegex = basePath && new RegExp(`(at | \\()${escapeStringRegexp(basePath)}`, 'g'); | ||
return stack.replace(/\\/g, '/') | ||
.split('\n') | ||
.filter(line => { | ||
const pathMatches = line.match(extractPathRegex); | ||
if (pathMatches === null || !pathMatches[1]) { | ||
return true; | ||
} | ||
const match = pathMatches[1]; | ||
// Electron | ||
if (match.includes('.app/Contents/Resources/electron.asar') || | ||
match.includes('.app/Contents/Resources/default_app.asar')) { | ||
return false; | ||
} | ||
return !pathRegex.test(match); | ||
}) | ||
.filter(line => line.trim() !== '') | ||
.map(line => { | ||
if (basePathRegex) { | ||
line = line.replace(basePathRegex, '$1'); | ||
} | ||
return line; | ||
}) | ||
.join('\n'); | ||
}; | ||
const cleanInternalStack = (stack) => stack.replace(/\s+at .*aggregate-error\/index.js:\d+:\d+\)?/g, ''); | ||
/** | ||
Indent each line in a string. | ||
@param string - The string to indent. | ||
@param count - How many times you want `options.indent` repeated. Default: `1`. | ||
@example | ||
``` | ||
import indentString = require('indent-string'); | ||
indentString('Unicorns\nRainbows', 4); | ||
//=> ' Unicorns\n Rainbows' | ||
indentString('Unicorns\nRainbows', 4, {indent: '♥'}); | ||
//=> '♥♥♥♥Unicorns\n♥♥♥♥Rainbows' | ||
``` | ||
*/ | ||
const indentString = (string, count = 1, options) => { | ||
options = { | ||
indent: ' ', | ||
includeEmptyLines: false, | ||
...options | ||
}; | ||
if (typeof string !== 'string') { | ||
throw new TypeError(`Expected \`input\` to be a \`string\`, got \`${typeof string}\``); | ||
} | ||
if (typeof count !== 'number') { | ||
throw new TypeError(`Expected \`count\` to be a \`number\`, got \`${typeof count}\``); | ||
} | ||
if (count < 0) { | ||
throw new RangeError(`Expected \`count\` to be at least 0, got \`${count}\``); | ||
} | ||
if (typeof options.indent !== 'string') { | ||
throw new TypeError(`Expected \`options.indent\` to be a \`string\`, got \`${typeof options.indent}\``); | ||
} | ||
if (count === 0) { | ||
return string; | ||
} | ||
const regex = options.includeEmptyLines ? /^/gm : /^(?!\s*$)/gm; | ||
return string.replace(regex, options.indent.repeat(count)); | ||
}; | ||
class AggregateError extends Error { | ||
/** | ||
@param errors - If a string, a new `Error` is created with the string as the error message. If a non-Error object, a new `Error` is created with all properties from the object copied over. | ||
@returns An Error that is also an [`Iterable`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators#Iterables) for the individual errors. | ||
@example | ||
``` | ||
import AggregateError = require('aggregate-error'); | ||
const error = new AggregateError([new Error('foo'), 'bar', {message: 'baz'}]); | ||
throw error; | ||
// AggregateError: | ||
// Error: foo | ||
// at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:33) | ||
// Error: bar | ||
// at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:13) | ||
// Error: baz | ||
// at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:13) | ||
// at AggregateError (/Users/sindresorhus/dev/aggregate-error/index.js:19:3) | ||
// at Object.<anonymous> (/Users/sindresorhus/dev/aggregate-error/example.js:3:13) | ||
// at Module._compile (module.js:556:32) | ||
// at Object.Module._extensions..js (module.js:565:10) | ||
// at Module.load (module.js:473:32) | ||
// at tryModuleLoad (module.js:432:12) | ||
// at Function.Module._load (module.js:424:3) | ||
// at Module.runMain (module.js:590:10) | ||
// at run (bootstrap_node.js:394:7) | ||
// at startup (bootstrap_node.js:149:9) | ||
for (const individualError of error) { | ||
console.log(individualError); | ||
} | ||
//=> [Error: foo] | ||
//=> [Error: bar] | ||
//=> [Error: baz] | ||
``` | ||
*/ | ||
constructor(errors) { | ||
if (!Array.isArray(errors)) { | ||
throw new TypeError(`Expected input to be an Array, got ${typeof errors}`); | ||
} | ||
const normalizedErrors = errors.map(error => { | ||
if (error instanceof Error) { | ||
return error; | ||
} | ||
if (error !== null && typeof error === 'object') { | ||
// Handle plain error objects with message property and/or possibly other metadata | ||
return Object.assign(new Error(error.message), error); | ||
} | ||
return new Error(error); | ||
}); | ||
let message = normalizedErrors | ||
.map(error => { | ||
// The `stack` property is not standardized, so we can't assume it exists | ||
return typeof error.stack === 'string' ? cleanInternalStack(cleanStack(error.stack)) : String(error); | ||
}) | ||
.join('\n'); | ||
message = '\n' + indentString(message, 4); | ||
super(message); | ||
this.name = 'AggregateError'; | ||
Object.defineProperty(this, '_errors', { value: normalizedErrors }); | ||
} | ||
*[Symbol.iterator]() { | ||
for (const error of this._errors) { | ||
yield error; | ||
} | ||
} | ||
} | ||
function getSchemaFromIntrospection(introspectionResult) { | ||
@@ -1178,0 +1355,0 @@ var _a, _b; |
{ | ||
"name": "@graphql-tools/wrap", | ||
"version": "6.0.10", | ||
"version": "6.0.11-alpha-002e171.0", | ||
"description": "A set of utils for faster development of GraphQL tools", | ||
@@ -10,5 +10,5 @@ "sideEffects": false, | ||
"dependencies": { | ||
"@graphql-tools/delegate": "6.0.10", | ||
"@graphql-tools/schema": "6.0.10", | ||
"@graphql-tools/utils": "6.0.10", | ||
"@graphql-tools/delegate": "6.0.11-alpha-002e171.0", | ||
"@graphql-tools/schema": "6.0.11-alpha-002e171.0", | ||
"@graphql-tools/utils": "6.0.11-alpha-002e171.0", | ||
"aggregate-error": "3.0.1", | ||
@@ -15,0 +15,0 @@ "tslib": "~2.0.0" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
356876
3082
2
+ Added@ardatan/aggregate-error@0.0.1(transitive)
+ Added@graphql-tools/delegate@6.0.11-alpha-002e171.0(transitive)
+ Added@graphql-tools/schema@6.0.11-alpha-002e171.0(transitive)
+ Added@graphql-tools/utils@6.0.11-alpha-002e171.0(transitive)
- Removed@graphql-tools/delegate@6.0.10(transitive)
- Removed@graphql-tools/schema@6.0.10(transitive)
- Removed@graphql-tools/utils@6.0.10(transitive)