@graphitation/supermassive
Advanced tools
Comparing version 1.1.0 to 1.1.1
# Change Log - @graphitation/supermassive | ||
This log was last generated on Fri, 30 Sep 2022 08:56:05 GMT and should not be manually modified. | ||
This log was last generated on Wed, 05 Oct 2022 16:48:37 GMT and should not be manually modified. | ||
<!-- Start content --> | ||
## 1.1.1 | ||
Wed, 05 Oct 2022 16:48:37 GMT | ||
### Patches | ||
- Hotfix: typescript codegen fixes (models and models file path) (jakubvejr@microsoft.com) | ||
## 1.1.0 | ||
Fri, 30 Sep 2022 08:56:05 GMT | ||
Fri, 30 Sep 2022 08:56:18 GMT | ||
@@ -11,0 +19,0 @@ ### Minor changes |
@@ -55,4 +55,4 @@ var __create = Object.create; | ||
var glob = __toESM(require("fast-glob")); | ||
const PREPEND_TO_INTERFACES = `// @ts-nocheck \r | ||
/* eslint-disable */ \r | ||
const PREPEND_TO_INTERFACES = `/* eslint-disable */ \r | ||
// @ts-nocheck \r | ||
// This file was automatically generated (by @graphitaiton/supermassive) and should not be edited.\r | ||
@@ -59,0 +59,0 @@ `; |
@@ -28,9 +28,10 @@ import { DocumentNode, ASTNode } from "graphql"; | ||
private allModelNames; | ||
private scalars; | ||
private allPossibleModels; | ||
constructor(options: TsCodegenContextOptions); | ||
addImport(imp: DefinitionImport, node: ASTNode): void; | ||
addPossibleModel(possibleModel: string): void; | ||
addModel(model: DefinitionModel, node: ASTNode): void; | ||
getAllImportDeclarations(): ts.ImportDeclaration[]; | ||
getAllModelImportDeclarations(): ts.ImportDeclaration[]; | ||
addScalar(scalarName: string | null): void; | ||
getScalarDeclaration(scalarName: string | null): ts.TypeAliasDeclaration | undefined; | ||
getAllResolverImportDeclarations(): ts.ImportDeclaration[]; | ||
@@ -40,4 +41,4 @@ getBaseModelType(): TypeLocation; | ||
getResolveInfoType(): TypeLocation; | ||
getDefaultTypes(): (ts.InterfaceDeclaration | ts.TypeAliasDeclaration)[]; | ||
getModelType(typeName: string, putModelSuffix: boolean, saveModels?: boolean, useScalars?: boolean): TypeLocation; | ||
getDefaultTypes(): ts.InterfaceDeclaration[]; | ||
getModelType(typeName: string, useScalars?: boolean): TypeLocation; | ||
getDefinedModelType(typeName: string): TypeLocation | null; | ||
@@ -44,0 +45,0 @@ } |
@@ -81,3 +81,3 @@ var __create = Object.create; | ||
this.allModelNames = /* @__PURE__ */ new Set(); | ||
this.scalars = /* @__PURE__ */ new Map(); | ||
this.allPossibleModels = /* @__PURE__ */ new Set(); | ||
} | ||
@@ -102,2 +102,5 @@ addImport(imp, node) { | ||
} | ||
addPossibleModel(possibleModel) { | ||
this.allPossibleModels.add(possibleModel); | ||
} | ||
addModel(model, node) { | ||
@@ -108,5 +111,2 @@ const existingModel = this.typeNameToModels.get(model.typeName); | ||
} | ||
if (this.scalars.has(model.typeName) && model.importName) { | ||
return; | ||
} | ||
this.typeNameToModels.set(model.typeName, model); | ||
@@ -127,11 +127,14 @@ } | ||
} | ||
addScalar(scalarName) { | ||
getScalarDeclaration(scalarName) { | ||
if (!scalarName || BUILT_IN_SCALARS.hasOwnProperty(scalarName)) { | ||
return; | ||
} | ||
let model; | ||
if (this.typeNameToModels.has(scalarName)) { | ||
this.scalars.set(scalarName, this.typeNameToModels.get(scalarName).modelName); | ||
return; | ||
const { from, modelName, tsType } = this.typeNameToModels.get(scalarName); | ||
model = from ? modelName : tsType; | ||
} else { | ||
model = DEFAULT_SCALAR_TYPE; | ||
} | ||
this.scalars.set(scalarName, DEFAULT_SCALAR_TYPE); | ||
return import_typescript.factory.createTypeAliasDeclaration(void 0, [import_typescript.factory.createModifier(import_typescript.default.SyntaxKind.ExportKeyword)], import_typescript.factory.createIdentifier((0, import_utilities2.addModelSuffix)(scalarName)), void 0, import_typescript.factory.createTypeReferenceNode(import_typescript.factory.createIdentifier(model), void 0)); | ||
} | ||
@@ -147,3 +150,3 @@ getAllResolverImportDeclarations() { | ||
} | ||
imports.push((0, import_utilities.createImportDeclaration)(Array.from(this.allModelNames), "./models.interface.ts")); | ||
imports.push((0, import_utilities.createImportDeclaration)(Array.from(this.allModelNames), "./models.interface")); | ||
imports.push(...this.getAllImportDeclarations()); | ||
@@ -165,14 +168,7 @@ return imports; | ||
import_typescript.factory.createPropertySignature(void 0, import_typescript.factory.createIdentifier("__typename"), void 0, import_typescript.factory.createKeywordTypeNode(import_typescript.default.SyntaxKind.StringKeyword)) | ||
]), import_typescript.SyntaxKind.SingleLineCommentTrivia, " Base type for all models. Enables automatic resolution of abstract GraphQL types (interfaces, unions)", true), | ||
...Array.from(this.scalars).map(([key, value]) => import_typescript.factory.createTypeAliasDeclaration(void 0, [import_typescript.factory.createModifier(import_typescript.default.SyntaxKind.ExportKeyword)], import_typescript.factory.createIdentifier(key), void 0, import_typescript.factory.createTypeReferenceNode(import_typescript.factory.createIdentifier(value), void 0))), | ||
...Array.from(this.scalars).filter(([key]) => { | ||
return this.typeNameToModels.has(key) && !this.typeNameToModels.get(key).importName; | ||
}).map(([key]) => import_typescript.factory.createTypeAliasDeclaration(void 0, [import_typescript.factory.createModifier(import_typescript.default.SyntaxKind.ExportKeyword)], import_typescript.factory.createIdentifier(this.typeNameToModels.get(key).modelName), void 0, import_typescript.factory.createTypeReferenceNode(import_typescript.factory.createIdentifier(this.typeNameToModels.get(key).tsType), void 0))) | ||
]), import_typescript.SyntaxKind.SingleLineCommentTrivia, " Base type for all models. Enables automatic resolution of abstract GraphQL types (interfaces, unions)", true) | ||
]; | ||
} | ||
getModelType(typeName, putModelSuffix, saveModels = false, useScalars = false) { | ||
if (this.scalars.has(typeName)) { | ||
this.allModelNames.add(typeName); | ||
return new TypeLocation(null, useScalars ? typeName : this.scalars.get(typeName)); | ||
} else if (BUILT_IN_SCALARS.hasOwnProperty(typeName)) { | ||
getModelType(typeName, useScalars = false) { | ||
if (BUILT_IN_SCALARS.hasOwnProperty(typeName)) { | ||
return new TypeLocation(null, BUILT_IN_SCALARS[typeName]); | ||
@@ -183,4 +179,4 @@ } else if (this.typeNameToImports.has(typeName)) { | ||
} else { | ||
const modelName = putModelSuffix ? (0, import_utilities2.addModelSuffix)(typeName) : typeName; | ||
if (saveModels) { | ||
const modelName = this.allPossibleModels.has(typeName) ? (0, import_utilities2.addModelSuffix)(typeName) : typeName; | ||
if (this.allPossibleModels.has(typeName)) { | ||
this.allModelNames.add(modelName); | ||
@@ -192,5 +188,3 @@ } | ||
getDefinedModelType(typeName) { | ||
if (this.scalars.has(typeName)) { | ||
return new TypeLocation(null, typeName); | ||
} else if (this.typeNameToModels.has(typeName)) { | ||
if (this.typeNameToModels.has(typeName)) { | ||
let imp = this.typeNameToModels.get(typeName); | ||
@@ -215,2 +209,27 @@ return new TypeLocation(null, imp.modelName); | ||
} | ||
}, | ||
EnumTypeDefinition: { | ||
enter(node) { | ||
context.addPossibleModel(node.name.value); | ||
} | ||
}, | ||
ObjectTypeDefinition: { | ||
enter(node) { | ||
context.addPossibleModel(node.name.value); | ||
} | ||
}, | ||
UnionTypeDefinition: { | ||
enter(node) { | ||
context.addPossibleModel(node.name.value); | ||
} | ||
}, | ||
ScalarTypeDefinition: { | ||
enter(node) { | ||
context.addPossibleModel(node.name.value); | ||
} | ||
}, | ||
InterfaceTypeDefinition: { | ||
enter(node) { | ||
context.addPossibleModel(node.name.value); | ||
} | ||
} | ||
@@ -217,0 +236,0 @@ }); |
@@ -43,3 +43,3 @@ var __defProp = Object.defineProperty; | ||
typeName, | ||
modelName: typeDef.kind === "ScalarTypeDefinition" ? (0, import_utilities.addModelSuffix)(typeName) : `_${(0, import_utilities.addModelSuffix)(typeName)}`, | ||
modelName: `_${(0, import_utilities.addModelSuffix)(typeName)}`, | ||
tsType: tsType.value, | ||
@@ -46,0 +46,0 @@ importName: from ? (0, import_utilities.createVariableNameFromImport)(from.value) : null, |
@@ -101,4 +101,8 @@ var __create = Object.create; | ||
const extendTypes = [context.getBaseModelType()]; | ||
const interfaces = node.interfaces || []; | ||
return import_typescript.factory.createInterfaceDeclaration(void 0, [import_typescript.factory.createModifier(import_typescript.default.SyntaxKind.ExportKeyword)], import_typescript.factory.createIdentifier((0, import_utilities.addModelSuffix)(node.name)), void 0, [ | ||
import_typescript.factory.createHeritageClause(import_typescript.default.SyntaxKind.ExtendsKeyword, extendTypes.map((type) => import_typescript.factory.createExpressionWithTypeArguments(type.toExpression(), void 0))) | ||
import_typescript.factory.createHeritageClause(import_typescript.default.SyntaxKind.ExtendsKeyword, [ | ||
...extendTypes.map((type) => import_typescript.factory.createExpressionWithTypeArguments(type.toExpression(), void 0)), | ||
...interfaces.map((interfaceExpression) => import_typescript.factory.createExpressionWithTypeArguments(interfaceExpression, void 0)) | ||
]) | ||
], [ | ||
@@ -118,9 +122,7 @@ import_typescript.factory.createPropertySignature(void 0, "__typename", void 0, import_typescript.factory.createKeywordTypeNode(import_typescript.default.SyntaxKind.StringKeyword)) | ||
leave(node) { | ||
context.addScalar(node.name); | ||
return null; | ||
return context.getScalarDeclaration(node.name) || null; | ||
} | ||
}, | ||
NamedType: { | ||
leave(node, _a, _p, path, ancestors) { | ||
const isAncestorInput = (0, import_utilities.isDirectAncestorInput)(ancestors); | ||
leave(node, _a, _p, path) { | ||
const isImplementedInterface = path[path.length - 2] === "interfaces"; | ||
@@ -130,3 +132,3 @@ if (isImplementedInterface) { | ||
} | ||
return (0, import_utilities.createNullableType)(context.getModelType(node.name, !isAncestorInput).toTypeReference()); | ||
return (0, import_utilities.createNullableType)(context.getModelType(node.name).toTypeReference()); | ||
} | ||
@@ -133,0 +135,0 @@ }, |
@@ -74,16 +74,25 @@ var __create = Object.create; | ||
} else if (parentObject.kind !== import_graphql.Kind.INTERFACE_TYPE_DEFINITION) { | ||
modelIdentifier = context.getModelType(parentName, true, true).toTypeReference(); | ||
modelIdentifier = context.getModelType(parentName).toTypeReference(); | ||
} | ||
return import_typescript.factory.createTypeAliasDeclaration(void 0, [import_typescript.factory.createModifier(import_typescript.default.SyntaxKind.ExportKeyword)], import_typescript.factory.createIdentifier(node.name), void 0, import_typescript.factory.createFunctionTypeNode(void 0, [ | ||
import_typescript.factory.createParameterDeclaration(void 0, void 0, void 0, import_typescript.factory.createIdentifier("model"), void 0, modelIdentifier, void 0), | ||
import_typescript.factory.createParameterDeclaration(void 0, void 0, void 0, import_typescript.factory.createIdentifier("args"), void 0, import_typescript.factory.createTypeLiteralNode(node.arguments || []), void 0), | ||
import_typescript.factory.createParameterDeclaration(void 0, void 0, void 0, import_typescript.factory.createIdentifier("context"), void 0, context.getContextType().toTypeReference(), void 0), | ||
import_typescript.factory.createParameterDeclaration(void 0, void 0, void 0, import_typescript.factory.createIdentifier("info"), void 0, context.getResolveInfoType().toTypeReference(), void 0) | ||
], import_typescript.factory.createTypeReferenceNode(import_typescript.factory.createIdentifier("PromiseOrValue"), [node.type]))); | ||
const resolverParametersDefinitions = { | ||
parent: { | ||
name: "model", | ||
type: modelIdentifier | ||
}, | ||
args: { name: "args", type: node.arguments || [] }, | ||
context: { | ||
name: "context", | ||
type: context.getContextType().toTypeReference() | ||
}, | ||
resolveInfo: { | ||
name: "info", | ||
type: context.getResolveInfoType().toTypeReference() | ||
} | ||
}; | ||
return import_typescript.factory.createTypeAliasDeclaration(void 0, [import_typescript.factory.createModifier(import_typescript.default.SyntaxKind.ExportKeyword)], import_typescript.factory.createIdentifier(node.name), void 0, import_typescript.factory.createFunctionTypeNode(void 0, (0, import_utilities.getResolverParameters)(resolverParametersDefinitions), (0, import_utilities.getResolverReturnType)(node.type, parentName, resolverParametersDefinitions))); | ||
} | ||
}, | ||
NamedType: { | ||
leave(node, _a, _p, _path, ancestors) { | ||
const isAncestorInput = (0, import_utilities.isDirectAncestorInput)(ancestors); | ||
return (0, import_utilities.createNullableType)(context.getModelType(node.name, !isAncestorInput, !isAncestorInput, true).toTypeReference()); | ||
leave(node, _a, _p, _path) { | ||
return (0, import_utilities.createNullableType)(context.getModelType(node.name, true).toTypeReference()); | ||
} | ||
@@ -90,0 +99,0 @@ }, |
import ts from "typescript"; | ||
import { ASTNode } from "graphql"; | ||
export declare function createNullableType(node: ts.TypeNode): ts.UnionTypeNode; | ||
declare type ResolverParameterDefinition<T> = { | ||
name: string; | ||
type: T; | ||
}; | ||
declare type ResolverParametersDefinitions = { | ||
parent: ResolverParameterDefinition<ts.TypeReferenceNode>; | ||
args: ResolverParameterDefinition<readonly ts.TypeElement[]>; | ||
context: ResolverParameterDefinition<ts.TypeReferenceNode>; | ||
resolveInfo: ResolverParameterDefinition<ts.TypeReferenceNode>; | ||
}; | ||
export declare function getResolverParameters({ parent, args, context, resolveInfo, }: ResolverParametersDefinitions): ts.ParameterDeclaration[]; | ||
export declare function getResolverReturnType(typeNode: ts.TypeNode, parentName: string, resolverParametersDefinitions: ResolverParametersDefinitions): ts.TypeReferenceNode | ts.UnionTypeNode; | ||
export declare function createNonNullableType(node: ts.TypeNode): ts.TypeNode; | ||
export declare function addModelSuffix(typeName: string): string; | ||
export declare function isDirectAncestorInput(ancestors: readonly (ASTNode | readonly ASTNode[])[]): boolean; | ||
export declare function createVariableNameFromImport(path: string): string; | ||
@@ -39,2 +49,3 @@ export declare type CamelCaseOptions = { | ||
export declare function camelCase(input: string | readonly string[], options: CamelCaseOptions): string; | ||
export {}; | ||
//# sourceMappingURL=utilities.d.ts.map |
var __create = Object.create; | ||
var __defProp = Object.defineProperty; | ||
var __defProps = Object.defineProperties; | ||
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; | ||
var __getOwnPropDescs = Object.getOwnPropertyDescriptors; | ||
var __getOwnPropNames = Object.getOwnPropertyNames; | ||
@@ -21,2 +23,3 @@ var __getOwnPropSymbols = Object.getOwnPropertySymbols; | ||
}; | ||
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b)); | ||
var __export = (target, all) => { | ||
@@ -43,7 +46,7 @@ for (var name in all) | ||
createVariableNameFromImport: () => createVariableNameFromImport, | ||
isDirectAncestorInput: () => isDirectAncestorInput | ||
getResolverParameters: () => getResolverParameters, | ||
getResolverReturnType: () => getResolverReturnType | ||
}); | ||
module.exports = __toCommonJS(utilities_exports); | ||
var import_typescript = __toESM(require("typescript")); | ||
var import_graphql = require("graphql"); | ||
const MODEL_SUFFIX = "Model"; | ||
@@ -56,2 +59,34 @@ function createNullableType(node) { | ||
} | ||
function getResolverParameters({ | ||
parent, | ||
args, | ||
context, | ||
resolveInfo | ||
}) { | ||
return [ | ||
import_typescript.factory.createParameterDeclaration(void 0, void 0, void 0, import_typescript.factory.createIdentifier(parent.name), void 0, parent.type), | ||
import_typescript.factory.createParameterDeclaration(void 0, void 0, void 0, import_typescript.factory.createIdentifier(args.name), void 0, import_typescript.factory.createTypeLiteralNode(args.type)), | ||
import_typescript.factory.createParameterDeclaration(void 0, void 0, void 0, import_typescript.factory.createIdentifier(context.name), void 0, context.type), | ||
import_typescript.factory.createParameterDeclaration(void 0, void 0, void 0, import_typescript.factory.createIdentifier(resolveInfo.name), void 0, resolveInfo.type) | ||
]; | ||
} | ||
function getResolverReturnType(typeNode, parentName, resolverParametersDefinitions) { | ||
if (parentName !== "Subscription") { | ||
return import_typescript.factory.createTypeReferenceNode(import_typescript.factory.createIdentifier("PromiseOrValue"), [typeNode]); | ||
} | ||
return import_typescript.factory.createUnionTypeNode([ | ||
import_typescript.factory.createTypeReferenceNode(import_typescript.factory.createIdentifier("AsyncIterator"), [ | ||
typeNode | ||
]), | ||
import_typescript.factory.createFunctionTypeNode([import_typescript.factory.createTypeParameterDeclaration(import_typescript.factory.createIdentifier("A"))], [], import_typescript.factory.createTypeLiteralNode([ | ||
import_typescript.factory.createPropertySignature(void 0, import_typescript.factory.createIdentifier("subscribe"), void 0, import_typescript.factory.createFunctionTypeNode(void 0, getResolverParameters(resolverParametersDefinitions), import_typescript.factory.createTypeReferenceNode(import_typescript.factory.createIdentifier("AsyncIterator"), [import_typescript.factory.createTypeReferenceNode(import_typescript.factory.createIdentifier("A"))]))), | ||
import_typescript.factory.createPropertySignature(void 0, import_typescript.factory.createIdentifier("resolve"), void 0, import_typescript.factory.createFunctionTypeNode(void 0, getResolverParameters(__spreadProps(__spreadValues({}, resolverParametersDefinitions), { | ||
parent: { | ||
name: "parent", | ||
type: import_typescript.factory.createTypeReferenceNode(import_typescript.factory.createIdentifier("A")) | ||
} | ||
})), typeNode)) | ||
])) | ||
]); | ||
} | ||
function createNonNullableType(node) { | ||
@@ -70,11 +105,2 @@ if (import_typescript.default.isUnionTypeNode(node)) { | ||
} | ||
function isDirectAncestorInput(ancestors) { | ||
const directAncestors = ancestors[ancestors.length - 1]; | ||
if (Array.isArray(directAncestors)) { | ||
return directAncestors.some((directAncestor) => { | ||
return "kind" in directAncestor && directAncestor.kind === import_graphql.Kind.INPUT_VALUE_DEFINITION; | ||
}); | ||
} | ||
return "kind" in directAncestors && directAncestors.kind === import_graphql.Kind.INPUT_VALUE_DEFINITION; | ||
} | ||
function createVariableNameFromImport(path) { | ||
@@ -81,0 +107,0 @@ return camelCase(path.replace(/\.\.\//g, "up-").replace(/@/g, "NS-").replace(/\.\//g, "cwd-").replace(/\//g, "-"), { |
{ | ||
"name": "@graphitation/supermassive", | ||
"license": "MIT", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"bin": { | ||
@@ -6,0 +6,0 @@ "supermassive": "./bin/supermassive.js" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
473970
9522