New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

grats

Package Overview
Dependencies
Maintainers
1
Versions
240
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

grats - npm Package Compare versions

Comparing version 0.0.16 to 0.0.17

dist/src/comments.d.ts

2

dist/package.json
{
"name": "grats",
"version": "0.0.15",
"version": "0.0.16",
"main": "dist/src/index.js",

@@ -5,0 +5,0 @@ "bin": "dist/src/cli.js",

@@ -186,10 +186,11 @@ "use strict";

if (propertyName != null) {
var name = (0, metadataDirectives_1.parsePropertyNameDirective)(propertyName).name;
var _a = (0, metadataDirectives_1.parsePropertyNameDirective)(propertyName), name = _a.name, isMethod = _a.isMethod;
var prop = F.createPropertyAccessExpression(F.createIdentifier("source"), F.createIdentifier(name));
var callExpression = F.createCallExpression(prop, undefined, RESOLVER_ARGS.map(function (name) {
return F.createIdentifier(name);
}));
var isFunc = F.createStrictEquality(F.createTypeOfExpression(prop), F.createStringLiteral("function"));
var ternary = F.createConditionalExpression(isFunc, undefined, callExpression, undefined, prop);
return this.method(methodName, RESOLVER_ARGS.map(function (name) { return _this.param(name); }), [F.createReturnStatement(ternary)]);
var valueExpression = prop;
if (isMethod) {
valueExpression = F.createCallExpression(prop, undefined, RESOLVER_ARGS.map(function (name) {
return F.createIdentifier(name);
}));
}
return this.method(methodName, RESOLVER_ARGS.map(function (name) { return _this.param(name); }), [F.createReturnStatement(valueExpression)]);
}

@@ -196,0 +197,0 @@ return null;

@@ -93,1 +93,4 @@ export declare const ISSUE_URL = "https://github.com/captbaritone/grats/issues";

export declare function expectedNullableArgumentToBeOptional(): string;
export declare function gqlTagInLineComment(): string;
export declare function gqlTagInNonJSDocBlockComment(): string;
export declare function gqlTagInDetachedJSDocBlockComment(): string;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultArgElementIsNotAssignment = exports.defaultValueIsNotLiteral = exports.ambiguousNumberType = exports.expectedOneNonNullishType = exports.propertyFieldMissingType = exports.cannotResolveSymbolForDescription = exports.wrapperMissingTypeArg = 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.typeTagOnAliasOfNonObjectOrUnknown = exports.typeTagOnUnnamedClass = 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.fieldTagOnWrongNode = exports.ISSUE_URL = void 0;
exports.expectedNullableArgumentToBeOptional = exports.operationTypeNotUnknown = exports.nonSubscriptionFieldAsyncIterable = exports.subscriptionFieldNotAsyncIterable = exports.graphQLTagNameHasWhitespace = exports.graphQLNameHasLeadingNewlines = exports.multipleContextTypes = exports.unexpectedParamSpreadForContextParam = exports.expectedTypeAnnotationOnContextToHaveDeclaration = exports.expectedTypeAnnotationOnContextToBeResolvable = exports.expectedTypeAnnotationOfReferenceOnContext = exports.expectedTypeAnnotationOnContext = exports.unresolvedTypeReference = exports.invalidTypePassedToFieldFunction = exports.parameterPropertyMissingType = exports.parameterPropertyNotPublic = exports.parameterWithoutModifiers = exports.duplicateInterfaceTag = exports.duplicateTag = exports.implementsTagOnTypeAlias = exports.implementsTagOnInterface = exports.implementsTagOnClass = exports.mergedInterfaces = exports.nonNullTypeCannotBeOptional = exports.killsParentOnExceptionOnNullable = exports.killsParentOnExceptionWithWrongConfig = exports.expectedNameIdentifier = exports.pluralTypeMissingParameter = exports.unknownGraphQLType = exports.unsupportedTypeLiteral = exports.defaultArgPropertyMissingInitializer = exports.defaultArgPropertyMissingName = void 0;
exports.gqlTagInDetachedJSDocBlockComment = exports.gqlTagInNonJSDocBlockComment = exports.gqlTagInLineComment = exports.expectedNullableArgumentToBeOptional = exports.operationTypeNotUnknown = exports.nonSubscriptionFieldAsyncIterable = exports.subscriptionFieldNotAsyncIterable = exports.graphQLTagNameHasWhitespace = exports.graphQLNameHasLeadingNewlines = exports.multipleContextTypes = exports.unexpectedParamSpreadForContextParam = exports.expectedTypeAnnotationOnContextToHaveDeclaration = exports.expectedTypeAnnotationOnContextToBeResolvable = exports.expectedTypeAnnotationOfReferenceOnContext = exports.expectedTypeAnnotationOnContext = exports.unresolvedTypeReference = exports.invalidTypePassedToFieldFunction = exports.parameterPropertyMissingType = exports.parameterPropertyNotPublic = exports.parameterWithoutModifiers = exports.duplicateInterfaceTag = exports.duplicateTag = exports.implementsTagOnTypeAlias = exports.implementsTagOnInterface = exports.implementsTagOnClass = exports.mergedInterfaces = exports.nonNullTypeCannotBeOptional = exports.killsParentOnExceptionOnNullable = exports.killsParentOnExceptionWithWrongConfig = exports.expectedNameIdentifier = exports.pluralTypeMissingParameter = exports.unknownGraphQLType = exports.unsupportedTypeLiteral = exports.defaultArgPropertyMissingInitializer = exports.defaultArgPropertyMissingName = void 0;
var Extractor_1 = require("./Extractor");

@@ -11,2 +11,3 @@ exports.ISSUE_URL = "https://github.com/captbaritone/grats/issues";

parameterProperties: "https://grats.capt.dev/docs/docblock-tags/fields#class-based-fields",
commentSyntax: "https://grats.capt.dev/docs/getting-started/comment-syntax",
};

@@ -364,1 +365,13 @@ /**

exports.expectedNullableArgumentToBeOptional = expectedNullableArgumentToBeOptional;
function gqlTagInLineComment() {
return "Unexpected Grats tag in line (`//`) comment. Grats looks for tags in JSDoc-style block comments. e.g. `/** @gqlType */`. For more information see: ".concat(DOC_URLS.commentSyntax);
}
exports.gqlTagInLineComment = gqlTagInLineComment;
function gqlTagInNonJSDocBlockComment() {
return "Unexpected Grats tag in non-JSDoc-style block comment. Grats only looks for tags in JSDoc-style block comments which start with `/**`. For more information see: ".concat(DOC_URLS.commentSyntax);
}
exports.gqlTagInNonJSDocBlockComment = gqlTagInNonJSDocBlockComment;
function gqlTagInDetachedJSDocBlockComment() {
return "Unexpected Grats tag in detached docblock. Grats was unable to determine which TypeScript declaration this docblock is associated with. Moving the docblock to a position with is unambiguously \"above\" the relevant declaration may help. For more information see: ".concat(DOC_URLS.commentSyntax);
}
exports.gqlTagInDetachedJSDocBlockComment = gqlTagInDetachedJSDocBlockComment;

@@ -41,2 +41,4 @@ "use strict";

var Errors_1 = require("./Errors");
var comments_1 = require("./comments");
var helpers_1 = require("./utils/helpers");
exports.LIBRARY_IMPORT_NAME = "grats";

@@ -104,4 +106,6 @@ exports.LIBRARY_NAME = "Grats";

var _this = this;
var seenCommentPositions = new Set();
(0, JSDoc_1.traverseJSDocTags)(sourceFile, function (node, tag) {
var e_1, _a;
seenCommentPositions.add(tag.parent.pos);
switch (tag.tagName.text) {

@@ -148,2 +152,3 @@ case exports.TYPE_TAG:

}
// TODO: Report invalid location as well
break;

@@ -177,2 +182,4 @@ }

});
var errors = (0, comments_1.detectInvalidComments)(sourceFile, seenCommentPositions);
(0, helpers_1.extend)(this.errors, errors);
if (this.errors.length > 0) {

@@ -234,2 +241,3 @@ return (0, Result_1.err)(this.errors);

this.inputTypeAliasDeclaration(node, tag);
// TODO: Could we support interfaces?
}

@@ -471,3 +479,3 @@ else {

var interfaces = this.collectInterfaces(node);
this.recordTypeName(node.name, name, "INTERFACE");
this.recordTypeName(node.name, name, "TYPE");
this.checkForTypenameProperty(node, name.value);

@@ -711,3 +719,6 @@ this.definitions.push(this.gql.objectTypeDefinition(node, name, fields, interfaces, description));

directives = [
this.gql.propertyNameDirective(node.name, { name: id.text }),
this.gql.propertyNameDirective(node.name, {
name: id.text,
isMethod: false,
}),
];

@@ -1107,3 +1118,6 @@ }

directives = [
this.gql.propertyNameDirective(node.name, { name: id.text }),
this.gql.propertyNameDirective(node.name, {
name: id.text,
isMethod: isCallable(node),
}),
];

@@ -1223,3 +1237,6 @@ }

directives = [
this.gql.propertyNameDirective(node.name, { name: id.text }),
this.gql.propertyNameDirective(node.name, {
name: id.text,
isMethod: false,
}),
];

@@ -1379,1 +1396,4 @@ }

}
function isCallable(node) {
return ts.isMethodDeclaration(node) || ts.isMethodSignature(node);
}

@@ -13,2 +13,3 @@ import { ConstDirectiveNode, DocumentNode, Location } from "graphql";

name: string;
isMethod: boolean;
};

@@ -15,0 +16,0 @@ export type ExportedMetadata = {

@@ -32,2 +32,3 @@ "use strict";

var FIELD_NAME_ARG = "name";
var IS_METHOD_ARG = "isMethod";
exports.EXPORTED_DIRECTIVE = "exported";

@@ -45,3 +46,3 @@ var TS_MODULE_PATH_ARG = "tsModulePath";

]);
exports.DIRECTIVES_AST = (0, graphql_1.parse)("\n directive @".concat(exports.ASYNC_ITERABLE_TYPE_DIRECTIVE, " on FIELD_DEFINITION\n directive @").concat(exports.FIELD_NAME_DIRECTIVE, "(").concat(FIELD_NAME_ARG, ": String!) on FIELD_DEFINITION\n directive @").concat(exports.EXPORTED_DIRECTIVE, "(\n ").concat(TS_MODULE_PATH_ARG, ": String!,\n ").concat(EXPORTED_FUNCTION_NAME_ARG, ": String!\n ").concat(ARG_COUNT, ": Int!\n ) on FIELD_DEFINITION\n directive @").concat(exports.KILLS_PARENT_ON_EXCEPTION_DIRECTIVE, " on FIELD_DEFINITION\n"));
exports.DIRECTIVES_AST = (0, graphql_1.parse)("\n directive @".concat(exports.ASYNC_ITERABLE_TYPE_DIRECTIVE, " on FIELD_DEFINITION\n directive @").concat(exports.FIELD_NAME_DIRECTIVE, "(").concat(FIELD_NAME_ARG, ": String!, ").concat(IS_METHOD_ARG, ": Boolean!) on FIELD_DEFINITION\n directive @").concat(exports.EXPORTED_DIRECTIVE, "(\n ").concat(TS_MODULE_PATH_ARG, ": String!,\n ").concat(EXPORTED_FUNCTION_NAME_ARG, ": String!\n ").concat(ARG_COUNT, ": Int!\n ) on FIELD_DEFINITION\n directive @").concat(exports.KILLS_PARENT_ON_EXCEPTION_DIRECTIVE, " on FIELD_DEFINITION\n"));
function addMetadataDirectives(definitions) {

@@ -56,3 +57,6 @@ return __spreadArray(__spreadArray([], __read(exports.DIRECTIVES_AST.definitions), false), __read(definitions), false);

name: { kind: graphql_1.Kind.NAME, loc: loc, value: exports.FIELD_NAME_DIRECTIVE },
arguments: [makeStringArg(loc, FIELD_NAME_ARG, propertyName.name)],
arguments: [
makeStringArg(loc, FIELD_NAME_ARG, propertyName.name),
makeBoolArg(loc, IS_METHOD_ARG, propertyName.isMethod),
],
};

@@ -103,3 +107,6 @@ }

}
return { name: getStringArg(directive, FIELD_NAME_ARG) };
return {
name: getStringArg(directive, FIELD_NAME_ARG),
isMethod: getBoolArg(directive, IS_METHOD_ARG),
};
}

@@ -140,2 +147,13 @@ exports.parsePropertyNameDirective = parsePropertyNameDirective;

}
function getBoolArg(directive, argName) {
var _a;
var arg = (_a = directive.arguments) === null || _a === void 0 ? void 0 : _a.find(function (arg) { return arg.name.value === argName; });
if (!arg) {
throw new Error("Expected to find argument ".concat(argName));
}
if (arg.value.kind !== graphql_1.Kind.BOOLEAN) {
throw new Error("Expected argument ".concat(argName, " to be a boolean"));
}
return arg.value.value;
}
function makeStringArg(loc, argName, value) {

@@ -149,2 +167,10 @@ return {

}
function makeBoolArg(loc, argName, value) {
return {
kind: graphql_1.Kind.ARGUMENT,
loc: loc,
name: { kind: graphql_1.Kind.NAME, loc: loc, value: argName },
value: { kind: graphql_1.Kind.BOOLEAN, loc: loc, value: value },
};
}
function makeIntArg(loc, argName, value) {

@@ -151,0 +177,0 @@ return {

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

// Set the location of the NON_NULL_TYPE wrapper to the location of the
// @killsParentOnException directive so that type errors created by graphql-js
// `@killsParentOnException` directive so that type errors created by graphql-js
// are reported at the correct location.

@@ -74,0 +74,0 @@ return __assign(__assign({}, t), { type: __assign(__assign({}, t.type), { loc: killsParent.loc }) });

@@ -9,2 +9,3 @@ "use strict";

var helpers_1 = require("../utils/helpers");
var TAG_REGEX = /@(gql)|(killsParentOnException)/i;
// Given a ts.Program, extract a set of ExtractionSnapshots from it.

@@ -17,3 +18,3 @@ // In the future this part might be able to be incremental, were we only run extraction

// If the file doesn't contain any GraphQL definitions, skip it.
if (!/@gql/i.test(sourceFile.text)) {
if (!TAG_REGEX.test(sourceFile.text)) {
return false;

@@ -20,0 +21,0 @@ }

@@ -19,4 +19,5 @@ import { GraphQLError, Location, Source } from "graphql";

export declare function gqlRelated(loc: Location, message: string): ts.DiagnosticRelatedInformation;
export declare function rangeErr(file: ts.SourceFile, commentRange: ts.CommentRange, message: string, relatedInformation?: ts.DiagnosticRelatedInformation[]): ts.DiagnosticWithLocation;
export declare function tsErr(node: ts.Node, message: string, relatedInformation?: ts.DiagnosticRelatedInformation[]): ts.DiagnosticWithLocation;
export declare function tsRelated(node: ts.Node, message: string): ts.DiagnosticRelatedInformation;
export declare function graphqlSourceToSourceFile(source: Source): ts.SourceFile;

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

Object.defineProperty(exports, "__esModule", { value: true });
exports.graphqlSourceToSourceFile = exports.tsRelated = exports.tsErr = exports.gqlRelated = exports.gqlErr = exports.graphQlErrorToDiagnostic = exports.FAKE_ERROR_CODE = exports.ReportableDiagnostics = void 0;
exports.graphqlSourceToSourceFile = exports.tsRelated = exports.tsErr = exports.rangeErr = exports.gqlRelated = exports.gqlErr = exports.graphQlErrorToDiagnostic = exports.FAKE_ERROR_CODE = exports.ReportableDiagnostics = void 0;
var ts = require("typescript");

@@ -149,2 +149,17 @@ var ReportableDiagnostics = /** @class */ (function () {

exports.gqlRelated = gqlRelated;
function rangeErr(file, commentRange, message, relatedInformation) {
var start = commentRange.pos;
var length = commentRange.end - commentRange.pos;
return {
messageText: message,
file: file,
code: exports.FAKE_ERROR_CODE,
category: ts.DiagnosticCategory.Error,
start: start,
length: length,
relatedInformation: relatedInformation,
source: "Grats",
};
}
exports.rangeErr = rangeErr;
function tsErr(node, message, relatedInformation) {

@@ -151,0 +166,0 @@ var start = node.getStart();

{
"name": "grats",
"version": "0.0.16",
"version": "0.0.17",
"main": "dist/src/index.js",

@@ -5,0 +5,0 @@ "bin": "dist/src/cli.js",

SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc