@0no-co/graphql.web
Advanced tools
Comparing version 0.1.2 to 0.1.3
@@ -250,2 +250,5 @@ declare enum Kind { | ||
export { ASTNode, ASTReducer, ASTVisitFn, ASTVisitor, ArgumentNode, BREAK, BooleanValueNode, ConstArgumentNode, ConstDirectiveNode, ConstListValueNode, ConstObjectFieldNode, ConstObjectValueNode, ConstValueNode, DefinitionNode, DirectiveNode, DocumentNode, EnumValueNode, ExecutableDefinitionNode, FieldNode, FloatValueNode, FragmentDefinitionNode, FragmentSpreadNode, GraphQLError, InlineFragmentNode, IntValueNode, Kind, ListTypeNode, ListValueNode, Location, NameNode, NamedTypeNode, NonNullTypeNode, NullValueNode, ObjectFieldNode, ObjectValueNode, OperationDefinitionNode, OperationTypeNode, SelectionNode, SelectionSetNode, Source, StringValueNode, TypeNode, ValueNode, VariableDefinitionNode, VariableNode, blockString, parse, parseType, parseValue, print, printBlockString, printString, visit }; | ||
declare function valueFromASTUntyped(node: ValueNode, variables?: Maybe<Record<string, any>>): unknown; | ||
declare function valueFromTypeNode(node: ValueNode, type: TypeNode, variables?: Maybe<Record<string, any>>): unknown; | ||
export { ASTNode, ASTReducer, ASTVisitFn, ASTVisitor, ArgumentNode, BREAK, BooleanValueNode, ConstArgumentNode, ConstDirectiveNode, ConstListValueNode, ConstObjectFieldNode, ConstObjectValueNode, ConstValueNode, DefinitionNode, DirectiveNode, DocumentNode, EnumValueNode, ExecutableDefinitionNode, FieldNode, FloatValueNode, FragmentDefinitionNode, FragmentSpreadNode, GraphQLError, InlineFragmentNode, IntValueNode, Kind, ListTypeNode, ListValueNode, Location, NameNode, NamedTypeNode, NonNullTypeNode, NullValueNode, ObjectFieldNode, ObjectValueNode, OperationDefinitionNode, OperationTypeNode, SelectionNode, SelectionSetNode, Source, StringValueNode, TypeNode, ValueNode, VariableDefinitionNode, VariableNode, blockString, parse, parseType, parseValue, print, printBlockString, printString, valueFromASTUntyped, valueFromTypeNode, visit }; |
@@ -43,3 +43,3 @@ Object.defineProperty(exports, "__esModule", { | ||
class GraphQLError extends Error { | ||
constructor(e, r, i, n, t, o, a) { | ||
constructor(e, r, n, i, t, o, a) { | ||
super(e); | ||
@@ -54,8 +54,8 @@ this.name = "GraphQLError"; | ||
} | ||
if (n) { | ||
this.source = n; | ||
} | ||
if (i) { | ||
this.source = i; | ||
this.positions = i; | ||
} | ||
if (n) { | ||
this.positions = n; | ||
} | ||
if (o) { | ||
@@ -90,14 +90,14 @@ this.originalError = o; | ||
function advance(i) { | ||
i.lastIndex = r; | ||
if (i.test(e)) { | ||
return e.slice(r, r = i.lastIndex); | ||
function advance(n) { | ||
n.lastIndex = r; | ||
if (n.test(e)) { | ||
return e.slice(r, r = n.lastIndex); | ||
} | ||
} | ||
var i = / +(?=[^\s])/y; | ||
var n = / +(?=[^\s])/y; | ||
function blockString(e) { | ||
var r = ""; | ||
var n = 0; | ||
var i = 0; | ||
var t = 0; | ||
@@ -107,6 +107,6 @@ var o = -1; | ||
for (var s = 0; s < a.length; s++) { | ||
i.lastIndex = 0; | ||
if (i.test(a[s])) { | ||
if (s && (!n || i.lastIndex < n)) { | ||
n = i.lastIndex; | ||
n.lastIndex = 0; | ||
if (n.test(a[s])) { | ||
if (s && (!i || n.lastIndex < i)) { | ||
i = n.lastIndex; | ||
} | ||
@@ -121,3 +121,3 @@ t = t || s; | ||
} | ||
r += a[d].slice(n).replace(/\\"""/g, '"""'); | ||
r += a[d].slice(i).replace(/\\"""/g, '"""'); | ||
} | ||
@@ -127,8 +127,8 @@ return r; | ||
var n = /(?:[\s,]*|#[^\n\r]*)*/y; | ||
var i = /(?:[\s,]*|#[^\n\r]*)*/y; | ||
function ignored() { | ||
n.lastIndex = r; | ||
n.test(e); | ||
r = n.lastIndex; | ||
i.lastIndex = r; | ||
i.test(e); | ||
r = i.lastIndex; | ||
} | ||
@@ -160,20 +160,20 @@ | ||
var v = /"""(?:[\s\S]+(?="""))?"""/y; | ||
var l = /"""(?:[\s\S]+(?="""))?"""/y; | ||
var l = /"(?:[^"\r\n]+)?"/y; | ||
var v = /"(?:[^"\r\n]+)?"/y; | ||
function value(i) { | ||
var n; | ||
function value(n) { | ||
var i; | ||
var c; | ||
if (advance(o)) { | ||
n = { | ||
i = { | ||
kind: exports.Kind.NULL | ||
}; | ||
} else if (c = advance(a)) { | ||
n = { | ||
i = { | ||
kind: exports.Kind.BOOLEAN, | ||
value: "true" === c | ||
}; | ||
} else if (!i && (c = advance(s))) { | ||
n = { | ||
} else if (!n && (c = advance(s))) { | ||
i = { | ||
kind: exports.Kind.VARIABLE, | ||
@@ -186,3 +186,3 @@ name: { | ||
} else if (c = advance(p)) { | ||
n = { | ||
i = { | ||
kind: exports.Kind.FLOAT, | ||
@@ -192,3 +192,3 @@ value: c | ||
} else if (c = advance(d)) { | ||
n = { | ||
i = { | ||
kind: exports.Kind.INT, | ||
@@ -198,8 +198,8 @@ value: c | ||
} else if (c = advance(t)) { | ||
n = { | ||
i = { | ||
kind: exports.Kind.ENUM, | ||
value: c | ||
}; | ||
} else if (c = advance(v)) { | ||
n = { | ||
} else if (c = advance(l)) { | ||
i = { | ||
kind: exports.Kind.STRING, | ||
@@ -209,4 +209,4 @@ value: blockString(c.slice(3, -3)), | ||
}; | ||
} else if (c = advance(l)) { | ||
n = { | ||
} else if (c = advance(v)) { | ||
i = { | ||
kind: exports.Kind.STRING, | ||
@@ -216,4 +216,4 @@ value: u.test(c) ? JSON.parse(c) : c.slice(1, -1), | ||
}; | ||
} else if (n = function list(i) { | ||
var n; | ||
} else if (i = function list(n) { | ||
var i; | ||
if (91 === e.charCodeAt(r)) { | ||
@@ -223,4 +223,4 @@ r++; | ||
var t = []; | ||
while (n = value(i)) { | ||
t.push(n); | ||
while (i = value(n)) { | ||
t.push(i); | ||
} | ||
@@ -236,7 +236,7 @@ if (93 !== e.charCodeAt(r++)) { | ||
} | ||
}(i) || function object(i) { | ||
}(n) || function object(n) { | ||
if (123 === e.charCodeAt(r)) { | ||
r++; | ||
ignored(); | ||
var n = []; | ||
var i = []; | ||
var t; | ||
@@ -249,7 +249,7 @@ while (t = name()) { | ||
ignored(); | ||
var o = value(i); | ||
var o = value(n); | ||
if (!o) { | ||
throw error(exports.Kind.OBJECT_FIELD); | ||
} | ||
n.push({ | ||
i.push({ | ||
kind: exports.Kind.OBJECT_FIELD, | ||
@@ -266,14 +266,14 @@ name: t, | ||
kind: exports.Kind.OBJECT, | ||
fields: n | ||
fields: i | ||
}; | ||
} | ||
}(i)) { | ||
return n; | ||
}(n)) { | ||
return i; | ||
} | ||
ignored(); | ||
return n; | ||
return i; | ||
} | ||
function arguments_(i) { | ||
var n = []; | ||
function arguments_(n) { | ||
var i = []; | ||
ignored(); | ||
@@ -290,7 +290,7 @@ if (40 === e.charCodeAt(r)) { | ||
ignored(); | ||
var o = value(i); | ||
var o = value(n); | ||
if (!o) { | ||
throw error(exports.Kind.ARGUMENT); | ||
} | ||
n.push({ | ||
i.push({ | ||
kind: exports.Kind.ARGUMENT, | ||
@@ -301,3 +301,3 @@ name: t, | ||
} | ||
if (!n.length || 41 !== e.charCodeAt(r++)) { | ||
if (!i.length || 41 !== e.charCodeAt(r++)) { | ||
throw error(exports.Kind.ARGUMENT); | ||
@@ -307,7 +307,7 @@ } | ||
} | ||
return n; | ||
return i; | ||
} | ||
function directives(i) { | ||
var n = []; | ||
function directives(n) { | ||
var i = []; | ||
ignored(); | ||
@@ -321,9 +321,9 @@ while (64 === e.charCodeAt(r)) { | ||
ignored(); | ||
n.push({ | ||
i.push({ | ||
kind: exports.Kind.DIRECTIVE, | ||
name: t, | ||
arguments: arguments_(i) | ||
arguments: arguments_(n) | ||
}); | ||
} | ||
return n; | ||
return i; | ||
} | ||
@@ -333,11 +333,11 @@ | ||
ignored(); | ||
var i = name(); | ||
if (i) { | ||
var n = name(); | ||
if (n) { | ||
ignored(); | ||
var n; | ||
var i; | ||
if (58 === e.charCodeAt(r)) { | ||
r++; | ||
ignored(); | ||
n = i; | ||
if (!(i = name())) { | ||
i = n; | ||
if (!(n = name())) { | ||
throw error(exports.Kind.FIELD); | ||
@@ -349,4 +349,4 @@ } | ||
kind: exports.Kind.FIELD, | ||
alias: n, | ||
name: i, | ||
alias: i, | ||
name: n, | ||
arguments: arguments_(!1), | ||
@@ -360,3 +360,3 @@ directives: directives(!1), | ||
function type() { | ||
var i; | ||
var n; | ||
ignored(); | ||
@@ -366,14 +366,14 @@ if (91 === e.charCodeAt(r)) { | ||
ignored(); | ||
var n = type(); | ||
if (!n || 93 !== e.charCodeAt(r++)) { | ||
var i = type(); | ||
if (!i || 93 !== e.charCodeAt(r++)) { | ||
throw error(exports.Kind.LIST_TYPE); | ||
} | ||
i = { | ||
n = { | ||
kind: exports.Kind.LIST_TYPE, | ||
type: n | ||
type: i | ||
}; | ||
} else if (i = name()) { | ||
i = { | ||
} else if (n = name()) { | ||
n = { | ||
kind: exports.Kind.NAMED_TYPE, | ||
name: i | ||
name: n | ||
}; | ||
@@ -389,6 +389,6 @@ } else { | ||
kind: exports.Kind.NON_NULL_TYPE, | ||
type: i | ||
type: n | ||
}; | ||
} else { | ||
return i; | ||
return n; | ||
} | ||
@@ -421,7 +421,7 @@ } | ||
var e = r; | ||
var i; | ||
if ((i = name()) && "on" !== i.value) { | ||
var n; | ||
if ((n = name()) && "on" !== n.value) { | ||
return { | ||
kind: exports.Kind.FRAGMENT_SPREAD, | ||
name: i, | ||
name: n, | ||
directives: directives(!1) | ||
@@ -431,3 +431,3 @@ }; | ||
r = e; | ||
var n = typeCondition(); | ||
var i = typeCondition(); | ||
var t = directives(!1); | ||
@@ -440,3 +440,3 @@ var o = selectionSet(); | ||
kind: exports.Kind.INLINE_FRAGMENT, | ||
typeCondition: n, | ||
typeCondition: i, | ||
directives: t, | ||
@@ -450,3 +450,3 @@ selectionSet: o | ||
function selectionSet() { | ||
var i; | ||
var n; | ||
ignored(); | ||
@@ -456,7 +456,7 @@ if (123 === e.charCodeAt(r)) { | ||
ignored(); | ||
var n = []; | ||
while (i = fragmentSpread() || field()) { | ||
n.push(i); | ||
var i = []; | ||
while (n = fragmentSpread() || field()) { | ||
i.push(n); | ||
} | ||
if (!n.length || 125 !== e.charCodeAt(r++)) { | ||
if (!i.length || 125 !== e.charCodeAt(r++)) { | ||
throw error(exports.Kind.SELECTION_SET); | ||
@@ -467,3 +467,3 @@ } | ||
kind: exports.Kind.SELECTION_SET, | ||
selections: n | ||
selections: i | ||
}; | ||
@@ -487,5 +487,5 @@ } | ||
} | ||
var i = directives(!1); | ||
var n = selectionSet(); | ||
if (!n) { | ||
var n = directives(!1); | ||
var i = selectionSet(); | ||
if (!i) { | ||
throw error(exports.Kind.FRAGMENT_DEFINITION); | ||
@@ -497,4 +497,4 @@ } | ||
typeCondition: r, | ||
directives: i, | ||
selectionSet: n | ||
directives: n, | ||
selectionSet: i | ||
}; | ||
@@ -507,12 +507,12 @@ } | ||
function operationDefinition() { | ||
var n; | ||
var i; | ||
var n; | ||
var t = []; | ||
var o = []; | ||
if (i = advance(N)) { | ||
if (n = advance(N)) { | ||
ignored(); | ||
n = name(); | ||
i = name(); | ||
t = function variableDefinitions() { | ||
var i; | ||
var n = []; | ||
var n; | ||
var i = []; | ||
ignored(); | ||
@@ -522,3 +522,3 @@ if (40 === e.charCodeAt(r)) { | ||
ignored(); | ||
while (i = advance(s)) { | ||
while (n = advance(s)) { | ||
ignored(); | ||
@@ -541,3 +541,3 @@ if (58 !== e.charCodeAt(r++)) { | ||
ignored(); | ||
n.push({ | ||
i.push({ | ||
kind: exports.Kind.VARIABLE_DEFINITION, | ||
@@ -548,3 +548,3 @@ variable: { | ||
kind: exports.Kind.NAME, | ||
value: i.slice(1) | ||
value: n.slice(1) | ||
} | ||
@@ -562,3 +562,3 @@ }, | ||
} | ||
return n; | ||
return i; | ||
}(); | ||
@@ -571,4 +571,4 @@ o = directives(!1); | ||
kind: exports.Kind.OPERATION_DEFINITION, | ||
operation: i || "query", | ||
name: n, | ||
operation: n || "query", | ||
name: i, | ||
variableDefinitions: t, | ||
@@ -595,2 +595,38 @@ directives: o, | ||
function valueFromASTUntyped(e, r) { | ||
switch (e.kind) { | ||
case exports.Kind.NULL: | ||
return null; | ||
case exports.Kind.INT: | ||
return parseInt(e.value, 10); | ||
case exports.Kind.FLOAT: | ||
return parseFloat(e.value); | ||
case exports.Kind.STRING: | ||
case exports.Kind.ENUM: | ||
case exports.Kind.BOOLEAN: | ||
return e.value; | ||
case exports.Kind.LIST: | ||
var n = []; | ||
for (var i = 0, t = e.values; i < t.length; i += 1) { | ||
n.push(valueFromASTUntyped(t[i], r)); | ||
} | ||
return n; | ||
case exports.Kind.OBJECT: | ||
var o = Object.create(null); | ||
for (var a = 0, s = e.fields; a < s.length; a += 1) { | ||
var d = s[a]; | ||
o[d.name.value] = valueFromASTUntyped(d.value, r); | ||
} | ||
return o; | ||
case exports.Kind.VARIABLE: | ||
return r && r[e.name.value]; | ||
} | ||
} | ||
exports.BREAK = I; | ||
@@ -602,11 +638,11 @@ | ||
exports.parse = function parse(i) { | ||
e = i; | ||
exports.parse = function parse(n) { | ||
e = n; | ||
r = 0; | ||
return function document() { | ||
var i; | ||
var n; | ||
ignored(); | ||
var n = []; | ||
while (i = fragmentDefinition() || operationDefinition()) { | ||
n.push(i); | ||
var i = []; | ||
while (n = fragmentDefinition() || operationDefinition()) { | ||
i.push(n); | ||
} | ||
@@ -618,3 +654,3 @@ if (r !== e.length) { | ||
kind: exports.Kind.DOCUMENT, | ||
definitions: n | ||
definitions: i | ||
}; | ||
@@ -624,4 +660,4 @@ }(); | ||
exports.parseType = function parseType(i) { | ||
e = i; | ||
exports.parseType = function parseType(n) { | ||
e = n; | ||
r = 0; | ||
@@ -631,4 +667,4 @@ return type(); | ||
exports.parseValue = function parseValue(i) { | ||
e = i; | ||
exports.parseValue = function parseValue(n) { | ||
e = n; | ||
r = 0; | ||
@@ -674,5 +710,5 @@ ignored(); | ||
if (hasItems(e.arguments)) { | ||
var i = e.arguments.map(print); | ||
var n = r + "(" + i.join(", ") + ")"; | ||
r = n.length > T ? r + "(\n " + i.join("\n").replace(/\n/g, "\n ") + "\n)" : n; | ||
var n = e.arguments.map(print); | ||
var i = r + "(" + n.join(", ") + ")"; | ||
r = i.length > T ? r + "(\n " + n.join("\n").replace(/\n/g, "\n ") + "\n)" : i; | ||
} | ||
@@ -767,5 +803,41 @@ if (hasItems(e.directives)) { | ||
exports.valueFromASTUntyped = valueFromASTUntyped; | ||
exports.valueFromTypeNode = function valueFromTypeNode(e, r, n) { | ||
if (e.kind === exports.Kind.VARIABLE) { | ||
return n ? valueFromTypeNode(n[e.name.value], r, n) : void 0; | ||
} else if (r.kind === exports.Kind.NON_NULL_TYPE) { | ||
return e.kind !== exports.Kind.NULL ? valueFromTypeNode(e, r, n) : void 0; | ||
} else if (e.kind === exports.Kind.NULL) { | ||
return null; | ||
} else if (r.kind === exports.Kind.LIST_TYPE) { | ||
if (e.kind === exports.Kind.LIST) { | ||
var i = []; | ||
for (var t = 0, o = e.values; t < o.length; t += 1) { | ||
var a = valueFromTypeNode(o[t], r.type, n); | ||
if (void 0 === a) { | ||
return; | ||
} else { | ||
i.push(a); | ||
} | ||
} | ||
return i; | ||
} | ||
} else if (r.kind === exports.Kind.NAMED_TYPE) { | ||
switch (r.name.value) { | ||
case "Int": | ||
case "Float": | ||
case "String": | ||
case "Bool": | ||
return r.name.value + "Value" === e.kind ? valueFromASTUntyped(e, n) : void 0; | ||
default: | ||
return valueFromASTUntyped(e, n); | ||
} | ||
} | ||
}; | ||
exports.visit = function visit(e, r) { | ||
var n = []; | ||
var i = []; | ||
var n = []; | ||
try { | ||
@@ -775,3 +847,3 @@ var t = function traverse(e, t, o) { | ||
var s = r[e.kind] && r[e.kind].enter || r[e.kind]; | ||
var d = s && s.call(r, e, t, o, n, i); | ||
var d = s && s.call(r, e, t, o, i, n); | ||
if (!1 === d) { | ||
@@ -788,3 +860,3 @@ return e; | ||
if (o) { | ||
i.push(o); | ||
n.push(o); | ||
} | ||
@@ -795,20 +867,20 @@ var p; | ||
}; | ||
for (var v in e) { | ||
n.push(v); | ||
var l = e[v]; | ||
if (Array.isArray(l)) { | ||
for (var l in e) { | ||
i.push(l); | ||
var v = e[l]; | ||
if (Array.isArray(v)) { | ||
var c = []; | ||
for (var f = 0; f < l.length; f++) { | ||
if (null != l[f] && "string" == typeof l[f].kind) { | ||
i.push(e); | ||
n.push(f); | ||
p = traverse(l[f], f, l); | ||
for (var f = 0; f < v.length; f++) { | ||
if (null != v[f] && "string" == typeof v[f].kind) { | ||
n.push(e); | ||
i.push(f); | ||
p = traverse(v[f], f, v); | ||
i.pop(); | ||
n.pop(); | ||
i.pop(); | ||
if (void 0 === p) { | ||
c.push(l[f]); | ||
c.push(v[f]); | ||
} else if (null === p) { | ||
a = !0; | ||
} else { | ||
a = a || p !== l[f]; | ||
a = a || p !== v[f]; | ||
c.push(p); | ||
@@ -818,19 +890,19 @@ } | ||
} | ||
l = c; | ||
} else if (null != l && "string" == typeof l.kind) { | ||
if (void 0 !== (p = traverse(l, v, e))) { | ||
a = a || l !== p; | ||
l = p; | ||
v = c; | ||
} else if (null != v && "string" == typeof v.kind) { | ||
if (void 0 !== (p = traverse(v, l, e))) { | ||
a = a || v !== p; | ||
v = p; | ||
} | ||
} | ||
n.pop(); | ||
i.pop(); | ||
if (a) { | ||
u[v] = l; | ||
u[l] = v; | ||
} | ||
} | ||
if (o) { | ||
i.pop(); | ||
n.pop(); | ||
} | ||
var E = r[e.kind] && r[e.kind].leave; | ||
var N = E && E.call(r, e, t, o, n, i); | ||
var N = E && E.call(r, e, t, o, i, n); | ||
if (N === I) { | ||
@@ -837,0 +909,0 @@ throw I; |
{ | ||
"name": "@0no-co/graphql.web", | ||
"description": "A spec-compliant client-side GraphQL implementation", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"author": "0no.co <hi@0no.co>", | ||
@@ -6,0 +6,0 @@ "source": "./src/index.ts", |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
149219
8
1829
0
61