graphql-jit 0.8.4 → 0.8.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/dist/{ast.d.ts → cjs/ast.d.ts} +1 -1
- package/dist/cjs/ast.js.map +1 -0
- package/dist/{compat.js → cjs/compat.js} +5 -1
- package/dist/cjs/compat.js.map +1 -0
- package/dist/cjs/error.js.map +1 -0
- package/dist/{execution.js → cjs/execution.js} +1 -1
- package/dist/cjs/execution.js.map +1 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/inspect.js.map +1 -0
- package/dist/cjs/json.js.map +1 -0
- package/dist/{memoize.d.ts → cjs/memoize.d.ts} +1 -1
- package/dist/cjs/memoize.js.map +1 -0
- package/dist/{non-null.d.ts → cjs/non-null.d.ts} +1 -1
- package/dist/{non-null.js → cjs/non-null.js} +4 -0
- package/dist/cjs/non-null.js.map +1 -0
- package/dist/{resolve-info.d.ts → cjs/resolve-info.d.ts} +1 -1
- package/dist/cjs/resolve-info.js.map +1 -0
- package/dist/cjs/types.d.ts +1 -0
- package/dist/cjs/types.js.map +1 -0
- package/dist/{variables.d.ts → cjs/variables.d.ts} +1 -1
- package/dist/cjs/variables.js.map +1 -0
- package/dist/esm/ast.d.ts +89 -0
- package/dist/esm/ast.js +704 -0
- package/dist/esm/ast.js.map +1 -0
- package/dist/esm/compat.d.ts +43 -0
- package/dist/esm/compat.js +101 -0
- package/dist/esm/compat.js.map +1 -0
- package/dist/esm/error.d.ts +7 -0
- package/dist/esm/error.js +59 -0
- package/dist/esm/error.js.map +1 -0
- package/dist/esm/execution.d.ts +148 -0
- package/dist/esm/execution.js +1200 -0
- package/dist/esm/execution.js.map +1 -0
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/inspect.d.ts +5 -0
- package/dist/esm/inspect.js +110 -0
- package/dist/esm/inspect.js.map +1 -0
- package/dist/esm/json.d.ts +9 -0
- package/dist/esm/json.js +145 -0
- package/dist/esm/json.js.map +1 -0
- package/dist/esm/memoize.d.ts +5 -0
- package/dist/esm/memoize.js +29 -0
- package/dist/esm/memoize.js.map +1 -0
- package/dist/esm/non-null.d.ts +9 -0
- package/dist/esm/non-null.js +207 -0
- package/dist/esm/non-null.js.map +1 -0
- package/dist/esm/resolve-info.d.ts +40 -0
- package/dist/esm/resolve-info.js +233 -0
- package/dist/esm/resolve-info.js.map +1 -0
- package/dist/esm/types.d.ts +1 -0
- package/dist/esm/types.js +3 -0
- package/dist/esm/types.js.map +1 -0
- package/dist/esm/variables.d.ts +15 -0
- package/dist/esm/variables.js +348 -0
- package/dist/esm/variables.js.map +1 -0
- package/package.json +61 -37
- package/dist/ast.js.map +0 -1
- package/dist/compat.js.map +0 -1
- package/dist/error.js.map +0 -1
- package/dist/execution.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/inspect.js.map +0 -1
- package/dist/json.js.map +0 -1
- package/dist/memoize.js.map +0 -1
- package/dist/non-null.js.map +0 -1
- package/dist/resolve-info.js.map +0 -1
- package/dist/types.d.ts +0 -1
- package/dist/types.js.map +0 -1
- package/dist/variables.js.map +0 -1
- /package/dist/{ast.js → cjs/ast.js} +0 -0
- /package/dist/{compat.d.ts → cjs/compat.d.ts} +0 -0
- /package/dist/{error.d.ts → cjs/error.d.ts} +0 -0
- /package/dist/{error.js → cjs/error.js} +0 -0
- /package/dist/{execution.d.ts → cjs/execution.d.ts} +0 -0
- /package/dist/{index.d.ts → cjs/index.d.ts} +0 -0
- /package/dist/{index.js → cjs/index.js} +0 -0
- /package/dist/{inspect.d.ts → cjs/inspect.d.ts} +0 -0
- /package/dist/{inspect.js → cjs/inspect.js} +0 -0
- /package/dist/{json.d.ts → cjs/json.d.ts} +0 -0
- /package/dist/{json.js → cjs/json.js} +0 -0
- /package/dist/{memoize.js → cjs/memoize.js} +0 -0
- /package/dist/{resolve-info.js → cjs/resolve-info.js} +0 -0
- /package/dist/{types.js → cjs/types.js} +0 -0
- /package/dist/{variables.js → cjs/variables.js} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"non-null.js","sourceRoot":"","sources":["../../src/non-null.ts"],"names":[],"mappings":";;;;;;AAAA,qCAQiB;AACjB,uCAA8C;AAC9C,gEAAiC;AACjC,+BAAyE;AACzE,qCAAgD;AAUhD;;;;GAIG;AACH,SAAgB,iBAAiB,CAC/B,kBAAsC;IAEtC,OAAO,QAAQ,CAAC,mBAAmB,CAAC,kBAAkB,CAAC,CAAC,CAAC;AAC3D,CAAC;AAJD,8CAIC;AAED;;;;;;;;GAQG;AACH,SAAS,QAAQ,CAAC,QAAuB;IACvC,OAAO,CAAC,IAAS,EAAE,MAAsB,EAAmB,EAAE;QAC5D,MAAM,WAAW,GAAG,EAAE,CAAC;QACvB,MAAM,eAAe,GAAG,IAAI,GAAG,EAAU,CAAC;QAC1C,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE;YAC1B,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE;gBACf,8CAA8C;gBAC9C,MAAM,IAAI,KAAK,CAAC,qCAAqC,CAAC,CAAC;aACxD;YACD,IAAI,eAAe,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE;gBAC7C,sDAAsD;gBACtD,0FAA0F;gBAC1F,SAAS;aACV;YACD,MAAM,SAAS,GAAG,oBAAoB,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,CAAC,CAAC;YAC7D,yCAAyC;YACzC,6EAA6E;YAC7E,EAAE;YACF,kFAAkF;YAClF,wCAAwC;YACxC,IAAI,SAAS,CAAC,MAAM,KAAK,CAAC,EAAE;gBAC1B,IAAI,GAAG,IAAI,CAAC;gBACZ,WAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;gBACxB,MAAM;aACP;YACD,YAAY,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;YAC9B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,UAAU,EAAE,IAAI;gBAChB,QAAQ,EAAE,EAAE,CAAC,gBAAgB,CAAC,EAAE,KAAK,EAAE;aACxC,CAAC;SACH;QAED,OAAO;YACL,UAAU,EAAE,IAAI;YAChB,QAAQ,EAAE,EAAE;SACb,CAAC;KACH;IACD,IAAI,IAAA,qBAAc,EAAC,IAAI,CAAC,EAAE;QACxB,OAAO,kBAAkB,CAAC,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,CAAC,MAAM,CAC5D,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE;YACT,MAAM,QAAQ,GAAG,aAAa,CAAC,kBAAkB,EAAE,UAAU,EAAE,CAAC,CAAC,CAAC;YAClE,IAAI,QAAQ,IAAI,IAAI,EAAE;gBACpB,oEAAoE;gBACpE,wEAAwE;gBACxE,GAAG,CAAC,QAAQ,GAAG,IAAA,sBAAK,EAAC,GAAG,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAC;aACvD;YACD,OAAO,GAAG,CAAC;QACb,CAAC,EACD;YACE,UAAU,EAAE,IAAI;YAChB,QAAQ,EAAE,EAAE;SACb,CACF,CAAC;KACH;IAED,0DAA0D;IAC1D,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { FieldNode, GraphQLObjectType, GraphQLOutputType, GraphQLResolveInfo } from "graphql";
|
|
2
|
+
export type GraphQLJitResolveInfo<Enrichments> = GraphQLResolveInfo & Enrichments;
|
|
3
|
+
export interface ResolveInfoEnricherInput {
|
|
4
|
+
schema: GraphQLResolveInfo["schema"];
|
|
5
|
+
fragments: GraphQLResolveInfo["fragments"];
|
|
6
|
+
operation: GraphQLResolveInfo["operation"];
|
|
7
|
+
parentType: GraphQLObjectType;
|
|
8
|
+
returnType: GraphQLOutputType;
|
|
9
|
+
fieldName: string;
|
|
10
|
+
fieldNodes: FieldNode[];
|
|
11
|
+
}
|
|
12
|
+
export interface FieldExpansion {
|
|
13
|
+
[returnType: string]: TypeExpansion;
|
|
14
|
+
}
|
|
15
|
+
declare const LeafFieldSymbol: unique symbol;
|
|
16
|
+
export interface LeafField {
|
|
17
|
+
[LeafFieldSymbol]: true;
|
|
18
|
+
}
|
|
19
|
+
export interface TypeExpansion {
|
|
20
|
+
[fieldName: string]: FieldExpansion | LeafField;
|
|
21
|
+
}
|
|
22
|
+
export declare function isLeafField(obj: LeafField | FieldExpansion): obj is LeafField;
|
|
23
|
+
/**
|
|
24
|
+
* Compute the GraphQLJitResolveInfo's `fieldExpansion` and return a function
|
|
25
|
+
* that returns the computed resolveInfo. This thunk is registered in
|
|
26
|
+
* context.dependencies for the field's resolveInfoName
|
|
27
|
+
*/
|
|
28
|
+
export declare function createResolveInfoThunk<T>({ schema, fragments, operation, parentType, fieldName, fieldType, fieldNodes }: {
|
|
29
|
+
schema: GraphQLResolveInfo["schema"];
|
|
30
|
+
fragments: GraphQLResolveInfo["fragments"];
|
|
31
|
+
operation: GraphQLResolveInfo["operation"];
|
|
32
|
+
parentType: GraphQLObjectType;
|
|
33
|
+
fieldType: GraphQLOutputType;
|
|
34
|
+
fieldName: string;
|
|
35
|
+
fieldNodes: FieldNode[];
|
|
36
|
+
}, enricher?: (inp: ResolveInfoEnricherInput) => T): any;
|
|
37
|
+
export declare function fieldExpansionEnricher(input: ResolveInfoEnricherInput): {
|
|
38
|
+
fieldExpansion: FieldExpansion;
|
|
39
|
+
};
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.fieldExpansionEnricher = exports.createResolveInfoThunk = exports.isLeafField = void 0;
|
|
7
|
+
const generate_function_1 = __importDefault(require("generate-function"));
|
|
8
|
+
const graphql_1 = require("graphql");
|
|
9
|
+
const lodash_memoize_1 = __importDefault(require("lodash.memoize"));
|
|
10
|
+
const lodash_mergewith_1 = __importDefault(require("lodash.mergewith"));
|
|
11
|
+
const memoize_1 = require("./memoize");
|
|
12
|
+
const LeafFieldSymbol = Symbol("LeafFieldSymbol");
|
|
13
|
+
function createLeafField(props) {
|
|
14
|
+
return {
|
|
15
|
+
[LeafFieldSymbol]: true,
|
|
16
|
+
...props
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function isLeafField(obj) {
|
|
20
|
+
return (obj != null && Object.prototype.hasOwnProperty.call(obj, LeafFieldSymbol));
|
|
21
|
+
}
|
|
22
|
+
exports.isLeafField = isLeafField;
|
|
23
|
+
/**
|
|
24
|
+
* Compute the GraphQLJitResolveInfo's `fieldExpansion` and return a function
|
|
25
|
+
* that returns the computed resolveInfo. This thunk is registered in
|
|
26
|
+
* context.dependencies for the field's resolveInfoName
|
|
27
|
+
*/
|
|
28
|
+
function createResolveInfoThunk({ schema, fragments, operation, parentType, fieldName, fieldType, fieldNodes }, enricher) {
|
|
29
|
+
let enrichedInfo = {};
|
|
30
|
+
if (typeof enricher === "function") {
|
|
31
|
+
enrichedInfo =
|
|
32
|
+
enricher({
|
|
33
|
+
fieldName,
|
|
34
|
+
fieldNodes,
|
|
35
|
+
returnType: fieldType,
|
|
36
|
+
parentType,
|
|
37
|
+
schema,
|
|
38
|
+
fragments,
|
|
39
|
+
operation
|
|
40
|
+
}) || {};
|
|
41
|
+
if (typeof enrichedInfo !== "object" || Array.isArray(enrichedInfo)) {
|
|
42
|
+
enrichedInfo = {};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
const gen = (0, generate_function_1.default)();
|
|
46
|
+
gen(`return function getGraphQLResolveInfo(rootValue, variableValues, path) {
|
|
47
|
+
return {
|
|
48
|
+
fieldName,
|
|
49
|
+
fieldNodes,
|
|
50
|
+
returnType: fieldType,
|
|
51
|
+
parentType,
|
|
52
|
+
path,
|
|
53
|
+
schema,
|
|
54
|
+
fragments,
|
|
55
|
+
rootValue,
|
|
56
|
+
operation,
|
|
57
|
+
variableValues,`);
|
|
58
|
+
Object.keys(enrichedInfo).forEach((key) => {
|
|
59
|
+
gen(`${key}: enrichedInfo["${key}"],\n`);
|
|
60
|
+
});
|
|
61
|
+
gen(`};};`);
|
|
62
|
+
// eslint-disable-next-line
|
|
63
|
+
return new Function("fieldName", "fieldNodes", "fieldType", "parentType", "schema", "fragments", "operation", "enrichedInfo", gen.toString()).call(null, fieldName, fieldNodes, fieldType, parentType, schema, fragments, operation, enrichedInfo);
|
|
64
|
+
}
|
|
65
|
+
exports.createResolveInfoThunk = createResolveInfoThunk;
|
|
66
|
+
function fieldExpansionEnricher(input) {
|
|
67
|
+
const { schema, fragments, returnType, fieldNodes } = input;
|
|
68
|
+
const fieldExpansion = {};
|
|
69
|
+
for (const fieldNode of fieldNodes) {
|
|
70
|
+
deepMerge(fieldExpansion, memoizedExpandFieldNode(schema, fragments, fieldNode, returnType));
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
fieldExpansion
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
exports.fieldExpansionEnricher = fieldExpansionEnricher;
|
|
77
|
+
const MEMOIZATION = true;
|
|
78
|
+
const memoizedGetReturnType = MEMOIZATION
|
|
79
|
+
? (0, memoize_1.memoize2)(getReturnType)
|
|
80
|
+
: getReturnType;
|
|
81
|
+
const memoizedHasField = MEMOIZATION ? (0, memoize_1.memoize2)(hasField) : hasField;
|
|
82
|
+
const memoizedResolveEndType = MEMOIZATION
|
|
83
|
+
? (0, lodash_memoize_1.default)(resolveEndType)
|
|
84
|
+
: resolveEndType;
|
|
85
|
+
const memoizedGetPossibleTypes = MEMOIZATION
|
|
86
|
+
? (0, memoize_1.memoize2)(getPossibleTypes)
|
|
87
|
+
: getPossibleTypes;
|
|
88
|
+
const memoizedExpandFieldNodeType = MEMOIZATION
|
|
89
|
+
? (0, memoize_1.memoize4)(expandFieldNodeType)
|
|
90
|
+
: expandFieldNodeType;
|
|
91
|
+
const memoizedExpandFieldNode = MEMOIZATION
|
|
92
|
+
? (0, memoize_1.memoize4)(expandFieldNode)
|
|
93
|
+
: expandFieldNode;
|
|
94
|
+
function expandFieldNode(schema, fragments, node, fieldType) {
|
|
95
|
+
if (node.selectionSet == null) {
|
|
96
|
+
return createLeafField({});
|
|
97
|
+
}
|
|
98
|
+
// there is a selectionSet which makes the fieldType a CompositeType
|
|
99
|
+
const typ = memoizedResolveEndType(fieldType);
|
|
100
|
+
const possibleTypes = memoizedGetPossibleTypes(schema, typ);
|
|
101
|
+
const fieldExpansion = {};
|
|
102
|
+
for (const possibleType of possibleTypes) {
|
|
103
|
+
if (!(0, graphql_1.isUnionType)(possibleType)) {
|
|
104
|
+
fieldExpansion[possibleType.name] = memoizedExpandFieldNodeType(schema, fragments, possibleType, node.selectionSet);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return fieldExpansion;
|
|
108
|
+
}
|
|
109
|
+
function expandFieldNodeType(schema, fragments, parentType, selectionSet) {
|
|
110
|
+
const typeExpansion = {};
|
|
111
|
+
for (const selection of selectionSet.selections) {
|
|
112
|
+
if (selection.kind === graphql_1.Kind.FIELD) {
|
|
113
|
+
if (!(0, graphql_1.isUnionType)(parentType) &&
|
|
114
|
+
memoizedHasField(parentType, selection.name.value)) {
|
|
115
|
+
typeExpansion[selection.name.value] = memoizedExpandFieldNode(schema, fragments, selection, memoizedGetReturnType(parentType, selection.name.value));
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
else {
|
|
119
|
+
const selectionSet = selection.kind === graphql_1.Kind.INLINE_FRAGMENT
|
|
120
|
+
? selection.selectionSet
|
|
121
|
+
: fragments[selection.name.value].selectionSet;
|
|
122
|
+
const nextType = selection.kind === graphql_1.Kind.INLINE_FRAGMENT
|
|
123
|
+
? selection.typeCondition
|
|
124
|
+
? schema.getType(selection.typeCondition.name.value)
|
|
125
|
+
: parentType
|
|
126
|
+
: schema.getType(fragments[selection.name.value].typeCondition.name.value);
|
|
127
|
+
/**
|
|
128
|
+
* nextType (comes from query) is the type extracted from the fragment
|
|
129
|
+
* parentType (comes from schema) is the possibleType for which we are filling fields
|
|
130
|
+
*
|
|
131
|
+
* if the type from query (nextType) is the same as the type we are filling (parentType)
|
|
132
|
+
* or
|
|
133
|
+
* if the type from query (nextType) is an abstract type - this case is when we jump
|
|
134
|
+
* to a super type or sub type. Here we maintain the context (parentType) for which
|
|
135
|
+
* we are filling the fields. The super type / sub type will be filled in its own
|
|
136
|
+
* pass.
|
|
137
|
+
*/
|
|
138
|
+
if (nextType === parentType || (0, graphql_1.isAbstractType)(nextType)) {
|
|
139
|
+
deepMerge(typeExpansion, memoizedExpandFieldNodeType(schema, fragments, parentType, selectionSet));
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return typeExpansion;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* Returns a list of Possible types that one can get to from the
|
|
147
|
+
* resolvedType. As an analogy, these are the same types that one
|
|
148
|
+
* can use in a fragment's typeCondition.
|
|
149
|
+
*
|
|
150
|
+
* Note: This is different from schema.getPossibleTypes() that this
|
|
151
|
+
* returns all possible types and not just the ones from the type definition.
|
|
152
|
+
*
|
|
153
|
+
* Example:
|
|
154
|
+
* interface Node {
|
|
155
|
+
* id: ID!
|
|
156
|
+
* }
|
|
157
|
+
* type User implements Node {
|
|
158
|
+
* id: ID!
|
|
159
|
+
* name: String
|
|
160
|
+
* }
|
|
161
|
+
* type Article implements Node {
|
|
162
|
+
* id: ID!
|
|
163
|
+
* title: String
|
|
164
|
+
* }
|
|
165
|
+
* union Card = User | Article
|
|
166
|
+
*
|
|
167
|
+
* - schema.getPossibleTypes(Card) would give [User, Article]
|
|
168
|
+
* - This function getPossibleTypes(schema, Card) would give [User, Article, Node]
|
|
169
|
+
*
|
|
170
|
+
*/
|
|
171
|
+
function getPossibleTypes(schema, compositeType) {
|
|
172
|
+
if ((0, graphql_1.isObjectType)(compositeType)) {
|
|
173
|
+
return [compositeType];
|
|
174
|
+
}
|
|
175
|
+
const possibleTypes = [];
|
|
176
|
+
const types = schema.getTypeMap();
|
|
177
|
+
for (const typeName in types) {
|
|
178
|
+
if (Object.prototype.hasOwnProperty.call(types, typeName)) {
|
|
179
|
+
const typ = types[typeName];
|
|
180
|
+
if ((0, graphql_1.isCompositeType)(typ) && (0, graphql_1.doTypesOverlap)(schema, typ, compositeType)) {
|
|
181
|
+
possibleTypes.push(typ);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return possibleTypes;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Given an (Object|Interface)Type, and a fieldName, find the
|
|
189
|
+
* appropriate `end` return type for the field in the Composite Type.
|
|
190
|
+
*
|
|
191
|
+
* Note: The `end` return type is the type by unwrapping non-null types
|
|
192
|
+
* and list types. Check `resolveEndType`
|
|
193
|
+
*/
|
|
194
|
+
function getReturnType(parentType, fieldName) {
|
|
195
|
+
const fields = parentType.getFields();
|
|
196
|
+
if (!Object.prototype.hasOwnProperty.call(fields, fieldName)) {
|
|
197
|
+
throw new graphql_1.GraphQLError(`Field "${fieldName}" does not exist in "${parentType.name}"`);
|
|
198
|
+
}
|
|
199
|
+
const outputType = fields[fieldName].type;
|
|
200
|
+
return memoizedResolveEndType(outputType);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Resolve to the end type of the Output type unwrapping non-null types and lists
|
|
204
|
+
*/
|
|
205
|
+
function resolveEndType(typ) {
|
|
206
|
+
if ((0, graphql_1.isListType)(typ) || (0, graphql_1.isNonNullType)(typ)) {
|
|
207
|
+
return memoizedResolveEndType(typ.ofType);
|
|
208
|
+
}
|
|
209
|
+
return typ;
|
|
210
|
+
}
|
|
211
|
+
function hasField(typ, fieldName) {
|
|
212
|
+
return Object.prototype.hasOwnProperty.call(typ.getFields(), fieldName);
|
|
213
|
+
}
|
|
214
|
+
// This is because lodash does not support merging keys
|
|
215
|
+
// which are symbols. We require them for leaf fields
|
|
216
|
+
function deepMerge(obj, src) {
|
|
217
|
+
(0, lodash_mergewith_1.default)(obj, src, (objValue, srcValue) => {
|
|
218
|
+
if (isLeafField(objValue)) {
|
|
219
|
+
if (isLeafField(srcValue)) {
|
|
220
|
+
return {
|
|
221
|
+
...objValue,
|
|
222
|
+
...srcValue
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
return objValue;
|
|
226
|
+
}
|
|
227
|
+
else if (isLeafField(srcValue)) {
|
|
228
|
+
return srcValue;
|
|
229
|
+
}
|
|
230
|
+
return undefined;
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
//# sourceMappingURL=resolve-info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"resolve-info.js","sourceRoot":"","sources":["../../src/resolve-info.ts"],"names":[],"mappings":";;;;;;AAAA,0EAAsC;AACtC,qCAmBiB;AACjB,oEAAqC;AACrC,wEAAyC;AACzC,uCAA+C;AA0B/C,MAAM,eAAe,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC;AAYlD,SAAS,eAAe,CAAmB,KAAQ;IACjD,OAAO;QACL,CAAC,eAAe,CAAC,EAAE,IAAI;QACvB,GAAG,KAAK;KACT,CAAC;AACJ,CAAC;AAED,SAAgB,WAAW,CAAC,GAA+B;IACzD,OAAO,CACL,GAAG,IAAI,IAAI,IAAI,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,EAAE,eAAe,CAAC,CAC1E,CAAC;AACJ,CAAC;AAJD,kCAIC;AAED;;;;GAIG;AACH,SAAgB,sBAAsB,CACpC,EACE,MAAM,EACN,SAAS,EACT,SAAS,EACT,UAAU,EACV,SAAS,EACT,SAAS,EACT,UAAU,EASX,EACD,QAA+C;IAE/C,IAAI,YAAY,GAAG,EAAE,CAAC;IACtB,IAAI,OAAO,QAAQ,KAAK,UAAU,EAAE;QAClC,YAAY;YACV,Q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IAED,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC;IAC1C,OAAO,sBAAsB,CAAC,UAAU,CAAC,CAAC;AAC5C,CAAC;AAED;;GAEG;AACH,SAAS,cAAc,CAAC,GAAsB;IAC5C,IAAI,IAAA,oBAAU,EAAC,GAAG,CAAC,IAAI,IAAA,uBAAa,EAAC,GAAG,CAAC,EAAE;QACzC,OAAO,sBAAsB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;KAC3C;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,QAAQ,CAAC,GAAsB,EAAE,SAAiB;IACzD,OAAO,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,SAAS,CAAC,CAAC;AAC1E,CAAC;AAED,uDAAuD;AACvD,qDAAqD;AACrD,SAAS,SAAS,CAAmB,GAAY,EAAE,GAAY;IAC7D,IAAA,0BAAS,EAAC,GAAG,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAyB,EAAE;QAChE,IAAI,WAAW,CAAC,QAAQ,CAAC,EAAE;YACzB,IAAI,WAAW,CAAC,QAAQ,CAAC,EAAE;gBACzB,OAAO;oBACL,GAAG,QAAQ;oBACX,GAAG,QAAQ;iBACZ,CAAC;aACH;YAED,OAAO,QAAQ,CAAC;SACjB;aAAM,IAAI,WAAW,CAAC,QAAQ,CAAC,EAAE;YAChC,OAAO,QAAQ,CAAC;SACjB;QAED,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Maybe<T> = null | undefined | T;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { GraphQLError, GraphQLSchema, VariableDefinitionNode } from "graphql";
|
|
2
|
+
interface FailedVariableCoercion {
|
|
3
|
+
errors: ReadonlyArray<GraphQLError>;
|
|
4
|
+
}
|
|
5
|
+
interface VariableValues {
|
|
6
|
+
coerced: {
|
|
7
|
+
[key: string]: any;
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
export type CoercedVariableValues = FailedVariableCoercion | VariableValues;
|
|
11
|
+
export declare function failToParseVariables(x: any): x is FailedVariableCoercion;
|
|
12
|
+
export declare function compileVariableParsing(schema: GraphQLSchema, varDefNodes: ReadonlyArray<VariableDefinitionNode>): (inputs: {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}) => CoercedVariableValues;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.compileVariableParsing = exports.failToParseVariables = void 0;
|
|
7
|
+
const generate_function_1 = __importDefault(require("generate-function"));
|
|
8
|
+
const graphql_1 = require("graphql");
|
|
9
|
+
const ast_1 = require("./ast");
|
|
10
|
+
const error_1 = require("./error");
|
|
11
|
+
const inspect_1 = __importDefault(require("./inspect"));
|
|
12
|
+
const inspect = (0, inspect_1.default)();
|
|
13
|
+
function failToParseVariables(x) {
|
|
14
|
+
return x.errors;
|
|
15
|
+
}
|
|
16
|
+
exports.failToParseVariables = failToParseVariables;
|
|
17
|
+
function createSubCompilationContext(context) {
|
|
18
|
+
return { ...context };
|
|
19
|
+
}
|
|
20
|
+
function compileVariableParsing(schema, varDefNodes) {
|
|
21
|
+
const errors = [];
|
|
22
|
+
const coercedValues = Object.create(null);
|
|
23
|
+
let mainBody = "";
|
|
24
|
+
const dependencies = new Map();
|
|
25
|
+
for (const varDefNode of varDefNodes) {
|
|
26
|
+
const context = {
|
|
27
|
+
varDefNode,
|
|
28
|
+
depth: 0,
|
|
29
|
+
inputPath: (0, ast_1.addPath)(undefined, "input"),
|
|
30
|
+
responsePath: (0, ast_1.addPath)(undefined, "coerced"),
|
|
31
|
+
dependencies
|
|
32
|
+
};
|
|
33
|
+
const varName = varDefNode.variable.name.value;
|
|
34
|
+
const varType = (0, graphql_1.typeFromAST)(schema, varDefNode.type);
|
|
35
|
+
if (!varType || !(0, graphql_1.isInputType)(varType)) {
|
|
36
|
+
// Must use input types for variables. This should be caught during
|
|
37
|
+
// validation, however is checked again here for safety.
|
|
38
|
+
errors.push(new error_1.GraphQLError(`Variable "$${varName}" expected value of type ` +
|
|
39
|
+
`"${varType || (0, graphql_1.print)(varDefNode.type)}" which cannot be used as an input type.`, (0, ast_1.computeLocations)([varDefNode.type])));
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
// Ensure a constant shape of the input map
|
|
43
|
+
coercedValues[varName] = undefined;
|
|
44
|
+
const hasValueName = hasValue((0, ast_1.addPath)(context.inputPath, varName));
|
|
45
|
+
mainBody += `const ${hasValueName} = Object.prototype.hasOwnProperty.call(${getObjectPath(context.inputPath)}, "${varName}");\n`;
|
|
46
|
+
context.inputPath = (0, ast_1.addPath)(context.inputPath, varName);
|
|
47
|
+
context.responsePath = (0, ast_1.addPath)(context.responsePath, varName);
|
|
48
|
+
mainBody += generateInput(context, varType, varName, hasValueName, (0, graphql_1.valueFromAST)(varDefNode.defaultValue, varType), false);
|
|
49
|
+
}
|
|
50
|
+
if (errors.length > 0) {
|
|
51
|
+
throw errors;
|
|
52
|
+
}
|
|
53
|
+
const gen = (0, generate_function_1.default)();
|
|
54
|
+
gen(`
|
|
55
|
+
return function getVariables(input) {
|
|
56
|
+
const errors = [];
|
|
57
|
+
const coerced = ${JSON.stringify(coercedValues)}
|
|
58
|
+
${mainBody}
|
|
59
|
+
if (errors.length > 0) {
|
|
60
|
+
return {errors, coerced: undefined};
|
|
61
|
+
}
|
|
62
|
+
return {errors: undefined, coerced};
|
|
63
|
+
}
|
|
64
|
+
`);
|
|
65
|
+
// eslint-disable-next-line
|
|
66
|
+
return Function.apply(null, ["GraphQLJITError", "inspect"]
|
|
67
|
+
.concat(Array.from(dependencies.keys()))
|
|
68
|
+
.concat(gen.toString())).apply(null, [error_1.GraphQLError, inspect].concat(Array.from(dependencies.values())));
|
|
69
|
+
}
|
|
70
|
+
exports.compileVariableParsing = compileVariableParsing;
|
|
71
|
+
// Int Scalars represent 32 bits
|
|
72
|
+
// https://graphql.github.io/graphql-spec/June2018/#sec-Int
|
|
73
|
+
const MAX_32BIT_INT = 2147483647;
|
|
74
|
+
const MIN_32BIT_INT = -2147483648;
|
|
75
|
+
function generateInput(context, varType, varName, hasValueName, defaultValue, wrapInList) {
|
|
76
|
+
const currentOutput = getObjectPath(context.responsePath);
|
|
77
|
+
const currentInput = getObjectPath(context.inputPath);
|
|
78
|
+
const errorLocation = printErrorLocation((0, ast_1.computeLocations)([context.varDefNode]));
|
|
79
|
+
const gen = (0, generate_function_1.default)();
|
|
80
|
+
gen(`if (${currentInput} == null) {`);
|
|
81
|
+
if ((0, graphql_1.isNonNullType)(varType)) {
|
|
82
|
+
let nonNullMessage;
|
|
83
|
+
let omittedMessage;
|
|
84
|
+
if (context.errorMessage) {
|
|
85
|
+
const objectPath = printObjectPath(context.responsePath);
|
|
86
|
+
nonNullMessage = `${context.errorMessage} + \`Expected non-nullable type ${varType} not to be null at ${objectPath}.\``;
|
|
87
|
+
omittedMessage = `${context.errorMessage} + \`Field ${objectPath} of required type ${varType} was not provided.\``;
|
|
88
|
+
}
|
|
89
|
+
else {
|
|
90
|
+
nonNullMessage = `'Variable "$${varName}" of non-null type "${varType}" must not be null.'`;
|
|
91
|
+
omittedMessage = `'Variable "$${varName}" of required type "${varType}" was not provided.'`;
|
|
92
|
+
}
|
|
93
|
+
varType = varType.ofType;
|
|
94
|
+
gen(`
|
|
95
|
+
if (${currentOutput} == null) {
|
|
96
|
+
errors.push(new GraphQLJITError(${hasValueName} ? ${nonNullMessage} : ${omittedMessage}, ${errorLocation}));
|
|
97
|
+
}
|
|
98
|
+
`);
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
gen(`
|
|
102
|
+
if (${hasValueName}) { ${currentOutput} = null; }
|
|
103
|
+
`);
|
|
104
|
+
if (defaultValue !== undefined) {
|
|
105
|
+
gen(`else { ${currentOutput} = ${JSON.stringify(defaultValue)} }`);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
gen(`} else {`);
|
|
109
|
+
if ((0, graphql_1.isScalarType)(varType)) {
|
|
110
|
+
switch (varType.name) {
|
|
111
|
+
case graphql_1.GraphQLID.name:
|
|
112
|
+
gen(`
|
|
113
|
+
if (typeof ${currentInput} === "string") {
|
|
114
|
+
${currentOutput} = ${currentInput};
|
|
115
|
+
} else if (Number.isInteger(${currentInput})) {
|
|
116
|
+
${currentOutput} = ${currentInput}.toString();
|
|
117
|
+
} else {
|
|
118
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
119
|
+
inspect(${currentInput}) + "; " +
|
|
120
|
+
'Expected type ${varType.name}; ' +
|
|
121
|
+
'${varType.name} cannot represent value: ' +
|
|
122
|
+
inspect(${currentInput}), ${errorLocation})
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
`);
|
|
126
|
+
break;
|
|
127
|
+
case graphql_1.GraphQLString.name:
|
|
128
|
+
gen(`
|
|
129
|
+
if (typeof ${currentInput} === "string") {
|
|
130
|
+
${currentOutput} = ${currentInput};
|
|
131
|
+
} else {
|
|
132
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
133
|
+
inspect(${currentInput}) + "; " +
|
|
134
|
+
'Expected type ${varType.name}; ' +
|
|
135
|
+
'${varType.name} cannot represent a non string value: ' +
|
|
136
|
+
inspect(${currentInput}), ${errorLocation})
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
`);
|
|
140
|
+
break;
|
|
141
|
+
case graphql_1.GraphQLBoolean.name:
|
|
142
|
+
gen(`
|
|
143
|
+
if (typeof ${currentInput} === "boolean") {
|
|
144
|
+
${currentOutput} = ${currentInput};
|
|
145
|
+
} else {
|
|
146
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
147
|
+
inspect(${currentInput}) + "; " +
|
|
148
|
+
'Expected type ${varType.name}; ' +
|
|
149
|
+
'${varType.name} cannot represent a non boolean value: ' +
|
|
150
|
+
inspect(${currentInput}), ${errorLocation}));
|
|
151
|
+
}
|
|
152
|
+
`);
|
|
153
|
+
break;
|
|
154
|
+
case graphql_1.GraphQLInt.name:
|
|
155
|
+
gen(`
|
|
156
|
+
if (Number.isInteger(${currentInput})) {
|
|
157
|
+
if (${currentInput} > ${MAX_32BIT_INT} || ${currentInput} < ${MIN_32BIT_INT}) {
|
|
158
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
159
|
+
inspect(${currentInput}) + "; " +
|
|
160
|
+
'Expected type ${varType.name}; ' +
|
|
161
|
+
'${varType.name} cannot represent non 32-bit signed integer value: ' +
|
|
162
|
+
inspect(${currentInput}), ${errorLocation}));
|
|
163
|
+
} else {
|
|
164
|
+
${currentOutput} = ${currentInput};
|
|
165
|
+
}
|
|
166
|
+
} else {
|
|
167
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
168
|
+
inspect(${currentInput}) + "; " +
|
|
169
|
+
'Expected type ${varType.name}; ' +
|
|
170
|
+
'${varType.name} cannot represent non-integer value: ' +
|
|
171
|
+
inspect(${currentInput}), ${errorLocation})
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
`);
|
|
175
|
+
break;
|
|
176
|
+
case graphql_1.GraphQLFloat.name:
|
|
177
|
+
gen(`
|
|
178
|
+
if (Number.isFinite(${currentInput})) {
|
|
179
|
+
${currentOutput} = ${currentInput};
|
|
180
|
+
} else {
|
|
181
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
182
|
+
inspect(${currentInput}) + "; " +
|
|
183
|
+
'Expected type ${varType.name}; ' +
|
|
184
|
+
'${varType.name} cannot represent non numeric value: ' +
|
|
185
|
+
inspect(${currentInput}), ${errorLocation})
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
`);
|
|
189
|
+
break;
|
|
190
|
+
default:
|
|
191
|
+
context.dependencies.set(`${varType.name}parseValue`, varType.parseValue.bind(varType));
|
|
192
|
+
gen(`
|
|
193
|
+
try {
|
|
194
|
+
const parseResult = ${varType.name}parseValue(${currentInput});
|
|
195
|
+
if (parseResult === undefined || parseResult !== parseResult) {
|
|
196
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
197
|
+
inspect(${currentInput}) + "; " +
|
|
198
|
+
'Expected type ${varType.name}.', ${errorLocation}));
|
|
199
|
+
}
|
|
200
|
+
${currentOutput} = parseResult;
|
|
201
|
+
} catch (error) {
|
|
202
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
203
|
+
inspect(${currentInput}) + "; " +
|
|
204
|
+
'Expected type ${varType.name}.', ${errorLocation}, undefined, error)
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
`);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
else if ((0, graphql_1.isEnumType)(varType)) {
|
|
211
|
+
context.dependencies.set(`${varType.name}getValue`, varType.getValue.bind(varType));
|
|
212
|
+
gen(`
|
|
213
|
+
if (typeof ${currentInput} === "string") {
|
|
214
|
+
const enumValue = ${varType.name}getValue(${currentInput});
|
|
215
|
+
if (enumValue) {
|
|
216
|
+
${currentOutput} = enumValue.value;
|
|
217
|
+
} else {
|
|
218
|
+
errors.push(
|
|
219
|
+
new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
220
|
+
inspect(${currentInput}) + "; " +
|
|
221
|
+
'Expected type ${varType.name}.', ${errorLocation})
|
|
222
|
+
);
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
errors.push(
|
|
226
|
+
new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
227
|
+
inspect(${currentInput}) + "; " +
|
|
228
|
+
'Expected type ${varType.name}.', ${errorLocation})
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
`);
|
|
232
|
+
}
|
|
233
|
+
else if ((0, graphql_1.isListType)(varType)) {
|
|
234
|
+
context.errorMessage = `'Variable "$${varName}" got invalid value ' + inspect(${currentInput}) + '; '`;
|
|
235
|
+
const hasValueName = hasValue(context.inputPath);
|
|
236
|
+
const index = `idx${context.depth}`;
|
|
237
|
+
const subContext = createSubCompilationContext(context);
|
|
238
|
+
subContext.responsePath = (0, ast_1.addPath)(subContext.responsePath, index, "variable");
|
|
239
|
+
subContext.inputPath = (0, ast_1.addPath)(subContext.inputPath, index, "variable");
|
|
240
|
+
subContext.depth++;
|
|
241
|
+
gen(`
|
|
242
|
+
if (Array.isArray(${currentInput})) {
|
|
243
|
+
${currentOutput} = [];
|
|
244
|
+
for (let ${index} = 0; ${index} < ${currentInput}.length; ++${index}) {
|
|
245
|
+
const ${hasValueName} =
|
|
246
|
+
${getObjectPath(subContext.inputPath)} !== undefined;
|
|
247
|
+
${generateInput(subContext, varType.ofType, varName, hasValueName, undefined, false)}
|
|
248
|
+
}
|
|
249
|
+
} else {
|
|
250
|
+
${generateInput(context, varType.ofType, varName, hasValueName, undefined, true)}
|
|
251
|
+
}
|
|
252
|
+
`);
|
|
253
|
+
}
|
|
254
|
+
else if ((0, graphql_1.isInputType)(varType)) {
|
|
255
|
+
gen(`
|
|
256
|
+
if (typeof ${currentInput} !== 'object') {
|
|
257
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
258
|
+
inspect(${currentInput}) + "; " +
|
|
259
|
+
'Expected type ${varType.name} to be an object.', ${errorLocation}));
|
|
260
|
+
} else {
|
|
261
|
+
${currentOutput} = {};
|
|
262
|
+
`);
|
|
263
|
+
const fields = varType.getFields();
|
|
264
|
+
const allowedFields = [];
|
|
265
|
+
for (const field of Object.values(fields)) {
|
|
266
|
+
const subContext = createSubCompilationContext(context);
|
|
267
|
+
allowedFields.push(field.name);
|
|
268
|
+
const hasValueName = hasValue((0, ast_1.addPath)(subContext.inputPath, field.name));
|
|
269
|
+
gen(`
|
|
270
|
+
const ${hasValueName} = Object.prototype.hasOwnProperty.call(
|
|
271
|
+
${getObjectPath(subContext.inputPath)}, "${field.name}"
|
|
272
|
+
);
|
|
273
|
+
`);
|
|
274
|
+
subContext.inputPath = (0, ast_1.addPath)(subContext.inputPath, field.name);
|
|
275
|
+
subContext.responsePath = (0, ast_1.addPath)(subContext.responsePath, field.name);
|
|
276
|
+
subContext.errorMessage = `'Variable "$${varName}" got invalid value ' + inspect(${currentInput}) + '; '`;
|
|
277
|
+
gen(`
|
|
278
|
+
${generateInput(subContext, field.type, field.name, hasValueName, field.defaultValue, false)}
|
|
279
|
+
`);
|
|
280
|
+
}
|
|
281
|
+
gen(`
|
|
282
|
+
const allowedFields = ${JSON.stringify(allowedFields)};
|
|
283
|
+
for (const fieldName of Object.keys(${currentInput})) {
|
|
284
|
+
if (!allowedFields.includes(fieldName)) {
|
|
285
|
+
errors.push(new GraphQLJITError('Variable "$${varName}" got invalid value ' +
|
|
286
|
+
inspect(${currentInput}) + "; " +
|
|
287
|
+
'Field "' + fieldName + '" is not defined by type ${varType.name}.', ${errorLocation}));
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}`);
|
|
292
|
+
}
|
|
293
|
+
else {
|
|
294
|
+
/* istanbul ignore next line */
|
|
295
|
+
throw new Error(`unknown type: ${varType}`);
|
|
296
|
+
}
|
|
297
|
+
if (wrapInList) {
|
|
298
|
+
gen(`${currentOutput} = [${currentOutput}];`);
|
|
299
|
+
}
|
|
300
|
+
gen(`}`);
|
|
301
|
+
return gen.toString();
|
|
302
|
+
}
|
|
303
|
+
function hasValue(path) {
|
|
304
|
+
const flattened = [];
|
|
305
|
+
let curr = path;
|
|
306
|
+
while (curr) {
|
|
307
|
+
flattened.push(curr.key);
|
|
308
|
+
curr = curr.prev;
|
|
309
|
+
}
|
|
310
|
+
return `hasValue${flattened.join("_")}`;
|
|
311
|
+
}
|
|
312
|
+
function printErrorLocation(location) {
|
|
313
|
+
return JSON.stringify(location);
|
|
314
|
+
}
|
|
315
|
+
function getObjectPath(path) {
|
|
316
|
+
const flattened = [];
|
|
317
|
+
let curr = path;
|
|
318
|
+
while (curr) {
|
|
319
|
+
flattened.unshift({ key: curr.key, type: curr.type });
|
|
320
|
+
curr = curr.prev;
|
|
321
|
+
}
|
|
322
|
+
let name = flattened[0].key;
|
|
323
|
+
for (let i = 1; i < flattened.length; ++i) {
|
|
324
|
+
name +=
|
|
325
|
+
flattened[i].type === "literal"
|
|
326
|
+
? `["${flattened[i].key}"]`
|
|
327
|
+
: `[${flattened[i].key}]`;
|
|
328
|
+
}
|
|
329
|
+
return name;
|
|
330
|
+
}
|
|
331
|
+
function printObjectPath(path) {
|
|
332
|
+
const flattened = [];
|
|
333
|
+
let curr = path;
|
|
334
|
+
while (curr) {
|
|
335
|
+
flattened.unshift({ key: curr.key, type: curr.type });
|
|
336
|
+
curr = curr.prev;
|
|
337
|
+
}
|
|
338
|
+
const initialIndex = Math.min(flattened.length - 1, 1);
|
|
339
|
+
let name = "value";
|
|
340
|
+
for (let i = initialIndex + 1; i < flattened.length; ++i) {
|
|
341
|
+
name +=
|
|
342
|
+
flattened[i].type === "literal"
|
|
343
|
+
? `.${flattened[i].key}`
|
|
344
|
+
: `[$\{${flattened[i].key}}]`;
|
|
345
|
+
}
|
|
346
|
+
return name;
|
|
347
|
+
}
|
|
348
|
+
//# sourceMappingURL=variables.js.map
|