Comparing version 0.0.0-main-99a0ac85 to 0.0.0-main-9fae3b01
{ | ||
"name": "grats", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"main": "dist/src/index.js", | ||
@@ -5,0 +5,0 @@ "bin": "dist/src/cli.js", |
#!/usr/bin/env node | ||
export {}; | ||
import { Location } from "graphql"; | ||
export declare function formatLoc(loc: Location): string; |
@@ -40,2 +40,3 @@ #!/usr/bin/env node | ||
exports.__esModule = true; | ||
exports.formatLoc = void 0; | ||
var graphql_1 = require("graphql"); | ||
@@ -49,2 +50,3 @@ var _1 = require("./"); | ||
var package_json_1 = require("../package.json"); | ||
var Locate_1 = require("./Locate"); | ||
var program = new commander_1.Command(); | ||
@@ -66,4 +68,33 @@ program | ||
}); | ||
program | ||
.command("locate") | ||
.argument("<ENTITY>", "GraphQL entity to locate. E.g. `User` or `User.id`") | ||
.option("--tsconfig <TSCONFIG>", "Path to tsconfig.json. Defaults to auto-detecting based on the current working directory") | ||
.action(function (entity, _a) { | ||
var tsconfig = _a.tsconfig; | ||
var schema = buildSchema(tsconfig); | ||
var loc = (0, Locate_1.locate)(schema, entity); | ||
if (loc.kind === "ERROR") { | ||
console.error(loc.err); | ||
process.exit(1); | ||
} | ||
console.log(formatLoc(loc.value)); | ||
}); | ||
program.parse(); | ||
function build(output, tsconfig) { | ||
var schema = buildSchema(tsconfig); | ||
var sortedSchema = (0, graphql_1.lexicographicSortSchema)(schema); | ||
var schemaStr = (0, utils_1.printSchemaWithDirectives)(sortedSchema, { | ||
assumeValid: true | ||
}); | ||
if (output) { | ||
var absOutput = (0, path_1.resolve)(process.cwd(), output); | ||
(0, fs_1.writeFileSync)(absOutput, schemaStr); | ||
console.error("Grats: Wrote schema to `".concat(absOutput, "`.")); | ||
} | ||
else { | ||
console.log(schemaStr); | ||
} | ||
} | ||
function buildSchema(tsconfig) { | ||
if (tsconfig && !(0, fs_1.existsSync)(tsconfig)) { | ||
@@ -81,12 +112,9 @@ console.error("Grats: Could not find tsconfig.json at `".concat(tsconfig, "`.")); | ||
} | ||
var schema = (0, graphql_1.lexicographicSortSchema)(schemaResult.value); | ||
var schemaStr = (0, utils_1.printSchemaWithDirectives)(schema, { assumeValid: true }); | ||
if (output) { | ||
var absOutput = (0, path_1.resolve)(process.cwd(), output); | ||
(0, fs_1.writeFileSync)(absOutput, schemaStr); | ||
console.error("Grats: Wrote schema to `".concat(absOutput, "`.")); | ||
} | ||
else { | ||
console.log(schemaStr); | ||
} | ||
return schemaResult.value; | ||
} | ||
// Format a location for printing to the console. Tools like VS Code and iTerm | ||
// will automatically turn this into a clickable link. | ||
function formatLoc(loc) { | ||
return "".concat(loc.source.name, ":").concat(loc.startToken.line + 1, ":").concat(loc.startToken.column + 1); | ||
} | ||
exports.formatLoc = formatLoc; |
@@ -74,1 +74,6 @@ /** | ||
export declare function duplicateInterfaceTag(): string; | ||
export declare function parameterWithoutModifiers(): string; | ||
export declare function parameterPropertyNotPublic(): string; | ||
export declare function parameterPropertyMissingType(): string; | ||
export declare function invalidTypePassedToFieldFunction(): string; | ||
export declare function unresolvedTypeReference(): string; |
"use strict"; | ||
exports.__esModule = true; | ||
exports.defaultArgElementIsNotAssignment = exports.defaultValueIsNotLiteral = exports.ambiguousNumberType = exports.expectedOneNonNullishType = exports.propertyFieldMissingType = exports.cannotResolveSymbolForDescription = exports.promiseMissingTypeArg = exports.methodMissingType = exports.gqlEntityMissingName = exports.enumVariantMissingInitializer = exports.enumVariantNotStringLiteral = exports.enumTagOnInvalidNode = exports.argNotTyped = exports.argNameNotLiteral = exports.argIsNotProperty = exports.argumentParamIsNotObject = exports.argumentParamIsMissingType = exports.typeNameDoesNotMatchExpected = exports.typeNameTypeNotStringLiteral = exports.typeNameMissingTypeAnnotation = exports.typeNameInitializerWrong = exports.typeNameInitializeNotString = exports.typeNameMissingInitializer = exports.typeNameNotDeclaration = exports.typeTagOnAliasOfNonObject = exports.typeTagOnUnamedClass = exports.inputFieldUntyped = exports.inputTypeFieldNotProperty = exports.inputTypeNotLiteral = exports.functionFieldNotNamedExport = exports.functionFieldDefaultExport = exports.functionFieldNotNamed = exports.functionFieldParentTypeNotValid = exports.functionFieldParentTypeMissing = exports.functionFieldNotTopLevel = exports.invalidReturnTypeForFunctionField = exports.invalidParentArgForFunctionField = exports.expectedUnionTypeReference = exports.expectedUnionTypeNode = exports.invalidUnionTagUsage = exports.invalidInputTagUsage = exports.invalidEnumTagUsage = exports.invalidInterfaceTagUsage = exports.invalidScalarTagUsage = exports.invalidTypeTagUsage = exports.invalidGratsTag = exports.wrongCasingForGratsTag = exports.killsParentOnExceptionOnWrongNode = exports.implementsTagOnWrongNode = exports.fieldTagOnWrongNode = void 0; | ||
exports.duplicateInterfaceTag = exports.duplicateTag = exports.implementsTagMissingValue = exports.mergedInterfaces = exports.nonNullTypeCannotBeOptional = exports.killsParentOnExceptionOnNullable = exports.killsParentOnExceptionWithWrongConfig = exports.expectedIdentifer = exports.pluralTypeMissingParameter = exports.unknownGraphQLType = exports.unsupportedTypeLiteral = exports.defaultArgPropertyMissingInitializer = exports.defaultArgPropertyMissingName = void 0; | ||
exports.unresolvedTypeReference = exports.invalidTypePassedToFieldFunction = exports.parameterPropertyMissingType = exports.parameterPropertyNotPublic = exports.parameterWithoutModifiers = exports.duplicateInterfaceTag = exports.duplicateTag = exports.implementsTagMissingValue = exports.mergedInterfaces = exports.nonNullTypeCannotBeOptional = exports.killsParentOnExceptionOnNullable = exports.killsParentOnExceptionWithWrongConfig = exports.expectedIdentifer = exports.pluralTypeMissingParameter = exports.unknownGraphQLType = exports.unsupportedTypeLiteral = exports.defaultArgPropertyMissingInitializer = exports.defaultArgPropertyMissingName = void 0; | ||
var Extractor_1 = require("./Extractor"); | ||
// TODO: Move these to short URLS that are easier to keep from breaking. | ||
var DOC_URLS = { | ||
mergedInterfaces: "https://grats.capt.dev/docs/dockblock-tags/interfaces/#merged-interfaces" | ||
mergedInterfaces: "https://grats.capt.dev/docs/dockblock-tags/interfaces/#merged-interfaces", | ||
parameterProperties: "https://grats.capt.dev/docs/dockblock-tags/fields#class-based-fields" | ||
}; | ||
@@ -279,1 +280,27 @@ /** | ||
exports.duplicateInterfaceTag = duplicateInterfaceTag; | ||
function parameterWithoutModifiers() { | ||
return [ | ||
"Expected `@".concat(Extractor_1.FIELD_TAG, "` constructor paramater to be a parameter property. This requires a modifier such as `public` or `readonly` before the parameter name.\n\n"), | ||
"Learn more: ".concat(DOC_URLS.parameterProperties), | ||
].join(""); | ||
} | ||
exports.parameterWithoutModifiers = parameterWithoutModifiers; | ||
function parameterPropertyNotPublic() { | ||
return [ | ||
"Expected `@".concat(Extractor_1.FIELD_TAG, "` parameter property to be public. Valid modifiers for `@").concat(Extractor_1.FIELD_TAG, "` parameter properties are `public` and `readonly`.\n\n"), | ||
"Learn more: ".concat(DOC_URLS.parameterProperties), | ||
].join(""); | ||
} | ||
exports.parameterPropertyNotPublic = parameterPropertyNotPublic; | ||
function parameterPropertyMissingType() { | ||
return "Expected `@".concat(Extractor_1.FIELD_TAG, "` parameter property to have a type annotation."); | ||
} | ||
exports.parameterPropertyMissingType = parameterPropertyMissingType; | ||
function invalidTypePassedToFieldFunction() { | ||
return "Unexpected type passed to `@".concat(Extractor_1.FIELD_TAG, "` function. `@").concat(Extractor_1.FIELD_TAG, "` functions can only be used to extend `@").concat(Extractor_1.TYPE_TAG, "` and `@").concat(Extractor_1.INTERFACE_TAG, "` types."); | ||
} | ||
exports.invalidTypePassedToFieldFunction = invalidTypePassedToFieldFunction; | ||
function unresolvedTypeReference() { | ||
return "This type is not a valid GraphQL type. Did you mean to annotate it's definition with a `/** @gql */` tag such as `/** @gqlType */` or `/** @gqlInput **/`?"; | ||
} | ||
exports.unresolvedTypeReference = unresolvedTypeReference; |
@@ -1,6 +0,7 @@ | ||
import { DefinitionNode, FieldDefinitionNode, InputValueDefinitionNode, ListTypeNode, NamedTypeNode, Location as GraphQLLocation, NameNode, Token, TypeNode, NonNullTypeNode, StringValueNode, ConstValueNode, ConstDirectiveNode, ConstArgumentNode, EnumValueDefinitionNode, ConstObjectFieldNode, ConstObjectValueNode, ConstListValueNode } from "graphql"; | ||
import { FieldDefinitionNode, InputValueDefinitionNode, NamedTypeNode, NameNode, TypeNode, StringValueNode, ConstValueNode, ConstDirectiveNode, EnumValueDefinitionNode, ConstObjectFieldNode, ConstObjectValueNode, ConstListValueNode } from "graphql"; | ||
import { DiagnosticsResult } from "./utils/DiagnosticError"; | ||
import * as ts from "typescript"; | ||
import { TypeContext } from "./TypeContext"; | ||
import { GratsDefinitionNode, TypeContext } from "./TypeContext"; | ||
import { ConfigOptions } from "./lib"; | ||
import { GraphQLConstructor } from "./GraphQLConstructor"; | ||
export declare const LIBRARY_IMPORT_NAME = "grats"; | ||
@@ -31,3 +32,3 @@ export declare const LIBRARY_NAME = "Grats"; | ||
export declare class Extractor { | ||
definitions: DefinitionNode[]; | ||
definitions: GratsDefinitionNode[]; | ||
sourceFile: ts.SourceFile; | ||
@@ -37,4 +38,5 @@ ctx: TypeContext; | ||
errors: ts.Diagnostic[]; | ||
gql: GraphQLConstructor; | ||
constructor(sourceFile: ts.SourceFile, ctx: TypeContext, buildOptions: ConfigOptions); | ||
extract(): DiagnosticsResult<DefinitionNode[]>; | ||
extract(): DiagnosticsResult<GratsDefinitionNode[]>; | ||
extractType(node: ts.Node, tag: ts.JSDocTag): void; | ||
@@ -48,3 +50,3 @@ extractScalar(node: ts.Node, tag: ts.JSDocTag): void; | ||
report(node: ts.Node, message: string, relatedInformation?: ts.DiagnosticRelatedInformation[]): null; | ||
reportUnhandled(node: ts.Node, message: string, relatedInformation?: ts.DiagnosticRelatedInformation[]): null; | ||
reportUnhandled(node: ts.Node, positionKind: "type" | "field" | "field type" | "input" | "input field" | "union member" | "constant value" | "union" | "enum value", message: string, relatedInformation?: ts.DiagnosticRelatedInformation[]): null; | ||
related(node: ts.Node, message: string): ts.DiagnosticRelatedInformation; | ||
@@ -56,4 +58,2 @@ diagnosticAnnotatedLocation(node: ts.Node): { | ||
}; | ||
loc(node: ts.Node): GraphQLLocation; | ||
gqlDummyToken(pos: number): Token; | ||
/** TypeScript traversals */ | ||
@@ -81,2 +81,3 @@ unionTypeAliasDeclaration(node: ts.TypeAliasDeclaration, tag: ts.JSDocTag): null | undefined; | ||
collectFields(node: ts.ClassDeclaration | ts.InterfaceDeclaration | ts.TypeLiteralNode): Array<FieldDefinitionNode>; | ||
constructorParam(node: ts.ParameterDeclaration): FieldDefinitionNode | null; | ||
collectArgs(argsParam: ts.ParameterDeclaration): ReadonlyArray<InputValueDefinitionNode> | null; | ||
@@ -93,3 +94,3 @@ collectArgDefaults(node: ts.ObjectBindingPattern): ArgDefaults; | ||
collectEnumValues(node: ts.EnumDeclaration): ReadonlyArray<EnumValueDefinitionNode>; | ||
entityName(node: ts.ClassDeclaration | ts.MethodDeclaration | ts.MethodSignature | ts.PropertyDeclaration | ts.InterfaceDeclaration | ts.PropertySignature | ts.EnumDeclaration | ts.TypeAliasDeclaration | ts.FunctionDeclaration, tag: ts.JSDocTag): NameNode | null; | ||
entityName(node: ts.ClassDeclaration | ts.MethodDeclaration | ts.MethodSignature | ts.PropertyDeclaration | ts.InterfaceDeclaration | ts.PropertySignature | ts.EnumDeclaration | ts.TypeAliasDeclaration | ts.FunctionDeclaration | ts.ParameterDeclaration, tag: ts.JSDocTag): NameNode | null; | ||
methodDeclaration(node: ts.MethodDeclaration | ts.MethodSignature): FieldDefinitionNode | null; | ||
@@ -108,14 +109,5 @@ collectMethodType(node: ts.TypeNode): TypeNode | null; | ||
handleErrorBubbling(parentNode: ts.Node, type: TypeNode): TypeNode; | ||
methodNameDirective(nameNode: ts.Node, name: string): ConstDirectiveNode; | ||
exportDirective(nameNode: ts.Node, filename: string, functionName: string): ConstDirectiveNode; | ||
/** GraphQL AST node helper methods */ | ||
gqlName(node: ts.Node, value: string): NameNode; | ||
gqlNamedType(node: ts.Node, value: string): NamedTypeNode; | ||
gqlNonNullType(node: ts.Node, type: TypeNode): NonNullTypeNode; | ||
gqlNullableType(type: TypeNode): NamedTypeNode | ListTypeNode; | ||
gqlListType(node: ts.Node, type: TypeNode): ListTypeNode; | ||
gqlConstArgument(node: ts.Node, name: NameNode, value: ConstValueNode): ConstArgumentNode; | ||
gqlConstDirective(node: ts.Node, name: NameNode, args: ReadonlyArray<ConstArgumentNode>): ConstDirectiveNode; | ||
gqlString(node: ts.Node, value: string): StringValueNode; | ||
fieldNameDirective(nameNode: ts.Node, name: string): ConstDirectiveNode; | ||
} | ||
export {}; |
@@ -35,6 +35,7 @@ "use strict"; | ||
var TypeContext_1 = require("./TypeContext"); | ||
var serverDirectives_1 = require("./serverDirectives"); | ||
var E = require("./Errors"); | ||
var JSDoc_1 = require("./utils/JSDoc"); | ||
var helpers_1 = require("./utils/helpers"); | ||
var GraphQLConstructor_1 = require("./GraphQLConstructor"); | ||
var serverDirectives_1 = require("./serverDirectives"); | ||
exports.LIBRARY_IMPORT_NAME = "grats"; | ||
@@ -81,2 +82,3 @@ exports.LIBRARY_NAME = "Grats"; | ||
this.configOptions = buildOptions; | ||
this.gql = new GraphQLConstructor_1.GraphQLConstructor(sourceFile); | ||
} | ||
@@ -114,3 +116,4 @@ // Traverse all nodes, checking each one for its JSDoc tags. | ||
} | ||
else if (!(ts.isMethodDeclaration(node) || | ||
else if (!(ts.isParameter(node) || | ||
ts.isMethodDeclaration(node) || | ||
ts.isPropertyDeclaration(node) || | ||
@@ -121,3 +124,3 @@ ts.isMethodSignature(node) || | ||
// Note: Keep this in sync with `collectFields` | ||
_this.reportUnhandled(node, E.fieldTagOnWrongNode()); | ||
_this.reportUnhandled(node, "field", E.fieldTagOnWrongNode()); | ||
} | ||
@@ -248,4 +251,4 @@ break; | ||
// Gives the user a path forward if they think we should be able to infer this type. | ||
Extractor.prototype.reportUnhandled = function (node, message, relatedInformation) { | ||
var suggestion = "If you think ".concat(exports.LIBRARY_NAME, " should be able to infer this type, please report an issue at ").concat(exports.ISSUE_URL, "."); | ||
Extractor.prototype.reportUnhandled = function (node, positionKind, message, relatedInformation) { | ||
var suggestion = "If you think ".concat(exports.LIBRARY_NAME, " should be able to infer this ").concat(positionKind, ", please report an issue at ").concat(exports.ISSUE_URL, "."); | ||
var completedMessage = "".concat(message, "\n\n").concat(suggestion); | ||
@@ -269,15 +272,2 @@ return this.report(node, completedMessage, relatedInformation); | ||
}; | ||
// TODO: This is potentially quite expensive, and we only need it if we report | ||
// an error at one of these locations. We could consider some trick to return a | ||
// proxy object that would lazily compute the line/column info. | ||
Extractor.prototype.loc = function (node) { | ||
var source = new graphql_1.Source(this.sourceFile.text, this.sourceFile.fileName); | ||
var startToken = this.gqlDummyToken(node.getStart()); | ||
var endToken = this.gqlDummyToken(node.getEnd()); | ||
return new graphql_1.Location(startToken, endToken, source); | ||
}; | ||
Extractor.prototype.gqlDummyToken = function (pos) { | ||
var _a = this.sourceFile.getLineAndCharacterOfPosition(pos), line = _a.line, character = _a.character; | ||
return new graphql_1.Token(graphql_1.TokenKind.SOF, pos, pos, line, character, undefined); | ||
}; | ||
/** TypeScript traversals */ | ||
@@ -298,5 +288,5 @@ Extractor.prototype.unionTypeAliasDeclaration = function (node, tag) { | ||
if (!ts.isTypeReferenceNode(member)) { | ||
return this.reportUnhandled(member, E.expectedUnionTypeReference()); | ||
return this.reportUnhandled(member, "union member", E.expectedUnionTypeReference()); | ||
} | ||
var namedType = this.gqlNamedType(member.typeName, TypeContext_1.UNRESOLVED_REFERENCE_NAME); | ||
var namedType = this.gql.namedType(member.typeName, TypeContext_1.UNRESOLVED_REFERENCE_NAME); | ||
this.ctx.markUnresolvedType(member.typeName, namedType.name); | ||
@@ -313,10 +303,4 @@ types.push(namedType); | ||
} | ||
this.ctx.recordTypeName(node.name, name.value); | ||
this.definitions.push({ | ||
kind: graphql_1.Kind.UNION_TYPE_DEFINITION, | ||
loc: this.loc(node), | ||
description: description !== null && description !== void 0 ? description : undefined, | ||
name: name, | ||
types: types | ||
}); | ||
this.ctx.recordTypeName(node.name, name, "UNION"); | ||
this.definitions.push(this.gql.unionTypeDefinition(node, name, types, description)); | ||
}; | ||
@@ -358,3 +342,3 @@ Extractor.prototype.functionDeclarationExtendType = function (node, tag) { | ||
if (funcName.text !== name.value) { | ||
directives.push(this.methodNameDirective(funcName, funcName.text)); | ||
directives.push(this.fieldNameDirective(funcName, funcName.text)); | ||
} | ||
@@ -365,18 +349,4 @@ var deprecated = this.collectDeprecated(node); | ||
} | ||
this.definitions.push({ | ||
kind: graphql_1.Kind.OBJECT_TYPE_EXTENSION, | ||
loc: this.loc(node), | ||
name: typeName, | ||
fields: [ | ||
{ | ||
kind: graphql_1.Kind.FIELD_DEFINITION, | ||
loc: this.loc(node), | ||
description: description || undefined, | ||
name: name, | ||
arguments: args || undefined, | ||
type: this.handleErrorBubbling(node, type), | ||
directives: directives.length === 0 ? undefined : directives | ||
}, | ||
] | ||
}); | ||
var field = this.gql.fieldDefinition(node, name, this.handleErrorBubbling(node, type), args, directives, description); | ||
this.definitions.push(this.gql.abstractFieldDefinition(node, typeName, field)); | ||
}; | ||
@@ -391,3 +361,3 @@ Extractor.prototype.typeReferenceFromParam = function (typeParam) { | ||
var nameNode = typeParam.type.typeName; | ||
var typeName = this.gqlName(nameNode, TypeContext_1.UNRESOLVED_REFERENCE_NAME); | ||
var typeName = this.gql.name(nameNode, TypeContext_1.UNRESOLVED_REFERENCE_NAME); | ||
this.ctx.markUnresolvedType(nameNode, typeName); | ||
@@ -421,9 +391,4 @@ return typeName; | ||
var description = this.collectDescription(node.name); | ||
this.ctx.recordTypeName(node.name, name.value); | ||
this.definitions.push({ | ||
kind: graphql_1.Kind.SCALAR_TYPE_DEFINITION, | ||
loc: this.loc(node), | ||
description: description !== null && description !== void 0 ? description : undefined, | ||
name: name | ||
}); | ||
this.ctx.recordTypeName(node.name, name, "SCALAR"); | ||
this.definitions.push(this.gql.scalarTypeDefinition(node, name, description)); | ||
}; | ||
@@ -435,13 +400,6 @@ Extractor.prototype.inputTypeAliasDeclaration = function (node, tag) { | ||
var description = this.collectDescription(node.name); | ||
this.ctx.recordTypeName(node.name, name.value); | ||
this.ctx.recordTypeName(node.name, name, "INPUT_OBJECT"); | ||
var fields = this.collectInputFields(node); | ||
var deprecatedDirective = this.collectDeprecated(node); | ||
this.definitions.push({ | ||
kind: graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION, | ||
loc: this.loc(node), | ||
description: description !== null && description !== void 0 ? description : undefined, | ||
name: name, | ||
fields: fields !== null && fields !== void 0 ? fields : undefined, | ||
directives: deprecatedDirective == null ? undefined : [deprecatedDirective] | ||
}); | ||
this.definitions.push(this.gql.inputObjectTypeDefinition(node, name, fields, deprecatedDirective == null ? null : [deprecatedDirective], description)); | ||
}; | ||
@@ -452,3 +410,3 @@ Extractor.prototype.collectInputFields = function (node) { | ||
if (!ts.isTypeLiteralNode(node.type)) { | ||
return this.reportUnhandled(node, E.inputTypeNotLiteral()); | ||
return this.reportUnhandled(node, "input", E.inputTypeNotLiteral()); | ||
} | ||
@@ -459,3 +417,3 @@ try { | ||
if (!ts.isPropertySignature(member)) { | ||
this.reportUnhandled(member, E.inputTypeFieldNotProperty()); | ||
this.reportUnhandled(member, "input field", E.inputTypeFieldNotProperty()); | ||
continue; | ||
@@ -487,14 +445,6 @@ } | ||
return null; | ||
var type = node.questionToken == null ? inner : this.gqlNullableType(inner); | ||
var type = node.questionToken == null ? inner : this.gql.nullableType(inner); | ||
var description = this.collectDescription(node.name); | ||
var deprecatedDirective = this.collectDeprecated(node); | ||
return { | ||
kind: graphql_1.Kind.INPUT_VALUE_DEFINITION, | ||
loc: this.loc(node), | ||
description: description !== null && description !== void 0 ? description : undefined, | ||
name: this.gqlName(id, id.text), | ||
type: type, | ||
defaultValue: undefined, | ||
directives: deprecatedDirective == null ? undefined : [deprecatedDirective] | ||
}; | ||
return this.gql.inputValueDefinition(node, this.gql.name(id, id.text), type, deprecatedDirective == null ? null : [deprecatedDirective], null, description); | ||
}; | ||
@@ -511,13 +461,5 @@ Extractor.prototype.typeClassDeclaration = function (node, tag) { | ||
var interfaces = this.collectInterfaces(node); | ||
this.ctx.recordTypeName(node.name, name.value); | ||
this.ctx.recordTypeName(node.name, name, "TYPE"); | ||
this.checkForTypenameProperty(node, name.value); | ||
this.definitions.push({ | ||
kind: graphql_1.Kind.OBJECT_TYPE_DEFINITION, | ||
loc: this.loc(node), | ||
description: description !== null && description !== void 0 ? description : undefined, | ||
directives: undefined, | ||
name: name, | ||
fields: fields, | ||
interfaces: interfaces !== null && interfaces !== void 0 ? interfaces : undefined | ||
}); | ||
this.definitions.push(this.gql.objectTypeDefinition(node, name, fields, interfaces, description)); | ||
}; | ||
@@ -531,13 +473,5 @@ Extractor.prototype.typeInterfaceDeclaration = function (node, tag) { | ||
var interfaces = this.collectInterfaces(node); | ||
this.ctx.recordTypeName(node.name, name.value); | ||
this.ctx.recordTypeName(node.name, name, "INTERFACE"); | ||
this.checkForTypenameProperty(node, name.value); | ||
this.definitions.push({ | ||
kind: graphql_1.Kind.OBJECT_TYPE_DEFINITION, | ||
loc: this.loc(node), | ||
description: description !== null && description !== void 0 ? description : undefined, | ||
directives: undefined, | ||
name: name, | ||
fields: fields, | ||
interfaces: interfaces !== null && interfaces !== void 0 ? interfaces : undefined | ||
}); | ||
this.definitions.push(this.gql.objectTypeDefinition(node, name, fields, interfaces, description)); | ||
}; | ||
@@ -549,3 +483,3 @@ Extractor.prototype.typeTypeAliasDeclaration = function (node, tag) { | ||
if (!ts.isTypeLiteralNode(node.type)) { | ||
this.reportUnhandled(node.type, E.typeTagOnAliasOfNonObject()); | ||
this.reportUnhandled(node.type, "type", E.typeTagOnAliasOfNonObject()); | ||
return; | ||
@@ -556,13 +490,5 @@ } | ||
var interfaces = this.collectInterfaces(node); | ||
this.ctx.recordTypeName(node.name, name.value); | ||
this.ctx.recordTypeName(node.name, name, "TYPE"); | ||
this.checkForTypenameProperty(node.type, name.value); | ||
this.definitions.push({ | ||
kind: graphql_1.Kind.OBJECT_TYPE_DEFINITION, | ||
loc: this.loc(node), | ||
description: description !== null && description !== void 0 ? description : undefined, | ||
directives: undefined, | ||
name: name, | ||
fields: fields, | ||
interfaces: interfaces !== null && interfaces !== void 0 ? interfaces : undefined | ||
}); | ||
this.definitions.push(this.gql.objectTypeDefinition(node, name, fields, interfaces, description)); | ||
}; | ||
@@ -653,3 +579,3 @@ Extractor.prototype.checkForTypenameProperty = function (node, expectedName) { | ||
// a richer set of tools to construct custom locations. | ||
return _this.gqlNamedType(tag, name.trim()); | ||
return _this.gql.namedType(tag, name.trim()); | ||
}); | ||
@@ -669,3 +595,3 @@ }; | ||
} | ||
var namedType = _this.gqlNamedType(type.expression, TypeContext_1.UNRESOLVED_REFERENCE_NAME); | ||
var namedType = _this.gql.namedType(type.expression, TypeContext_1.UNRESOLVED_REFERENCE_NAME); | ||
_this.ctx.markUnresolvedType(type.expression, namedType.name); | ||
@@ -707,11 +633,4 @@ return namedType; | ||
var fields = this.collectFields(node); | ||
this.ctx.recordTypeName(node.name, name.value); | ||
this.definitions.push({ | ||
kind: graphql_1.Kind.INTERFACE_TYPE_DEFINITION, | ||
loc: this.loc(node), | ||
description: description || undefined, | ||
name: name, | ||
fields: fields, | ||
interfaces: interfaces || undefined | ||
}); | ||
this.ctx.recordTypeName(node.name, name, "INTERFACE"); | ||
this.definitions.push(this.gql.interfaceTypeDefinition(node, name, fields, interfaces, description)); | ||
}; | ||
@@ -722,5 +641,26 @@ Extractor.prototype.collectFields = function (node) { | ||
ts.forEachChild(node, function (node) { | ||
var e_4, _a; | ||
if (ts.isConstructorDeclaration(node)) { | ||
try { | ||
// Handle parameter properties | ||
// https://www.typescriptlang.org/docs/handbook/2/classes.html#parameter-properties | ||
for (var _b = __values(node.parameters), _c = _b.next(); !_c.done; _c = _b.next()) { | ||
var param = _c.value; | ||
var field = _this.constructorParam(param); | ||
if (field != null) { | ||
fields.push(field); | ||
} | ||
} | ||
} | ||
catch (e_4_1) { e_4 = { error: e_4_1 }; } | ||
finally { | ||
try { | ||
if (_c && !_c.done && (_a = _b["return"])) _a.call(_b); | ||
} | ||
finally { if (e_4) throw e_4.error; } | ||
} | ||
} | ||
if (ts.isMethodDeclaration(node) || ts.isMethodSignature(node)) { | ||
var field = _this.methodDeclaration(node); | ||
if (field) { | ||
if (field != null) { | ||
fields.push(field); | ||
@@ -739,4 +679,54 @@ } | ||
}; | ||
Extractor.prototype.constructorParam = function (node) { | ||
var tag = this.findTag(node, exports.FIELD_TAG); | ||
if (tag == null) | ||
return null; | ||
if (node.modifiers == null) { | ||
return this.report(node, E.parameterWithoutModifiers()); | ||
} | ||
var isParameterProperty = node.modifiers.some(function (modifier) { | ||
return modifier.kind === ts.SyntaxKind.PublicKeyword || | ||
modifier.kind === ts.SyntaxKind.PrivateKeyword || | ||
modifier.kind === ts.SyntaxKind.ProtectedKeyword || | ||
modifier.kind === ts.SyntaxKind.ReadonlyKeyword; | ||
}); | ||
if (!isParameterProperty) { | ||
return this.report(node, E.parameterWithoutModifiers()); | ||
} | ||
var notPublic = node.modifiers.find(function (modifier) { | ||
return modifier.kind === ts.SyntaxKind.PrivateKeyword || | ||
modifier.kind === ts.SyntaxKind.ProtectedKeyword; | ||
}); | ||
if (notPublic != null) { | ||
return this.report(notPublic, E.parameterPropertyNotPublic()); | ||
} | ||
var name = this.entityName(node, tag); | ||
if (name == null) | ||
return null; | ||
if (node.type == null) { | ||
return this.report(node, E.parameterPropertyMissingType()); | ||
} | ||
var id = node.name; | ||
if (ts.isArrayBindingPattern(id) || ts.isObjectBindingPattern(id)) { | ||
// TypeScript triggers an error if a binding pattern is used for a | ||
// parameter property, so we don't need to report them. | ||
// https://www.typescriptlang.org/play?#code/MYGwhgzhAEBiD29oG8BQ1rHgOwgFwCcBXYPeAgCgAciAjEAS2BQDNEBfAShXdXaA | ||
return null; | ||
} | ||
var directives = []; | ||
if (id.text !== name.value) { | ||
directives = [this.fieldNameDirective(node.name, id.text)]; | ||
} | ||
var type = this.collectType(node.type); | ||
if (type == null) | ||
return null; | ||
var deprecated = this.collectDeprecated(node); | ||
if (deprecated != null) { | ||
directives.push(deprecated); | ||
} | ||
var description = this.collectDescription(node.name); | ||
return this.gql.fieldDefinition(node, name, this.handleErrorBubbling(node, type), null, directives, description); | ||
}; | ||
Extractor.prototype.collectArgs = function (argsParam) { | ||
var e_4, _a; | ||
var e_5, _a; | ||
var args = []; | ||
@@ -766,3 +756,3 @@ var argsType = argsParam.type; | ||
} | ||
catch (e_4_1) { e_4 = { error: e_4_1 }; } | ||
catch (e_5_1) { e_5 = { error: e_5_1 }; } | ||
finally { | ||
@@ -772,3 +762,3 @@ try { | ||
} | ||
finally { if (e_4) throw e_4.error; } | ||
finally { if (e_5) throw e_5.error; } | ||
} | ||
@@ -778,3 +768,3 @@ return args; | ||
Extractor.prototype.collectArgDefaults = function (node) { | ||
var e_5, _a; | ||
var e_6, _a; | ||
var defaults = new Map(); | ||
@@ -791,3 +781,3 @@ try { | ||
} | ||
catch (e_5_1) { e_5 = { error: e_5_1 }; } | ||
catch (e_6_1) { e_6 = { error: e_6_1 }; } | ||
finally { | ||
@@ -797,3 +787,3 @@ try { | ||
} | ||
finally { if (e_5) throw e_5.error; } | ||
finally { if (e_6) throw e_6.error; } | ||
} | ||
@@ -804,16 +794,17 @@ return defaults; | ||
if (ts.isStringLiteral(node)) { | ||
return { kind: graphql_1.Kind.STRING, loc: this.loc(node), value: node.text }; | ||
return this.gql.string(node, node.text); | ||
} | ||
else if (ts.isNumericLiteral(node)) { | ||
var kind = node.text.includes(".") ? graphql_1.Kind.FLOAT : graphql_1.Kind.INT; | ||
return { kind: kind, loc: this.loc(node), value: node.text }; | ||
return node.text.includes(".") | ||
? this.gql.float(node, node.text) | ||
: this.gql.int(node, node.text); | ||
} | ||
else if (this.isNullish(node)) { | ||
return { kind: graphql_1.Kind.NULL, loc: this.loc(node) }; | ||
return this.gql["null"](node); | ||
} | ||
else if (node.kind === ts.SyntaxKind.TrueKeyword) { | ||
return { kind: graphql_1.Kind.BOOLEAN, loc: this.loc(node), value: true }; | ||
return this.gql.boolean(node, true); | ||
} | ||
else if (node.kind === ts.SyntaxKind.FalseKeyword) { | ||
return { kind: graphql_1.Kind.BOOLEAN, loc: this.loc(node), value: false }; | ||
return this.gql.boolean(node, false); | ||
} | ||
@@ -826,6 +817,6 @@ else if (ts.isObjectLiteralExpression(node)) { | ||
} | ||
return this.reportUnhandled(node, E.defaultValueIsNotLiteral()); | ||
return this.reportUnhandled(node, "constant value", E.defaultValueIsNotLiteral()); | ||
}; | ||
Extractor.prototype.collectArrayLiteral = function (node) { | ||
var e_6, _a; | ||
var e_7, _a; | ||
var values = []; | ||
@@ -845,3 +836,3 @@ var errors = false; | ||
} | ||
catch (e_6_1) { e_6 = { error: e_6_1 }; } | ||
catch (e_7_1) { e_7 = { error: e_7_1 }; } | ||
finally { | ||
@@ -851,3 +842,3 @@ try { | ||
} | ||
finally { if (e_6) throw e_6.error; } | ||
finally { if (e_7) throw e_7.error; } | ||
} | ||
@@ -857,10 +848,6 @@ if (errors) { | ||
} | ||
return { | ||
kind: graphql_1.Kind.LIST, | ||
loc: this.loc(node), | ||
values: values | ||
}; | ||
return this.gql.list(node, values); | ||
}; | ||
Extractor.prototype.cellectObjectLiteral = function (node) { | ||
var e_7, _a; | ||
var e_8, _a; | ||
var fields = []; | ||
@@ -880,3 +867,3 @@ var errors = false; | ||
} | ||
catch (e_7_1) { e_7 = { error: e_7_1 }; } | ||
catch (e_8_1) { e_8 = { error: e_8_1 }; } | ||
finally { | ||
@@ -886,3 +873,3 @@ try { | ||
} | ||
finally { if (e_7) throw e_7.error; } | ||
finally { if (e_8) throw e_8.error; } | ||
} | ||
@@ -892,14 +879,10 @@ if (errors) { | ||
} | ||
return { | ||
kind: graphql_1.Kind.OBJECT, | ||
loc: this.loc(node), | ||
fields: fields | ||
}; | ||
return this.gql.object(node, fields); | ||
}; | ||
Extractor.prototype.collectObjectField = function (node) { | ||
if (!ts.isPropertyAssignment(node)) { | ||
return this.reportUnhandled(node, E.defaultArgElementIsNotAssignment()); | ||
return this.reportUnhandled(node, "constant value", E.defaultArgElementIsNotAssignment()); | ||
} | ||
if (node.name == null) { | ||
return this.reportUnhandled(node, E.defaultArgPropertyMissingName()); | ||
return this.reportUnhandled(node, "field", E.defaultArgPropertyMissingName()); | ||
} | ||
@@ -916,8 +899,3 @@ var name = this.expectIdentifier(node.name); | ||
return null; | ||
return { | ||
kind: graphql_1.Kind.OBJECT_FIELD, | ||
loc: this.loc(node), | ||
name: this.gqlName(node.name, name.text), | ||
value: value | ||
}; | ||
return this.gql.constObjectField(node, this.gql.name(node.name, name.text), value); | ||
}; | ||
@@ -946,3 +924,3 @@ Extractor.prototype.collectArg = function (node, defaults) { | ||
*/ | ||
type = this.gqlNullableType(type); | ||
type = this.gql.nullableType(type); | ||
} | ||
@@ -958,11 +936,3 @@ var description = this.collectDescription(node.name); | ||
var deprecatedDirective = this.collectDeprecated(node); | ||
return { | ||
kind: graphql_1.Kind.INPUT_VALUE_DEFINITION, | ||
loc: this.loc(node), | ||
description: description || undefined, | ||
name: this.gqlName(node.name, node.name.text), | ||
type: type, | ||
defaultValue: defaultValue || undefined, | ||
directives: deprecatedDirective != null ? [deprecatedDirective] : undefined | ||
}; | ||
return this.gql.inputValueDefinition(node, this.gql.name(node.name, node.name.text), type, deprecatedDirective == null ? null : [deprecatedDirective], defaultValue, description); | ||
}; | ||
@@ -976,10 +946,4 @@ Extractor.prototype.enumEnumDeclaration = function (node, tag) { | ||
var values = this.collectEnumValues(node); | ||
this.ctx.recordTypeName(node.name, name.value); | ||
this.definitions.push({ | ||
kind: graphql_1.Kind.ENUM_TYPE_DEFINITION, | ||
loc: this.loc(node), | ||
description: description || undefined, | ||
name: name, | ||
values: values | ||
}); | ||
this.ctx.recordTypeName(node.name, name, "ENUM"); | ||
this.definitions.push(this.gql.enumTypeDefinition(node, name, values, description)); | ||
}; | ||
@@ -995,13 +959,7 @@ Extractor.prototype.enumTypeAliasDeclaration = function (node, tag) { | ||
var description = this.collectDescription(node.name); | ||
this.ctx.recordTypeName(node.name, name.value); | ||
this.definitions.push({ | ||
kind: graphql_1.Kind.ENUM_TYPE_DEFINITION, | ||
loc: this.loc(node), | ||
description: description || undefined, | ||
name: name, | ||
values: values | ||
}); | ||
this.ctx.recordTypeName(node.name, name, "ENUM"); | ||
this.definitions.push(this.gql.enumTypeDefinition(node, name, values, description)); | ||
}; | ||
Extractor.prototype.enumTypeAliasVariants = function (node) { | ||
var e_8, _a; | ||
var e_9, _a; | ||
var _b; | ||
@@ -1016,12 +974,7 @@ // Semantically we only support deriving enums from type aliases that | ||
return [ | ||
{ | ||
kind: graphql_1.Kind.ENUM_VALUE_DEFINITION, | ||
name: this.gqlName(node.type.literal, node.type.literal.text), | ||
description: undefined, | ||
loc: this.loc(node) | ||
}, | ||
this.gql.enumValueDefinition(node, this.gql.name(node.type.literal, node.type.literal.text), undefined, null), | ||
]; | ||
} | ||
if (!ts.isUnionTypeNode(node.type)) { | ||
this.reportUnhandled(node.type, E.enumTagOnInvalidNode()); | ||
this.reportUnhandled(node.type, "union", E.enumTagOnInvalidNode()); | ||
return null; | ||
@@ -1045,9 +998,3 @@ } | ||
var memberDescription = this.collectDescription(declaration.name); | ||
values.push({ | ||
kind: graphql_1.Kind.ENUM_VALUE_DEFINITION, | ||
name: this.gqlName(declaration.type.literal, declaration.type.literal.text), | ||
directives: deprecatedDirective ? [deprecatedDirective] : [], | ||
description: memberDescription || undefined, | ||
loc: this.loc(node) | ||
}); | ||
values.push(this.gql.enumValueDefinition(node, this.gql.name(declaration.type.literal, declaration.type.literal.text), deprecatedDirective ? [deprecatedDirective] : [], memberDescription)); | ||
continue; | ||
@@ -1061,3 +1008,3 @@ } | ||
!ts.isStringLiteral(member.literal)) { | ||
this.reportUnhandled(member, E.enumVariantNotStringLiteral()); | ||
this.reportUnhandled(member, "union member", E.enumVariantNotStringLiteral()); | ||
continue; | ||
@@ -1067,11 +1014,6 @@ } | ||
// does not allow comments attached to string literal types. | ||
values.push({ | ||
kind: graphql_1.Kind.ENUM_VALUE_DEFINITION, | ||
name: this.gqlName(member.literal, member.literal.text), | ||
description: undefined, | ||
loc: this.loc(member) | ||
}); | ||
values.push(this.gql.enumValueDefinition(node, this.gql.name(member.literal, member.literal.text), undefined, null)); | ||
} | ||
} | ||
catch (e_8_1) { e_8 = { error: e_8_1 }; } | ||
catch (e_9_1) { e_9 = { error: e_9_1 }; } | ||
finally { | ||
@@ -1081,3 +1023,3 @@ try { | ||
} | ||
finally { if (e_8) throw e_8.error; } | ||
finally { if (e_9) throw e_9.error; } | ||
} | ||
@@ -1087,3 +1029,3 @@ return values; | ||
Extractor.prototype.collectEnumValues = function (node) { | ||
var e_9, _a; | ||
var e_10, _a; | ||
var values = []; | ||
@@ -1095,3 +1037,3 @@ try { | ||
!ts.isStringLiteral(member.initializer)) { | ||
this.reportUnhandled(member, E.enumVariantMissingInitializer()); | ||
this.reportUnhandled(member, "enum value", E.enumVariantMissingInitializer()); | ||
continue; | ||
@@ -1101,12 +1043,6 @@ } | ||
var deprecated = this.collectDeprecated(member); | ||
values.push({ | ||
kind: graphql_1.Kind.ENUM_VALUE_DEFINITION, | ||
loc: this.loc(member), | ||
description: description || undefined, | ||
name: this.gqlName(member.initializer, member.initializer.text), | ||
directives: deprecated ? [deprecated] : undefined | ||
}); | ||
values.push(this.gql.enumValueDefinition(member, this.gql.name(member.initializer, member.initializer.text), deprecated ? [deprecated] : undefined, description)); | ||
} | ||
} | ||
catch (e_9_1) { e_9 = { error: e_9_1 }; } | ||
catch (e_10_1) { e_10 = { error: e_10_1 }; } | ||
finally { | ||
@@ -1116,3 +1052,3 @@ try { | ||
} | ||
finally { if (e_9) throw e_9.error; } | ||
finally { if (e_10) throw e_10.error; } | ||
} | ||
@@ -1126,3 +1062,3 @@ return values; | ||
// FIXME: Use the _value_'s location not the tag's | ||
return this.gqlName(tag, commentName); | ||
return this.gql.name(tag, commentName); | ||
} | ||
@@ -1136,3 +1072,3 @@ } | ||
return null; | ||
return this.gqlName(id, id.text); | ||
return this.gql.name(id, id.text); | ||
}; | ||
@@ -1164,3 +1100,3 @@ Extractor.prototype.methodDeclaration = function (node) { | ||
if (id.text !== name.value) { | ||
directives = [this.methodNameDirective(node.name, id.text)]; | ||
directives = [this.fieldNameDirective(node.name, id.text)]; | ||
} | ||
@@ -1171,11 +1107,3 @@ var deprecated = this.collectDeprecated(node); | ||
} | ||
return { | ||
kind: graphql_1.Kind.FIELD_DEFINITION, | ||
loc: this.loc(node), | ||
description: description || undefined, | ||
name: name, | ||
arguments: args || undefined, | ||
type: this.handleErrorBubbling(node, type), | ||
directives: directives.length === 0 ? undefined : directives | ||
}; | ||
return this.gql.fieldDefinition(node, name, this.handleErrorBubbling(node, type), args, directives, description); | ||
}; | ||
@@ -1217,8 +1145,3 @@ Extractor.prototype.collectMethodType = function (node) { | ||
if (description) { | ||
return { | ||
kind: graphql_1.Kind.STRING, | ||
loc: this.loc(node), | ||
value: description, | ||
block: true | ||
}; | ||
return this.gql.string(node, description, true); | ||
} | ||
@@ -1236,12 +1159,6 @@ return null; | ||
// FIXME: Use the _value_'s location not the tag's | ||
reason = this.gqlConstArgument(tag, this.gqlName(tag, "reason"), this.gqlString(tag, reasonComment)); | ||
reason = this.gql.constArgument(tag, this.gql.name(tag, "reason"), this.gql.string(tag, reasonComment)); | ||
} | ||
} | ||
var args = reason == null ? undefined : [reason]; | ||
return { | ||
kind: graphql_1.Kind.DIRECTIVE, | ||
loc: this.loc(tag.tagName), | ||
name: this.gqlName(tag.tagName, DEPRECATED_TAG), | ||
arguments: args | ||
}; | ||
return this.gql.constDirective(tag.tagName, this.gql.name(node, DEPRECATED_TAG), reason == null ? null : [reason]); | ||
}; | ||
@@ -1263,3 +1180,3 @@ Extractor.prototype.property = function (node) { | ||
return null; | ||
var type = node.questionToken == null ? inner : this.gqlNullableType(inner); | ||
var type = node.questionToken == null ? inner : this.gql.nullableType(inner); | ||
var description = this.collectDescription(node.name); | ||
@@ -1275,13 +1192,5 @@ var directives = []; | ||
if (id.text !== name.value) { | ||
directives = [this.methodNameDirective(node.name, id.text)]; | ||
directives = [this.fieldNameDirective(node.name, id.text)]; | ||
} | ||
return { | ||
kind: graphql_1.Kind.FIELD_DEFINITION, | ||
loc: this.loc(node), | ||
description: description || undefined, | ||
name: name, | ||
arguments: undefined, | ||
type: this.handleErrorBubbling(node, type), | ||
directives: directives.length === 0 ? undefined : directives | ||
}; | ||
return this.gql.fieldDefinition(node, name, this.handleErrorBubbling(node, type), null, directives, description); | ||
}; | ||
@@ -1302,3 +1211,3 @@ // TODO: Support separate modes for input and output types | ||
return null; | ||
return this.gqlNonNullType(node, this.gqlListType(node, element)); | ||
return this.gql.nonNullType(node, this.gql.listType(node, element)); | ||
} | ||
@@ -1323,5 +1232,5 @@ else if (ts.isUnionTypeNode(node)) { | ||
if (node.types.length > 1) { | ||
return this.gqlNullableType(type); | ||
return this.gql.nullableType(type); | ||
} | ||
return this.gqlNonNullType(node, type); | ||
return this.gql.nonNullType(node, type); | ||
} | ||
@@ -1332,6 +1241,6 @@ else if (ts.isParenthesizedTypeNode(node)) { | ||
else if (node.kind === ts.SyntaxKind.StringKeyword) { | ||
return this.gqlNonNullType(node, this.gqlNamedType(node, "String")); | ||
return this.gql.nonNullType(node, this.gql.namedType(node, "String")); | ||
} | ||
else if (node.kind === ts.SyntaxKind.BooleanKeyword) { | ||
return this.gqlNonNullType(node, this.gqlNamedType(node, "Boolean")); | ||
return this.gql.nonNullType(node, this.gql.namedType(node, "Boolean")); | ||
} | ||
@@ -1345,3 +1254,3 @@ else if (node.kind === ts.SyntaxKind.NumberKeyword) { | ||
// TODO: Better error message. This is okay if it's a type reference, but everything else is not. | ||
this.reportUnhandled(node, E.unknownGraphQLType()); | ||
this.reportUnhandled(node, "type", E.unknownGraphQLType()); | ||
return null; | ||
@@ -1364,3 +1273,3 @@ }; | ||
return null; | ||
return this.gqlNonNullType(node, this.gqlListType(node, element)); | ||
return this.gql.nonNullType(node, this.gql.listType(node, element)); | ||
} | ||
@@ -1372,5 +1281,5 @@ default: { | ||
// A later pass will resolve the type. | ||
var namedType = this.gqlNamedType(node, TypeContext_1.UNRESOLVED_REFERENCE_NAME); | ||
var namedType = this.gql.namedType(node, TypeContext_1.UNRESOLVED_REFERENCE_NAME); | ||
this.ctx.markUnresolvedType(node.typeName, namedType.name); | ||
return this.gqlNonNullType(node, namedType); | ||
return this.gql.nonNullType(node, namedType); | ||
} | ||
@@ -1433,55 +1342,20 @@ } | ||
if (this.configOptions.nullableByDefault) { | ||
return this.gqlNullableType(type); | ||
return this.gql.nullableType(type); | ||
} | ||
return type; | ||
}; | ||
Extractor.prototype.methodNameDirective = function (nameNode, name) { | ||
return this.gqlConstDirective(nameNode, this.gqlName(nameNode, serverDirectives_1.METHOD_NAME_DIRECTIVE), [ | ||
this.gqlConstArgument(nameNode, this.gqlName(nameNode, serverDirectives_1.METHOD_NAME_ARG), this.gqlString(nameNode, name)), | ||
/* Grats directives */ | ||
Extractor.prototype.exportDirective = function (nameNode, filename, functionName) { | ||
return this.gql.constDirective(nameNode, this.gql.name(nameNode, serverDirectives_1.EXPORTED_DIRECTIVE), [ | ||
this.gql.constArgument(nameNode, this.gql.name(nameNode, serverDirectives_1.EXPORTED_FILENAME_ARG), this.gql.string(nameNode, filename)), | ||
this.gql.constArgument(nameNode, this.gql.name(nameNode, serverDirectives_1.EXPORTED_FUNCTION_NAME_ARG), this.gql.string(nameNode, functionName)), | ||
]); | ||
}; | ||
Extractor.prototype.exportDirective = function (nameNode, filename, functionName) { | ||
return this.gqlConstDirective(nameNode, this.gqlName(nameNode, serverDirectives_1.EXPORTED_DIRECTIVE), [ | ||
this.gqlConstArgument(nameNode, this.gqlName(nameNode, serverDirectives_1.EXPORTED_FILENAME_ARG), this.gqlString(nameNode, filename)), | ||
this.gqlConstArgument(nameNode, this.gqlName(nameNode, serverDirectives_1.EXPORTED_FUNCTION_NAME_ARG), this.gqlString(nameNode, functionName)), | ||
Extractor.prototype.fieldNameDirective = function (nameNode, name) { | ||
return this.gql.constDirective(nameNode, this.gql.name(nameNode, serverDirectives_1.METHOD_NAME_DIRECTIVE), [ | ||
this.gql.constArgument(nameNode, this.gql.name(nameNode, serverDirectives_1.METHOD_NAME_ARG), this.gql.string(nameNode, name)), | ||
]); | ||
}; | ||
/** GraphQL AST node helper methods */ | ||
Extractor.prototype.gqlName = function (node, value) { | ||
return { kind: graphql_1.Kind.NAME, loc: this.loc(node), value: value }; | ||
}; | ||
Extractor.prototype.gqlNamedType = function (node, value) { | ||
return { | ||
kind: graphql_1.Kind.NAMED_TYPE, | ||
loc: this.loc(node), | ||
name: this.gqlName(node, value) | ||
}; | ||
}; | ||
Extractor.prototype.gqlNonNullType = function (node, type) { | ||
if (type.kind === graphql_1.Kind.NON_NULL_TYPE) { | ||
return type; | ||
} | ||
return { kind: graphql_1.Kind.NON_NULL_TYPE, loc: this.loc(node), type: type }; | ||
}; | ||
Extractor.prototype.gqlNullableType = function (type) { | ||
var inner = type; | ||
while (inner.kind === graphql_1.Kind.NON_NULL_TYPE) { | ||
inner = inner.type; | ||
} | ||
return inner; | ||
}; | ||
Extractor.prototype.gqlListType = function (node, type) { | ||
return { kind: graphql_1.Kind.LIST_TYPE, loc: this.loc(node), type: type }; | ||
}; | ||
Extractor.prototype.gqlConstArgument = function (node, name, value) { | ||
return { kind: graphql_1.Kind.ARGUMENT, loc: this.loc(node), name: name, value: value }; | ||
}; | ||
Extractor.prototype.gqlConstDirective = function (node, name, args) { | ||
return { kind: graphql_1.Kind.DIRECTIVE, loc: this.loc(node), name: name, arguments: args }; | ||
}; | ||
Extractor.prototype.gqlString = function (node, value) { | ||
return { kind: graphql_1.Kind.STRING, loc: this.loc(node), value: value }; | ||
}; | ||
return Extractor; | ||
}()); | ||
exports.Extractor = Extractor; |
@@ -140,3 +140,13 @@ "use strict"; | ||
} | ||
var docResult = ctx.resolveTypes({ kind: graphql_1.Kind.DOCUMENT, definitions: definitions }); | ||
// If you define a field on an interface using the functional style, we need to add | ||
// that field to each concrete type as well. This must be done after all types are created, | ||
// but before we validate the schema. | ||
var definitionsResult = ctx.handleAbstractDefinitions(definitions); | ||
if (definitionsResult.kind === "ERROR") { | ||
return definitionsResult; | ||
} | ||
var docResult = ctx.resolveTypes({ | ||
kind: graphql_1.Kind.DOCUMENT, | ||
definitions: definitionsResult.value | ||
}); | ||
if (docResult.kind === "ERROR") | ||
@@ -143,0 +153,0 @@ return docResult; |
@@ -54,2 +54,3 @@ "use strict"; | ||
var gratsRoot_1 = require("./gratsRoot"); | ||
// TODO: Rename to be generic since it can apply to properties as well as methods. | ||
exports.METHOD_NAME_DIRECTIVE = "methodName"; | ||
@@ -56,0 +57,0 @@ exports.METHOD_NAME_ARG = "name"; |
@@ -65,4 +65,7 @@ "use strict"; | ||
var utils_1 = require("@graphql-tools/utils"); | ||
var ts = require("typescript"); | ||
var graphql_1 = require("graphql"); | ||
var commander_1 = require("commander"); | ||
var Locate_1 = require("../Locate"); | ||
var DiagnosticError_1 = require("../utils/DiagnosticError"); | ||
var program = new commander_1.Command(); | ||
@@ -72,3 +75,3 @@ program | ||
.description("Run Grats' internal tests") | ||
.option("-w, --write", "Write the actual ouput of the test to the expected output files. Useful for updating tests.") | ||
.option("-w, --write", "Write the actual output of the test to the expected output files. Useful for updating tests.") | ||
.option("-f, --filter <FILTER_REGEX>", "A regex to filter the tests to run. Only tests with a file path matching the regex will be run.") | ||
@@ -145,9 +148,26 @@ .action(function (_a) { | ||
}; | ||
var schemaResult = (0, lib_1.buildSchemaResult)(parsedOptions); | ||
// https://stackoverflow.com/a/66604532/1263117 | ||
var compilerHost = ts.createCompilerHost(parsedOptions.options, | ||
/* setParentNodes this is needed for finding jsDocs */ | ||
true); | ||
var schemaResult = (0, lib_1.buildSchemaResultWithHost)(parsedOptions, compilerHost); | ||
if (schemaResult.kind === "ERROR") { | ||
return schemaResult.err.formatDiagnosticsWithContext(); | ||
} | ||
return (0, utils_1.printSchemaWithDirectives)(schemaResult.value, { | ||
assumeValid: true | ||
}); | ||
var LOCATION_REGEX = /^\/\/ Locate: (.*)/; | ||
var locationMatch = code.match(LOCATION_REGEX); | ||
if (locationMatch != null) { | ||
var locResult = (0, Locate_1.locate)(schemaResult.value, locationMatch[1].trim()); | ||
if (locResult.kind === "ERROR") { | ||
return locResult.err; | ||
} | ||
return new DiagnosticError_1.ReportableDiagnostics(compilerHost, [ | ||
(0, DiagnosticError_1.diagnosticAtGraphQLLocation)("Located here", locResult.value), | ||
]).formatDiagnosticsWithContext(); | ||
} | ||
else { | ||
return (0, utils_1.printSchemaWithDirectives)(schemaResult.value, { | ||
assumeValid: true | ||
}); | ||
} | ||
} | ||
@@ -154,0 +174,0 @@ }, |
@@ -1,5 +0,17 @@ | ||
import { DocumentNode, NameNode } from "graphql"; | ||
import { DefinitionNode, DocumentNode, FieldDefinitionNode, Location, NameNode } from "graphql"; | ||
import * as ts from "typescript"; | ||
import { DiagnosticResult, DiagnosticsResult } from "./utils/DiagnosticError"; | ||
import { InterfaceMap } from "./InterfaceGraph"; | ||
export declare const UNRESOLVED_REFERENCE_NAME = "__UNRESOLVED_REFERENCE__"; | ||
type NameDefinition = { | ||
name: NameNode; | ||
kind: "TYPE" | "INTERFACE" | "UNION" | "SCALAR" | "INPUT_OBJECT" | "ENUM"; | ||
}; | ||
export type GratsDefinitionNode = DefinitionNode | AbstractFieldDefinitionNode; | ||
export type AbstractFieldDefinitionNode = { | ||
readonly kind: "AbstractFieldDefinition"; | ||
readonly loc: Location; | ||
readonly onType: NameNode; | ||
readonly field: FieldDefinitionNode; | ||
}; | ||
/** | ||
@@ -21,13 +33,19 @@ * Used to track TypeScript references. | ||
_options: ts.ParsedCommandLine; | ||
_symbolToName: Map<ts.Symbol, string>; | ||
_symbolToName: Map<ts.Symbol, NameDefinition>; | ||
_unresolvedTypes: Map<NameNode, ts.Symbol>; | ||
hasTypename: Set<string>; | ||
constructor(options: ts.ParsedCommandLine, checker: ts.TypeChecker, host: ts.CompilerHost); | ||
recordTypeName(node: ts.Node, name: string): void; | ||
recordTypeName(node: ts.Node, name: NameNode, kind: NameDefinition["kind"]): void; | ||
recordHasTypenameField(name: string): void; | ||
markUnresolvedType(node: ts.Node, name: NameNode): void; | ||
resolveTypes(doc: DocumentNode): DiagnosticsResult<DocumentNode>; | ||
handleAbstractDefinitions(docs: GratsDefinitionNode[]): DiagnosticsResult<DefinitionNode[]>; | ||
addAbstractFieldDefinition(doc: AbstractFieldDefinitionNode, interfaceGraph: InterfaceMap): DiagnosticsResult<DefinitionNode[]>; | ||
resolveNamedDefinition(unresolved: NameNode): DiagnosticResult<NameNode>; | ||
resolveNamedType(unresolved: NameNode): DiagnosticResult<NameNode>; | ||
err(loc: Location, message: string, relatedInformation?: ts.DiagnosticRelatedInformation[]): ts.Diagnostic; | ||
relatedInformation(loc: Location, message: string): ts.DiagnosticRelatedInformation; | ||
validateInterfaceImplementorsHaveTypenameField(): DiagnosticResult<null>; | ||
getDestFilePath(sourceFile: ts.SourceFile): string; | ||
} | ||
export {}; |
@@ -13,2 +13,13 @@ "use strict"; | ||
}; | ||
var __values = (this && this.__values) || function(o) { | ||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
if (m) return m.call(o); | ||
if (o && typeof o.length === "number") return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
}; | ||
exports.__esModule = true; | ||
@@ -20,2 +31,7 @@ exports.TypeContext = exports.UNRESOLVED_REFERENCE_NAME = void 0; | ||
var gratsRoot_1 = require("./gratsRoot"); | ||
var serverDirectives_1 = require("./serverDirectives"); | ||
var Extractor_1 = require("./Extractor"); | ||
var E = require("./Errors"); | ||
var InterfaceGraph_1 = require("./InterfaceGraph"); | ||
var helpers_1 = require("./utils/helpers"); | ||
exports.UNRESOLVED_REFERENCE_NAME = "__UNRESOLVED_REFERENCE__"; | ||
@@ -43,3 +59,3 @@ /** | ||
} | ||
TypeContext.prototype.recordTypeName = function (node, name) { | ||
TypeContext.prototype.recordTypeName = function (node, name, kind) { | ||
var symbol = this.checker.getSymbolAtLocation(node); | ||
@@ -54,3 +70,3 @@ if (symbol == null) { | ||
} | ||
this._symbolToName.set(symbol, name); | ||
this._symbolToName.set(symbol, { name: name, kind: kind }); | ||
}; | ||
@@ -73,6 +89,7 @@ TypeContext.prototype.recordHasTypenameField = function (name) { | ||
TypeContext.prototype.resolveTypes = function (doc) { | ||
var _a; | ||
var _this = this; | ||
var errors = []; | ||
var newDoc = (0, graphql_1.visit)(doc, { | ||
Name: function (t) { | ||
var newDoc = (0, graphql_1.visit)(doc, (_a = {}, | ||
_a[graphql_1.Kind.NAME] = function (t) { | ||
var namedTypeResult = _this.resolveNamedType(t); | ||
@@ -84,4 +101,4 @@ if (namedTypeResult.kind === "ERROR") { | ||
return namedTypeResult.value; | ||
} | ||
}); | ||
}, | ||
_a)); | ||
if (errors.length > 0) { | ||
@@ -92,2 +109,157 @@ return (0, DiagnosticError_1.err)(errors); | ||
}; | ||
TypeContext.prototype.handleAbstractDefinitions = function (docs) { | ||
var e_1, _a; | ||
var newDocs = []; | ||
var errors = []; | ||
var interfaceGraphResult = (0, InterfaceGraph_1.computeInterfaceMap)(this, docs); | ||
if (interfaceGraphResult.kind === "ERROR") { | ||
return interfaceGraphResult; | ||
} | ||
var interfaceGraph = interfaceGraphResult.value; | ||
try { | ||
for (var docs_1 = __values(docs), docs_1_1 = docs_1.next(); !docs_1_1.done; docs_1_1 = docs_1.next()) { | ||
var doc = docs_1_1.value; | ||
if (doc.kind === "AbstractFieldDefinition") { | ||
var abstractDocResults = this.addAbstractFieldDefinition(doc, interfaceGraph); | ||
if (abstractDocResults.kind === "ERROR") { | ||
(0, helpers_1.extend)(errors, abstractDocResults.err); | ||
} | ||
else { | ||
(0, helpers_1.extend)(newDocs, abstractDocResults.value); | ||
} | ||
} | ||
else { | ||
newDocs.push(doc); | ||
} | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (docs_1_1 && !docs_1_1.done && (_a = docs_1["return"])) _a.call(docs_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
if (errors.length > 0) { | ||
return (0, DiagnosticError_1.err)(errors); | ||
} | ||
return (0, DiagnosticError_1.ok)(newDocs); | ||
}; | ||
// A field definition may be on a concrete type, or on an interface. If it's on an interface, | ||
// we need to add it to each concrete type that implements the interface. | ||
TypeContext.prototype.addAbstractFieldDefinition = function (doc, interfaceGraph) { | ||
var e_2, _a; | ||
var _b; | ||
var newDocs = []; | ||
var typeNameResult = this.resolveNamedType(doc.onType); | ||
if (typeNameResult.kind === "ERROR") { | ||
return (0, DiagnosticError_1.err)([typeNameResult.err]); | ||
} | ||
var symbol = this._unresolvedTypes.get(doc.onType); | ||
if (symbol == null) { | ||
// This should have already been handled by resolveNamedType | ||
throw new Error("Expected to find unresolved type."); | ||
} | ||
var nameDefinition = this._symbolToName.get(symbol); | ||
if (nameDefinition == null) { | ||
// This should have already been handled by resolveNamedType | ||
throw new Error("Expected to find name definition."); | ||
} | ||
switch (nameDefinition.kind) { | ||
case "TYPE": | ||
// Extending a type, is just adding a field to it. | ||
newDocs.push({ | ||
kind: graphql_1.Kind.OBJECT_TYPE_EXTENSION, | ||
name: doc.onType, | ||
fields: [doc.field], | ||
loc: doc.loc | ||
}); | ||
break; | ||
case "INTERFACE": { | ||
// Extending an interface is a bit more complicated. We need to add the field | ||
// to the interface, and to each type that implements the interface. | ||
// The interface field definition is not executable, so we don't | ||
// need to annotate it with the details of the implementation. | ||
var directives = (_b = doc.field.directives) === null || _b === void 0 ? void 0 : _b.filter(function (directive) { | ||
return directive.name.value !== serverDirectives_1.EXPORTED_DIRECTIVE; | ||
}); | ||
newDocs.push({ | ||
kind: graphql_1.Kind.INTERFACE_TYPE_EXTENSION, | ||
name: doc.onType, | ||
fields: [__assign(__assign({}, doc.field), { directives: directives })] | ||
}); | ||
try { | ||
for (var _c = __values(interfaceGraph.get(nameDefinition.name.value)), _d = _c.next(); !_d.done; _d = _c.next()) { | ||
var implementor = _d.value; | ||
var name = { | ||
kind: graphql_1.Kind.NAME, | ||
value: implementor.name, | ||
loc: doc.loc | ||
}; | ||
switch (implementor.kind) { | ||
case "TYPE": | ||
newDocs.push({ | ||
kind: graphql_1.Kind.OBJECT_TYPE_EXTENSION, | ||
name: name, | ||
fields: [doc.field], | ||
loc: doc.loc | ||
}); | ||
break; | ||
case "INTERFACE": | ||
newDocs.push({ | ||
kind: graphql_1.Kind.INTERFACE_TYPE_EXTENSION, | ||
name: name, | ||
fields: [__assign(__assign({}, doc.field), { directives: directives })], | ||
loc: doc.loc | ||
}); | ||
break; | ||
} | ||
} | ||
} | ||
catch (e_2_1) { e_2 = { error: e_2_1 }; } | ||
finally { | ||
try { | ||
if (_d && !_d.done && (_a = _c["return"])) _a.call(_c); | ||
} | ||
finally { if (e_2) throw e_2.error; } | ||
} | ||
break; | ||
} | ||
default: { | ||
// Extending any other type of definition is not supported. | ||
var loc = doc.onType.loc; | ||
if (loc == null) { | ||
throw new Error("Expected onType to have a location."); | ||
} | ||
var relatedLoc = nameDefinition.name.loc; | ||
if (relatedLoc == null) { | ||
throw new Error("Expected nameDefinition to have a location."); | ||
} | ||
return (0, DiagnosticError_1.err)([ | ||
this.err(loc, E.invalidTypePassedToFieldFunction(), [ | ||
this.relatedInformation(relatedLoc, "This is the type that was passed to `@".concat(Extractor_1.FIELD_TAG, "`.")), | ||
]), | ||
]); | ||
} | ||
} | ||
return (0, DiagnosticError_1.ok)(newDocs); | ||
}; | ||
TypeContext.prototype.resolveNamedDefinition = function (unresolved) { | ||
var symbol = this._unresolvedTypes.get(unresolved); | ||
if (symbol == null) { | ||
if (unresolved.value === exports.UNRESOLVED_REFERENCE_NAME) { | ||
// This is a logic error on our side. | ||
throw new Error("Unexpected unresolved reference name."); | ||
} | ||
return (0, DiagnosticError_1.ok)(unresolved); | ||
} | ||
var nameDefinition = this._symbolToName.get(symbol); | ||
if (nameDefinition == null) { | ||
if (unresolved.loc == null) { | ||
throw new Error("Expected namedType to have a location."); | ||
} | ||
return (0, DiagnosticError_1.err)(this.err(unresolved.loc, E.unresolvedTypeReference())); | ||
} | ||
return (0, DiagnosticError_1.ok)(__assign(__assign({}, unresolved), { value: nameDefinition.name.value })); | ||
}; | ||
TypeContext.prototype.resolveNamedType = function (unresolved) { | ||
@@ -102,18 +274,32 @@ var symbol = this._unresolvedTypes.get(unresolved); | ||
} | ||
var name = this._symbolToName.get(symbol); | ||
if (name == null) { | ||
var nameDefinition = this._symbolToName.get(symbol); | ||
if (nameDefinition == null) { | ||
if (unresolved.loc == null) { | ||
throw new Error("Expected namedType to have a location."); | ||
} | ||
return (0, DiagnosticError_1.err)({ | ||
messageText: "This type is not a valid GraphQL type. Did you mean to annotate it's definition with a `/** @gql */` tag such as `/** @gqlType */` or `/** @gqlInput **/`?", | ||
start: unresolved.loc.start, | ||
length: unresolved.loc.end - unresolved.loc.start, | ||
category: ts.DiagnosticCategory.Error, | ||
code: DiagnosticError_1.FAKE_ERROR_CODE, | ||
file: ts.createSourceFile(unresolved.loc.source.name, unresolved.loc.source.body, ts.ScriptTarget.Latest) | ||
}); | ||
return (0, DiagnosticError_1.err)(this.err(unresolved.loc, E.unresolvedTypeReference())); | ||
} | ||
return (0, DiagnosticError_1.ok)(__assign(__assign({}, unresolved), { value: name })); | ||
return (0, DiagnosticError_1.ok)(__assign(__assign({}, unresolved), { value: nameDefinition.name.value })); | ||
}; | ||
TypeContext.prototype.err = function (loc, message, relatedInformation) { | ||
return { | ||
messageText: message, | ||
start: loc.start, | ||
length: loc.end - loc.start, | ||
category: ts.DiagnosticCategory.Error, | ||
code: DiagnosticError_1.FAKE_ERROR_CODE, | ||
file: ts.createSourceFile(loc.source.name, loc.source.body, ts.ScriptTarget.Latest), | ||
relatedInformation: relatedInformation | ||
}; | ||
}; | ||
TypeContext.prototype.relatedInformation = function (loc, message) { | ||
return { | ||
category: ts.DiagnosticCategory.Message, | ||
code: DiagnosticError_1.FAKE_ERROR_CODE, | ||
messageText: message, | ||
file: ts.createSourceFile(loc.source.name, loc.source.body, ts.ScriptTarget.Latest), | ||
start: loc.start, | ||
length: loc.end - loc.start | ||
}; | ||
}; | ||
TypeContext.prototype.validateInterfaceImplementorsHaveTypenameField = function () { | ||
@@ -120,0 +306,0 @@ return (0, DiagnosticError_1.ok)(null); |
export declare function concatMaybeArrays<T>(a: T[] | null, b: T[] | null): T[] | null; | ||
export declare class DefaultMap<K, V> { | ||
private readonly getDefault; | ||
_map: Map<K, V>; | ||
constructor(getDefault: () => V); | ||
get(key: K): V; | ||
} | ||
export declare function extend<T>(a: T[], b: T[]): void; |
"use strict"; | ||
var __values = (this && this.__values) || function(o) { | ||
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; | ||
if (m) return m.call(o); | ||
if (o && typeof o.length === "number") return { | ||
next: function () { | ||
if (o && i >= o.length) o = void 0; | ||
return { value: o && o[i++], done: !o }; | ||
} | ||
}; | ||
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); | ||
}; | ||
exports.__esModule = true; | ||
exports.concatMaybeArrays = void 0; | ||
exports.extend = exports.DefaultMap = exports.concatMaybeArrays = void 0; | ||
// Returns null if both are null, otherwise returns the concatenated values of | ||
@@ -14,1 +25,34 @@ // the non-null arrays. | ||
exports.concatMaybeArrays = concatMaybeArrays; | ||
var DefaultMap = /** @class */ (function () { | ||
function DefaultMap(getDefault) { | ||
this.getDefault = getDefault; | ||
this._map = new Map(); | ||
} | ||
DefaultMap.prototype.get = function (key) { | ||
if (!this._map.has(key)) { | ||
this._map.set(key, this.getDefault()); | ||
} | ||
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion | ||
return this._map.get(key); | ||
}; | ||
return DefaultMap; | ||
}()); | ||
exports.DefaultMap = DefaultMap; | ||
// Similar to a.push(...b), but avoids potential stack overflows. | ||
function extend(a, b) { | ||
var e_1, _a; | ||
try { | ||
for (var b_1 = __values(b), b_1_1 = b_1.next(); !b_1_1.done; b_1_1 = b_1.next()) { | ||
var item = b_1_1.value; | ||
a.push(item); | ||
} | ||
} | ||
catch (e_1_1) { e_1 = { error: e_1_1 }; } | ||
finally { | ||
try { | ||
if (b_1_1 && !b_1_1.done && (_a = b_1["return"])) _a.call(b_1); | ||
} | ||
finally { if (e_1) throw e_1.error; } | ||
} | ||
} | ||
exports.extend = extend; |
{ | ||
"name": "grats", | ||
"version": "0.0.0-main-99a0ac85", | ||
"version": "0.0.0-main-9fae3b01", | ||
"main": "dist/src/index.js", | ||
@@ -5,0 +5,0 @@ "bin": "dist/src/cli.js", |
201488
47
4189