{"version":3,"file":"thread-chunk2.mjs","sources":["../../src/commands/turbo/cache.ts","../../src/commands/turbo/hash.ts","../../src/commands/turbo/thread.ts"],"sourcesContent":["import ts from 'typescript';\nimport * as fs from 'node:fs';\n\nconst HASH_COMMENT = /@gql\\.tada\\/hash\\s+([^\\s*]+)/;\n\nexport interface CachedTurboDocument {\n  documentHash: string;\n  documentType: string;\n}\n\nexport type CachedTurboDocuments = Map<string, CachedTurboDocument>;\n\nexport function readCachedTurboDocuments(cachePath: string | undefined): CachedTurboDocuments {\n  const documents: CachedTurboDocuments = new Map();\n  if (!cachePath || !fs.existsSync(cachePath)) {\n    return documents;\n  }\n\n  let contents: string;\n  try {\n    contents = fs.readFileSync(cachePath, 'utf8');\n  } catch {\n    return documents;\n  }\n\n  const sourceFile = ts.createSourceFile(\n    cachePath,\n    contents,\n    ts.ScriptTarget.Latest,\n    /*setParentNodes*/ true,\n    ts.ScriptKind.TS\n  );\n\n  const visit = (node: ts.Node) => {\n    if (ts.isInterfaceDeclaration(node) && node.name.text === 'setupCache') {\n      for (const member of node.members) {\n        if (!ts.isPropertySignature(member) || !member.type) continue;\n        if (!ts.isStringLiteral(member.name) && !ts.isNumericLiteral(member.name)) continue;\n\n        const documentHash = getHashComment(contents, member);\n        if (!documentHash) continue;\n\n        documents.set(JSON.stringify(member.name.text), {\n          documentHash,\n          documentType: member.type.getText(sourceFile),\n        });\n      }\n    }\n\n    ts.forEachChild(node, visit);\n  };\n\n  visit(sourceFile);\n  return documents;\n}\n\nfunction getHashComment(contents: string, node: ts.Node): string | undefined {\n  const comments = ts.getLeadingCommentRanges(contents, node.pos) || [];\n  for (let i = comments.length - 1; i >= 0; i--) {\n    const comment = contents.slice(comments[i].pos, comments[i].end);\n    const match = HASH_COMMENT.exec(comment);\n    if (match) return match[1];\n  }\n  return undefined;\n}\n","import ts from 'typescript';\nimport * as crypto from 'node:crypto';\n\n// NOTE(@kitten): Change if document type input or output changes\nconst CACHE_BUSTER = 'turbo-document-hash-v1';\n\nexport interface DocumentHashResult {\n  hashable: boolean;\n  documentHash?: string;\n}\n\nexport interface DocumentHasher {\n  hashCallExpression(\n    callExpression: ts.CallExpression,\n    schemaName: string | null\n  ): DocumentHashResult;\n}\n\ninterface HashContext {\n  readonly checker: ts.TypeChecker;\n  schemaFingerprints: ReadonlyMap<string | null, string>;\n}\n\nexport function createDocumentHasher(context: HashContext): DocumentHasher {\n  const callExpressionCache = new WeakMap<ts.CallExpression, Map<string, DocumentHashResult>>();\n  const symbolCallCache = new Map<ts.Symbol, ts.CallExpression | null>();\n  const activeCalls = new WeakSet<ts.CallExpression>();\n\n  const hashCallExpression = (\n    callExpression: ts.CallExpression,\n    schemaName: string | null\n  ): DocumentHashResult => {\n    const schemaKey = schemaName || '';\n    const cached = callExpressionCache.get(callExpression)?.get(schemaKey);\n    if (cached) {\n      return cached;\n    } else if (activeCalls.has(callExpression)) {\n      return { hashable: false };\n    }\n\n    activeCalls.add(callExpression);\n    const result = computeCallExpressionHash(callExpression, schemaName);\n    activeCalls.delete(callExpression);\n\n    let schemaCache = callExpressionCache.get(callExpression);\n    if (!schemaCache) {\n      schemaCache = new Map();\n      callExpressionCache.set(callExpression, schemaCache);\n    }\n\n    schemaCache.set(schemaKey, result);\n    return result;\n  };\n\n  const computeCallExpressionHash = (\n    callExpression: ts.CallExpression,\n    schemaName: string | null\n  ): DocumentHashResult => {\n    const documentText = getStaticStringValue(callExpression.arguments[0]);\n    if (documentText == null) {\n      return { hashable: false };\n    }\n\n    const fragmentHashes = getFragmentHashes(callExpression.arguments[1], schemaName);\n    if (!fragmentHashes) {\n      return { hashable: false };\n    }\n\n    const hash = crypto.createHash('sha256');\n\n    addHashPart(hash, CACHE_BUSTER);\n    addHashPart(hash, schemaName || '');\n    addHashPart(hash, context.schemaFingerprints.get(schemaName) || '');\n    addHashPart(hash, documentText);\n    for (const fragmentHash of fragmentHashes) {\n      addHashPart(hash, fragmentHash);\n    }\n\n    return {\n      hashable: true,\n      documentHash: `sha256:${hash.digest('hex').slice(0, 32)}`,\n    };\n  };\n\n  const getFragmentHashes = (\n    fragmentsExpression: ts.Expression | undefined,\n    schemaName: string | null\n  ): string[] | null => {\n    if (!fragmentsExpression) return [];\n\n    fragmentsExpression = unwrapExpression(fragmentsExpression);\n\n    if (ts.isArrayLiteralExpression(fragmentsExpression)) {\n      const hashes: string[] = [];\n      for (const element of fragmentsExpression.elements) {\n        if (ts.isSpreadElement(element)) {\n          const spreadHashes = getFragmentHashes(element.expression, schemaName);\n          if (!spreadHashes) return null;\n          hashes.push(...spreadHashes);\n          continue;\n        }\n\n        const documentCall = resolveDocumentCallExpression(element);\n        if (!documentCall) return null;\n\n        const fragmentHash = hashCallExpression(documentCall, schemaName);\n        if (!fragmentHash.hashable || !fragmentHash.documentHash) return null;\n        hashes.push(fragmentHash.documentHash);\n      }\n      return hashes;\n    }\n\n    const declarationExpression = resolveDeclarationInitializer(fragmentsExpression);\n    if (declarationExpression && declarationExpression !== fragmentsExpression) {\n      return getFragmentHashes(declarationExpression, schemaName);\n    }\n\n    return null;\n  };\n\n  const resolveDocumentCallExpression = (expression: ts.Expression): ts.CallExpression | null => {\n    expression = unwrapExpression(expression);\n    if (ts.isCallExpression(expression)) return expression;\n\n    const symbol = getSymbol(expression);\n    if (!symbol) return null;\n\n    const cached = symbolCallCache.get(symbol);\n    if (cached !== undefined) return cached;\n\n    const callExpression = resolveSymbolCallExpression(symbol);\n    symbolCallCache.set(symbol, callExpression);\n    return callExpression;\n  };\n\n  const resolveDeclarationInitializer = (expression: ts.Expression): ts.Expression | null => {\n    const symbol = getSymbol(expression);\n    if (!symbol) return null;\n\n    for (const declaration of symbol.declarations || []) {\n      if (ts.isVariableDeclaration(declaration) && declaration.initializer) {\n        return declaration.initializer;\n      }\n    }\n\n    return null;\n  };\n\n  const resolveSymbolCallExpression = (symbol: ts.Symbol): ts.CallExpression | null => {\n    for (const declaration of symbol.declarations || []) {\n      if (ts.isVariableDeclaration(declaration) && declaration.initializer) {\n        const initializer = unwrapExpression(declaration.initializer);\n        if (ts.isCallExpression(initializer)) return initializer;\n      }\n    }\n    return null;\n  };\n\n  const getSymbol = (expression: ts.Expression): ts.Symbol | undefined => {\n    let symbol = context.checker.getSymbolAtLocation(expression);\n    if (symbol && symbol.flags & ts.SymbolFlags.Alias) {\n      symbol = context.checker.getAliasedSymbol(symbol);\n    }\n    return symbol;\n  };\n\n  return { hashCallExpression };\n}\n\nfunction getStaticStringValue(expression: ts.Expression | undefined): string | undefined {\n  if (!expression) return undefined;\n  expression = unwrapExpression(expression);\n\n  if (ts.isStringLiteral(expression) || ts.isNoSubstitutionTemplateLiteral(expression)) {\n    return expression.text;\n  }\n\n  return undefined;\n}\n\nfunction unwrapExpression(expression: ts.Expression): ts.Expression {\n  while (\n    ts.isParenthesizedExpression(expression) ||\n    ts.isAsExpression(expression) ||\n    ts.isTypeAssertionExpression(expression) ||\n    ts.isSatisfiesExpression(expression) ||\n    ts.isNonNullExpression(expression)\n  ) {\n    expression = expression.expression;\n  }\n  return expression;\n}\n\nfunction addHashPart(hash: crypto.Hash, part: string): void {\n  hash.update(`${part.length}:`);\n  hash.update(part);\n  hash.update('\\0');\n}\n","import ts from 'typescript';\nimport v8 from 'node:v8';\nimport vm from 'node:vm';\nimport * as fs from 'node:fs';\nimport * as path from 'node:path';\nimport * as crypto from 'node:crypto';\nimport type { GraphQLSPConfig } from '@gql.tada/internal';\n\nimport { getSchemaNamesFromConfig, getSchemaConfigForName } from '@gql.tada/internal';\nimport { findAllCallExpressions } from '@0no-co/graphqlsp/api';\n\nimport type { ProgramContainer, PluginCreateInfo } from '../../ts';\nimport { programFactory } from '../../ts';\nimport { expose } from '../../threads';\n\nimport type {\n  TurboSignal,\n  TurboWarning,\n  TurboDocument,\n  GraphQLSourceFile,\n  GraphQLSourceImport,\n  TurboPath,\n} from './types';\nimport { readCachedTurboDocuments, type CachedTurboDocuments } from './cache';\nimport { createDocumentHasher } from './hash';\nimport { hasGraphQLDocumentCandidate, shouldScanTurboFile } from './scan';\n\nexport interface TurboParams {\n  rootPath: string;\n  tsconfigPath?: string;\n  configPath: string;\n  pluginConfig: GraphQLSPConfig;\n  turboOutputPath: string | TurboPath[];\n}\n\nconst HEAP_SOFT_LIMIT_BYTES = 2_500 * 1_024 * 1_024;\nconst TURBO_MAX_BATCH = 1_000;\n\ninterface ImportTraceCache {\n  /** Resolved import source per `fileName\\0identifier` key */\n  traces: Map<string, string | undefined>;\n  host: ts.CompilerHost | undefined;\n  resolutionCache: ts.ModuleResolutionCache | undefined;\n}\n\nconst createImportTraceCache = (): ImportTraceCache => ({\n  traces: new Map(),\n  host: undefined,\n  resolutionCache: undefined,\n});\n\nfunction traceCallToImportSource(\n  callExpression: ts.CallExpression,\n  sourceFile: ts.SourceFile,\n  program: ts.Program,\n  cache: ImportTraceCache\n): string | undefined {\n  const expression = callExpression.expression;\n\n  let identifier: ts.Identifier | undefined;\n  if (ts.isIdentifier(expression)) {\n    identifier = expression;\n  } else if (ts.isPropertyAccessExpression(expression) && ts.isIdentifier(expression.expression)) {\n    identifier = expression.expression;\n  }\n\n  if (!identifier) return undefined;\n\n  // NOTE: All calls of the same identifier in a file resolve to the same import\n  // source, so the resolution is cached per file and identifier name\n  const traceKey = `${sourceFile.fileName}\\0${identifier.text}`;\n  if (cache.traces.has(traceKey)) return cache.traces.get(traceKey);\n\n  let result: string | undefined;\n  const typeChecker = program.getTypeChecker();\n  const symbol = typeChecker.getSymbolAtLocation(identifier);\n  if (symbol && symbol.declarations) {\n    for (const declaration of symbol.declarations) {\n      const importDeclaration = findImportDeclaration(declaration);\n      if (importDeclaration && ts.isStringLiteral(importDeclaration.moduleSpecifier)) {\n        const moduleName = importDeclaration.moduleSpecifier.text;\n        result = resolveModulePath(moduleName, sourceFile, program, cache);\n        break;\n      }\n    }\n  }\n\n  cache.traces.set(traceKey, result);\n  return result;\n}\n\nfunction findImportDeclaration(node: ts.Node): ts.ImportDeclaration | undefined {\n  let current: ts.Node | undefined = node;\n\n  while (current) {\n    if (ts.isImportDeclaration(current)) {\n      return current;\n    }\n    current = current.parent;\n  }\n\n  return undefined;\n}\n\nfunction resolveModulePath(\n  moduleName: string,\n  containingFile: ts.SourceFile,\n  program: ts.Program,\n  cache: ImportTraceCache\n): string | undefined {\n  const compilerOptions = program.getCompilerOptions();\n  const host = cache.host || (cache.host = ts.createCompilerHost(compilerOptions));\n  const resolutionCache =\n    cache.resolutionCache ||\n    (cache.resolutionCache = ts.createModuleResolutionCache(\n      host.getCurrentDirectory(),\n      host.getCanonicalFileName.bind(host),\n      compilerOptions\n    ));\n\n  const resolved = ts.resolveModuleName(\n    moduleName,\n    containingFile.fileName,\n    compilerOptions,\n    host,\n    resolutionCache\n  );\n\n  if (resolved.resolvedModule) {\n    return resolved.resolvedModule.resolvedFileName;\n  }\n\n  return undefined;\n}\n\nexport function collectImportsFromSourceFile(\n  sourceFile: ts.SourceFile,\n  pluginConfig: GraphQLSPConfig,\n  resolveModuleName: (importSpecifier: string, fromPath: string, toPath: string) => string,\n  resolveModulePath: (importSpecifier: string, fromPath: string) => string | undefined,\n  rootPath: string,\n  turboOutputPath?: string,\n  shouldTreatImportsAsNodeNext?: boolean\n): GraphQLSourceImport[] {\n  const imports: GraphQLSourceImport[] = [];\n\n  const tadaImportPaths = getTadaOutputPaths(pluginConfig, rootPath);\n\n  // NOTE: Import declarations may only appear as top-level statements\n  for (const node of sourceFile.statements) {\n    if (ts.isImportDeclaration(node) && ts.isStringLiteral(node.moduleSpecifier)) {\n      const specifier = node.moduleSpecifier.text;\n\n      if (!isTadaImport(specifier, sourceFile.fileName, tadaImportPaths, resolveModulePath)) {\n        const importClause = node.getFullText().trim();\n        if (turboOutputPath) {\n          // Adjust the import specifier to point to the turbo output path\n          let adjustedSpecifier = resolveModuleName(\n            specifier,\n            sourceFile.fileName,\n            turboOutputPath\n          );\n\n          if (shouldTreatImportsAsNodeNext) {\n            if (adjustedSpecifier.endsWith('.ts') || adjustedSpecifier.endsWith('.tsx')) {\n              adjustedSpecifier = adjustedSpecifier\n                .replace(/\\.ts$/, '.js')\n                .replace(/\\.tsx$/, '.js');\n            }\n          } else {\n            adjustedSpecifier = adjustedSpecifier.replace(/\\.ts$/, '').replace(/\\.tsx$/, '');\n          }\n\n          if (adjustedSpecifier && !adjustedSpecifier.includes('gql.tada')) {\n            imports.push({\n              specifier: adjustedSpecifier,\n              importClause: importClause.replace(specifier, adjustedSpecifier),\n            });\n          }\n        } else {\n          imports.push({ specifier, importClause });\n        }\n      }\n    }\n  }\n\n  return imports;\n}\n\nfunction getTadaOutputPaths(pluginConfig: GraphQLSPConfig, rootPath: string): string[] {\n  const paths: string[] = [];\n\n  if ('schema' in pluginConfig && pluginConfig.tadaOutputLocation) {\n    paths.push(path.resolve(rootPath, pluginConfig.tadaOutputLocation));\n  } else if ('schemas' in pluginConfig) {\n    for (const schemaConfig of pluginConfig.schemas) {\n      if (schemaConfig.tadaOutputLocation) {\n        paths.push(path.resolve(rootPath, schemaConfig.tadaOutputLocation));\n      }\n    }\n  }\n\n  return paths;\n}\n\nfunction isTadaImport(\n  importSpecifier: string,\n  sourceFilePath: string,\n  tadaOutputLocationPaths: string[],\n  resolveModulePath: (importSpecifier: string, fromPath: string) => string | undefined\n): boolean {\n  const resolvedImportPath = resolveModulePath(importSpecifier, sourceFilePath);\n  if (resolvedImportPath) {\n    return tadaOutputLocationPaths.some(\n      (tadaOutputLocationPath) => resolvedImportPath === tadaOutputLocationPath\n    );\n  }\n\n  if (importSpecifier.startsWith('.')) {\n    const sourceDir = path.dirname(sourceFilePath);\n    const absoluteImportPath = path.resolve(sourceDir, importSpecifier);\n\n    return tadaOutputLocationPaths.some((tadaOutputLocationPath) => {\n      return absoluteImportPath === tadaOutputLocationPath;\n    });\n  }\n\n  return tadaOutputLocationPaths.some(\n    (tadaPath) => importSpecifier === tadaPath || importSpecifier.startsWith(tadaPath + '/')\n  );\n}\n\nexport async function* _runTurbo(params: TurboParams): AsyncIterableIterator<TurboSignal> {\n  const schemaNames = getSchemaNamesFromConfig(params.pluginConfig);\n  const factory = programFactory(params);\n  const cachedDocumentsByPath = new Map<string, CachedTurboDocuments>();\n\n  const getCachedDocuments = (schemaName: string | null): CachedTurboDocuments => {\n    const turboOutputPath = getTurboOutputPath(params.turboOutputPath, schemaName);\n    if (!turboOutputPath) return new Map();\n\n    let cachedDocuments = cachedDocumentsByPath.get(turboOutputPath);\n    if (!cachedDocuments) {\n      cachedDocuments = readCachedTurboDocuments(turboOutputPath);\n      cachedDocumentsByPath.set(turboOutputPath, cachedDocuments);\n    }\n    return cachedDocuments;\n  };\n\n  // NOTE: We add our override declaration here before loading all files\n  // This sets `__cacheDisabled` on the turbo cache, which disables the cache temporarily\n  // If we don't disable the cache then we couldn't regenerate it from inferred types\n  factory.addSourceFile({\n    fileId: '__gql-tada-override__.d.ts',\n    sourceText: DECLARATION_OVERRIDE,\n    scriptKind: ts.ScriptKind.TS,\n  });\n\n  const externalFiles = factory.createExternalFiles();\n  if (externalFiles.length) {\n    yield { kind: 'EXTERNAL_WARNING' };\n    await factory.addVirtualFiles(externalFiles);\n  }\n\n  // Initially, we only build the program to count files\n  // Later, we may reinstantiate to free up memory between batches\n  let container = factory.build();\n  let pluginInfo = container.buildPluginInfo(params.pluginConfig);\n  const turboOutputPaths = new Set(\n    getTurboOutputPaths(params.turboOutputPath).map((fileName) => path.resolve(fileName))\n  );\n  const fileNames = factory.rootFileNames.filter((fileName) =>\n    shouldScanTurboFile(fileName, turboOutputPaths)\n  );\n\n  yield {\n    kind: 'FILE_COUNT',\n    fileCount: fileNames.length,\n  };\n\n  const uniqueGraphQLSources = new Map<string, GraphQLSourceFile>();\n  const importTraceCache = createImportTraceCache();\n\n  const processSourceFile = (\n    sourceFile: ts.SourceFile,\n    container: ProgramContainer,\n    pluginInfo: PluginCreateInfo,\n    checker: ts.TypeChecker\n  ): { filePath: string; documents: TurboDocument[]; warnings: TurboWarning[] } => {\n    let filePath = sourceFile.fileName;\n    const documents: TurboDocument[] = [];\n    const warnings: TurboWarning[] = [];\n\n    if (!hasGraphQLDocumentCandidate(sourceFile)) {\n      return { filePath, documents, warnings };\n    }\n\n    // NOTE: Turbo only consumes the discovered call nodes, so fragment definitions\n    // aren't collected and external fragment documents aren't searched for\n    const calls = findAllCallExpressions(sourceFile, pluginInfo, {\n      searchExternal: false,\n      collectFragments: false,\n    }).nodes;\n    for (const call of calls) {\n      const callExpression = call.node.parent;\n      if (!ts.isCallExpression(callExpression)) {\n        continue;\n      }\n\n      const position = container.getSourcePosition(sourceFile, callExpression.getStart());\n      filePath = position.fileName;\n      if (!schemaNames.has(call.schema)) {\n        warnings.push({\n          message: call.schema\n            ? `The '${call.schema}' schema is not in the configuration but was referenced by document.`\n            : schemaNames.size > 1\n              ? 'The document is not for a known schema. Have you re-generated the output file?'\n              : 'Multiple schemas are configured, but the document is not for a specific schema.',\n          file: position.fileName,\n          line: position.line,\n          col: position.col,\n        });\n        continue;\n      }\n\n      const graphqlSourcePath = traceCallToImportSource(\n        callExpression,\n        sourceFile,\n        container.program,\n        importTraceCache\n      );\n\n      if (graphqlSourcePath && !uniqueGraphQLSources.has(graphqlSourcePath)) {\n        const graphqlSourceFile = container.program.getSourceFile(graphqlSourcePath);\n        if (graphqlSourceFile) {\n          const turboPath = getTurboOutputPath(params.turboOutputPath, call.schema);\n          const imports = collectImportsFromSourceFile(\n            graphqlSourceFile,\n            params.pluginConfig,\n            factory.resolveModuleName.bind(factory),\n            factory.resolveModulePath.bind(factory),\n            params.rootPath,\n            turboPath,\n            !!factory.wasOriginallyNodeNext\n          );\n          uniqueGraphQLSources.set(graphqlSourcePath, {\n            absolutePath: graphqlSourcePath,\n            imports,\n          });\n        }\n      }\n\n      const argumentKey = JSON.stringify(call.node.text);\n\n      const documentHash = documentHasher.hashCallExpression(callExpression, call.schema);\n      const cachedDocument =\n        documentHash.hashable && documentHash.documentHash\n          ? getCachedDocuments(call.schema).get(argumentKey)\n          : undefined;\n\n      let documentType: string;\n      let isCached = false;\n      if (cachedDocument && cachedDocument.documentHash === documentHash.documentHash) {\n        documentType = cachedDocument.documentType;\n        isCached = true;\n      } else {\n        const returnType = checker.getTypeAtLocation(callExpression);\n        // NOTE: `returnType.symbol` is incorrectly typed and is in fact\n        // optional and not always present\n        if (!returnType.symbol || returnType.symbol.getEscapedName() !== 'TadaDocumentNode') {\n          warnings.push({\n            message:\n              `The discovered document is not of type \"TadaDocumentNode\".\\n` +\n              'If this is unexpected, please file an issue describing your case.',\n            file: position.fileName,\n            line: position.line,\n            col: position.col,\n          });\n          continue;\n        }\n\n        documentType = checker.typeToString(returnType, callExpression, BUILDER_FLAGS);\n      }\n\n      documents.push({\n        schemaName: call.schema,\n        argumentKey,\n        documentType,\n        documentHash: documentHash.documentHash,\n        isCached,\n      });\n    }\n\n    return { filePath, documents, warnings };\n  };\n\n  const isHeapOverSoftLimit = (): boolean => {\n    if (process.memoryUsage().heapUsed < HEAP_SOFT_LIMIT_BYTES) return false;\n    forceGc();\n    return process.memoryUsage().heapUsed >= HEAP_SOFT_LIMIT_BYTES;\n  };\n\n  let checker = container.program.getTypeChecker();\n  const documentHasher = createDocumentHasher({\n    get checker() {\n      return checker;\n    },\n    schemaFingerprints: computeSchemaFingerprints(params),\n  });\n  let filesInBatch = 0;\n\n  for (const fileName of fileNames) {\n    // When heap or batch limit is reached, rotate out the type checker\n    if (filesInBatch > 0 && (filesInBatch >= TURBO_MAX_BATCH || isHeapOverSoftLimit())) {\n      container = factory.build();\n      pluginInfo = container.buildPluginInfo(params.pluginConfig);\n      forceGc();\n      checker = container.program.getTypeChecker();\n      filesInBatch = 0;\n    }\n\n    const sourceFile = container.getSourceFile(fileName);\n    if (!sourceFile) continue;\n\n    const { filePath, documents, warnings } = processSourceFile(\n      sourceFile,\n      container,\n      pluginInfo,\n      checker\n    );\n    filesInBatch++;\n\n    yield {\n      kind: 'FILE_TURBO',\n      filePath,\n      documents,\n      warnings,\n    };\n  }\n\n  if (uniqueGraphQLSources.size > 0) {\n    yield {\n      kind: 'GRAPHQL_SOURCES',\n      sources: Array.from(uniqueGraphQLSources.values()),\n    };\n  }\n}\n\nfunction computeSchemaFingerprints(params: TurboParams): Map<string | null, string> {\n  const fingerprints = new Map<string | null, string>();\n  const configDir = path.dirname(params.configPath);\n  for (const schemaName of getSchemaNamesFromConfig(params.pluginConfig)) {\n    const schemaConfig = getSchemaConfigForName(params.pluginConfig, schemaName || undefined);\n    const outputLocation = schemaConfig && schemaConfig.tadaOutputLocation;\n    if (!outputLocation) continue;\n\n    let contents: string;\n    try {\n      contents = fs.readFileSync(path.resolve(configDir, outputLocation), 'utf8');\n    } catch {\n      continue;\n    }\n\n    const hash = crypto.createHash('sha256').update(contents).digest('hex');\n    fingerprints.set(schemaName, `sha256:${hash.slice(0, 32)}`);\n  }\n  return fingerprints;\n}\n\nfunction getTurboOutputPath(\n  turboOutputPath: string | TurboPath[],\n  schemaName: string | null\n): string | undefined {\n  if (typeof turboOutputPath === 'string') return turboOutputPath;\n  return turboOutputPath.find((cfg) => cfg.schemaName === schemaName)?.path;\n}\n\nfunction getTurboOutputPaths(turboOutputPath: string | TurboPath[]): string[] {\n  return typeof turboOutputPath === 'string'\n    ? [turboOutputPath]\n    : turboOutputPath.map((cfg) => cfg.path);\n}\n\nlet cachedGc: (() => void) | null | undefined;\n\nfunction forceGc(): void {\n  if (cachedGc === undefined) {\n    const existing = (globalThis as { gc?: () => void }).gc;\n    if (typeof existing === 'function') {\n      cachedGc = existing;\n    } else {\n      // NOTE: If gc isn't available, try to retrieve it via `node:vm`\n      try {\n        v8.setFlagsFromString('--expose-gc');\n        cachedGc = vm.runInNewContext('gc') as () => void;\n        v8.setFlagsFromString('--no-expose-gc');\n      } catch {\n        cachedGc = null;\n      }\n    }\n  }\n  if (cachedGc) cachedGc();\n}\n\nexport const runTurbo = expose(_runTurbo);\n\nconst BUILDER_FLAGS: ts.TypeFormatFlags =\n  ts.TypeFormatFlags.NoTruncation |\n  ts.TypeFormatFlags.NoTypeReduction |\n  ts.TypeFormatFlags.InTypeAlias |\n  ts.TypeFormatFlags.UseFullyQualifiedType |\n  ts.TypeFormatFlags.GenerateNamesForShadowedTypeParams |\n  ts.TypeFormatFlags.UseAliasDefinedOutsideCurrentScope |\n  ts.TypeFormatFlags.AllowUniqueESSymbolType |\n  ts.TypeFormatFlags.WriteTypeArgumentsOfSignature;\n\nconst DECLARATION_OVERRIDE = `\nimport * as _gqlTada from 'gql.tada';\ndeclare module 'gql.tada' {\n  interface setupCache {\n    readonly __cacheDisabled: true;\n  }\n}\n`.trim();\n"],"names":["HASH_COMMENT","getHashComment","contents","node","comments","ts","getLeadingCommentRanges","pos","i","length","comment","slice","end","match","exec","CACHE_BUSTER","createDocumentHasher","context","callExpressionCache","WeakMap","symbolCallCache","Map","activeCalls","WeakSet","hashCallExpression","callExpression","schemaName","schemaKey","cached","get","has","hashable","add","result","computeCallExpressionHash","delete","schemaCache","set","documentText","getStaticStringValue","expression","unwrapExpression","isStringLiteral","isNoSubstitutionTemplateLiteral","text","arguments","fragmentHashes","getFragmentHashes","hash","crypto","createHash","addHashPart","schemaFingerprints","fragmentHash","documentHash","digest","fragmentsExpression","isArrayLiteralExpression","hashes","element","elements","isSpreadElement","spreadHashes","push","documentCall","resolveDocumentCallExpression","declarationExpression","resolveDeclarationInitializer","isCallExpression","symbol","getSymbol","undefined","resolveSymbolCallExpression","declaration","declarations","isVariableDeclaration","initializer","checker","getSymbolAtLocation","flags","SymbolFlags","Alias","getAliasedSymbol","isParenthesizedExpression","isAsExpression","isTypeAssertionExpression","isSatisfiesExpression","isNonNullExpression","part","update","HEAP_SOFT_LIMIT_BYTES","traceCallToImportSource","sourceFile","program","cache","identifier","isIdentifier","isPropertyAccessExpression","traceKey","fileName","traces","getTypeChecker","importDeclaration","findImportDeclaration","moduleSpecifier","resolveModulePath","current","isImportDeclaration","parent","moduleName","containingFile","compilerOptions","getCompilerOptions","host","createCompilerHost","resolutionCache","createModuleResolutionCache","getCurrentDirectory","getCanonicalFileName","bind","resolved","resolveModuleName","resolvedModule","resolvedFileName","collectImportsFromSourceFile","pluginConfig","rootPath","turboOutputPath","shouldTreatImportsAsNodeNext","imports","tadaImportPaths","getTadaOutputPaths","paths","tadaOutputLocation","path","resolve","schemaConfig","schemas","statements","specifier","isTadaImport","importClause","getFullText","trim","adjustedSpecifier","endsWith","replace","includes","importSpecifier","sourceFilePath","tadaOutputLocationPaths","resolvedImportPath","some","tadaOutputLocationPath","startsWith","sourceDir","dirname","absoluteImportPath","tadaPath","async","_runTurbo","params","schemaNames","getSchemaNamesFromConfig","factory","programFactory","cachedDocumentsByPath","getCachedDocuments","getTurboOutputPath","cachedDocuments","readCachedTurboDocuments","cachePath","documents","fs","existsSync","readFileSync","createSourceFile","ScriptTarget","Latest","ScriptKind","TS","visit","isInterfaceDeclaration","name","member","members","isPropertySignature","type","isNumericLiteral","JSON","stringify","documentType","getText","forEachChild","addSourceFile","fileId","sourceText","DECLARATION_OVERRIDE","scriptKind","externalFiles","createExternalFiles","kind","addVirtualFiles","container","build","pluginInfo","buildPluginInfo","turboOutputPaths","Set","getTurboOutputPaths","map","cfg","fileNames","rootFileNames","filter","shouldScanTurboFile","fileCount","uniqueGraphQLSources","importTraceCache","processSourceFile","filePath","warnings","hasGraphQLDocumentCandidate","calls","findAllCallExpressions","searchExternal","collectFragments","nodes","call","position","getSourcePosition","getStart","schema","message","size","file","line","col","graphqlSourcePath","graphqlSourceFile","getSourceFile","turboPath","wasOriginallyNodeNext","absolutePath","argumentKey","documentHasher","cachedDocument","isCached","returnType","getTypeAtLocation","getEscapedName","typeToString","BUILDER_FLAGS","isHeapOverSoftLimit","process","memoryUsage","heapUsed","forceGc","computeSchemaFingerprints","filesInBatch","sources","Array","from","values","fingerprints","configDir","configPath","getSchemaConfigForName","outputLocation","find","cachedGc","existing","globalThis","gc","v8","setFlagsFromString","vm","runInNewContext","runTurbo","expose","TypeFormatFlags","NoTruncation","NoTypeReduction","InTypeAlias","UseFullyQualifiedType","GenerateNamesForShadowedTypeParams","UseAliasD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