MCPcopy Create free account
hub / github.com/andywer/postguard / createQueryInvocation

Function createQueryInvocation

src/babel/parse-query-invocation.ts:27–69  ·  view source on GitHub ↗
(
  query: Query,
  path: NodePath<types.TaggedTemplateExpression>,
  sourceFile: SourceFile
)

Source from the content-addressed store, hash-verified

25}
26
27export function createQueryInvocation(
28 query: Query,
29 path: NodePath<types.TaggedTemplateExpression>,
30 sourceFile: SourceFile
31): QueryInvocation {
32 let resultTypeAssertion: QueryInvocation["resultTypeAssertion"]
33
34 if (path.parentPath.isCallExpression() && sourceFile.ts) {
35 const callExpression: NodePath<types.CallExpression> = path.parentPath
36 const typeParameters = callExpression.get("typeParameters")
37
38 const propTypes = resolveTypeParamPropTypes(
39 typeParameters,
40 sourceFile.ts.program,
41 sourceFile.ts.sourceFile
42 )
43
44 if (propTypes && Object.keys(propTypes).length > 0) {
45 const schema = mapPropertyTypesToSchemaDescriptor(propTypes)
46
47 resultTypeAssertion = {
48 path: typeParameters as NodePath<types.Node>,
49 schema
50 }
51 } else if (typeParameters.node) {
52 const { loc } = callExpression.node
53 console.warn(
54 format.warning(
55 `Warning: Cannot infer type of type parameter. Skipping type checking of this expression.\n` +
56 ` File: ${sourceFile.filePath}${loc ? `:${loc.start.line}` : ""}\n` +
57 ` Type parameter: ${typeParameters.getSource()}`
58 )
59 )
60 } else {
61 // No type params specified - Ignore
62 }
63 }
64
65 return {
66 query,
67 resultTypeAssertion
68 }
69}

Callers 1

TaggedTemplateExpressionFunction · 0.90

Tested by

no test coverage detected