@soda-gql/tools 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +72 -0
  2. package/codegen.d.ts +2 -0
  3. package/codegen.js +1 -0
  4. package/dist/bin.cjs +15509 -0
  5. package/dist/bin.cjs.map +1 -0
  6. package/dist/bin.d.cts +839 -0
  7. package/dist/bin.d.cts.map +1 -0
  8. package/dist/chunk-BrXtsOCC.cjs +41 -0
  9. package/dist/codegen.cjs +4704 -0
  10. package/dist/codegen.cjs.map +1 -0
  11. package/dist/codegen.d.cts +416 -0
  12. package/dist/codegen.d.cts.map +1 -0
  13. package/dist/codegen.d.mts +416 -0
  14. package/dist/codegen.d.mts.map +1 -0
  15. package/dist/codegen.mjs +4712 -0
  16. package/dist/codegen.mjs.map +1 -0
  17. package/dist/formatter-Glj5a663.cjs +510 -0
  18. package/dist/formatter-Glj5a663.cjs.map +1 -0
  19. package/dist/formatter.cjs +509 -0
  20. package/dist/formatter.cjs.map +1 -0
  21. package/dist/formatter.d.cts +33 -0
  22. package/dist/formatter.d.cts.map +1 -0
  23. package/dist/formatter.d.mts +33 -0
  24. package/dist/formatter.d.mts.map +1 -0
  25. package/dist/formatter.mjs +507 -0
  26. package/dist/formatter.mjs.map +1 -0
  27. package/dist/index.cjs +13 -0
  28. package/dist/index.cjs.map +1 -0
  29. package/dist/index.d.cts +11 -0
  30. package/dist/index.d.cts.map +1 -0
  31. package/dist/index.d.mts +11 -0
  32. package/dist/index.d.mts.map +1 -0
  33. package/dist/index.mjs +12 -0
  34. package/dist/index.mjs.map +1 -0
  35. package/dist/typegen.cjs +864 -0
  36. package/dist/typegen.cjs.map +1 -0
  37. package/dist/typegen.d.cts +205 -0
  38. package/dist/typegen.d.cts.map +1 -0
  39. package/dist/typegen.d.mts +205 -0
  40. package/dist/typegen.d.mts.map +1 -0
  41. package/dist/typegen.mjs +859 -0
  42. package/dist/typegen.mjs.map +1 -0
  43. package/formatter.d.ts +2 -0
  44. package/formatter.js +1 -0
  45. package/index.d.ts +2 -0
  46. package/index.js +1 -0
  47. package/package.json +102 -0
  48. package/typegen.d.ts +2 -0
  49. package/typegen.js +1 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typegen.cjs","names":["warnings: string[]","builderErrors","outputFormatters: TypeFormatters","inputFormatters: TypeFormatters","Kind","lines: string[]","formatters: TypeFormatters","lines: string[]","module","declaration: ImportDeclaration | null","warnings: string[]","warnings: string[]","fg","warnings: string[]","Kind","extensionMap: Record<string, string>","withPrefix","currentExt"],"sources":["../src/typegen/emitter.ts","../src/typegen/errors.ts","../src/typegen/template-extractor.ts","../src/typegen/template-scanner.ts","../src/typegen/template-to-selections.ts","../src/typegen/runner.ts"],"sourcesContent":["/**\n * Prebuilt types emitter.\n *\n * Generates TypeScript type definitions for PrebuiltTypes registry\n * from field selection data and schema.\n *\n * ## Error Handling Strategy\n *\n * The emitter uses a partial failure approach for type calculation errors:\n *\n * **Recoverable errors** (result in warnings, element skipped):\n * - Type calculation failures (e.g., `calculateFieldsType` throws)\n * - Input type generation failures (e.g., `generateInputType` throws)\n * - These are caught per-element, logged as warnings, and the element is omitted\n *\n * **Fatal errors** (result in error result):\n * - `SCHEMA_NOT_FOUND`: Selection references non-existent schema\n * - `WRITE_FAILED`: Cannot write output file to disk\n *\n * This allows builds to succeed with partial type coverage when some elements\n * have issues, while providing visibility into problems via warnings.\n *\n * @module\n */\n\nimport { writeFile } from \"node:fs/promises\";\nimport { join } from \"node:path\";\nimport { type BuilderError, builderErrors, type FieldSelectionsMap } from \"@soda-gql/builder\";\nimport type { AnyGraphqlSchema, InputTypeSpecifiers, TypeFormatters } from \"@soda-gql/core\";\nimport {\n calculateFieldsType,\n generateInputObjectType,\n generateInputType,\n generateInputTypeFromVarDefs,\n parseInputSpecifier,\n} from \"@soda-gql/core\";\nimport { Kind, type TypeNode, type VariableDefinitionNode } from \"graphql\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport type { TypegenError } from \"./errors\";\n\n/**\n * Options for emitting prebuilt types.\n */\nexport type PrebuiltTypesEmitterOptions = {\n /**\n * Schema definitions per schema name.\n * These come from the codegen output.\n */\n readonly schemas: Record<string, AnyGraphqlSchema>;\n /**\n * Field selections extracted from the builder.\n */\n readonly fieldSelections: FieldSelectionsMap;\n /**\n * Output directory (where types.prebuilt.ts should be written).\n * This should be the same as config.outdir.\n */\n readonly outdir: string;\n /**\n * Relative import path to _internal-injects.ts from types.prebuilt.ts.\n * Example: \"./_internal-injects\"\n */\n readonly injectsModulePath: string;\n};\n\ntype PrebuiltFragmentEntry = {\n readonly key: string;\n readonly typename: string;\n readonly inputType: string;\n readonly outputType: string;\n};\n\ntype PrebuiltOperationEntry = {\n readonly key: string;\n readonly inputType: string;\n readonly outputType: string;\n};\n\ntype SchemaGroup = {\n fragments: PrebuiltFragmentEntry[];\n operations: PrebuiltOperationEntry[];\n inputObjects: Set<string>;\n};\n\ntype GroupBySchemaResult = {\n readonly grouped: Map<string, SchemaGroup>;\n readonly warnings: string[];\n readonly skippedFragmentCount: number;\n};\n\n/**\n * Group field selections by schema.\n * Uses the schemaLabel from each selection to group them correctly.\n *\n * Fragments without a 'key' property are skipped (not included in PrebuiltTypes)\n * and a warning is added. This allows projects to use fragments without keys\n * while still generating prebuilt types for those that have keys.\n *\n * @returns Result containing grouped selections and warnings, or error if schema not found\n */\nconst groupBySchema = (\n fieldSelections: FieldSelectionsMap,\n schemas: Record<string, AnyGraphqlSchema>,\n): Result<GroupBySchemaResult, BuilderError | TypegenError> => {\n const grouped = new Map<string, SchemaGroup>();\n const warnings: string[] = [];\n let skippedFragmentCount = 0;\n\n // Initialize groups for each schema\n for (const schemaName of Object.keys(schemas)) {\n grouped.set(schemaName, { fragments: [], operations: [], inputObjects: new Set() });\n }\n\n for (const [canonicalId, selection] of fieldSelections) {\n // Use schemaLabel to determine which schema this selection belongs to\n const schemaName = selection.schemaLabel;\n const schema = schemas[schemaName];\n const group = grouped.get(schemaName);\n\n if (!schema || !group) {\n return err(builderErrors.schemaNotFound(schemaName, canonicalId));\n }\n\n // Create formatters for schema-specific type names\n const outputFormatters: TypeFormatters = {\n scalarOutput: (name) => `ScalarOutput_${schemaName}<\"${name}\">`,\n };\n const inputFormatters: TypeFormatters = {\n scalarInput: (name) => `ScalarInput_${schemaName}<\"${name}\">`,\n inputObject: (name) => `Input_${schemaName}_${name}`,\n };\n\n if (selection.type === \"fragment\") {\n // Skip fragments without keys (they won't be included in PrebuiltTypes)\n if (!selection.key) {\n skippedFragmentCount++;\n warnings.push(\n `[prebuilt] Fragment \"${canonicalId}\" skipped: missing 'key' property. ` +\n `Use tagged template syntax fragment(\"Name\", \"Type\")\\`{ ... }\\` to auto-assign a key, ` +\n `or set 'key' explicitly in the callback builder.`,\n );\n continue;\n }\n\n try {\n // Collect input objects used in fragment variables\n const usedInputObjects = collectUsedInputObjectsFromVarDefs(schema, selection.variableDefinitions);\n for (const inputName of usedInputObjects) {\n group.inputObjects.add(inputName);\n }\n\n // Generate output type with schema-specific scalar names\n const outputType = calculateFieldsType(schema, selection.fields, outputFormatters, selection.typename);\n\n // Generate input type from variableDefinitions with schema-specific names\n const hasVariables = Object.keys(selection.variableDefinitions).length > 0;\n const inputType = hasVariables\n ? generateInputTypeFromVarDefs(schema, selection.variableDefinitions, { formatters: inputFormatters })\n : \"void\";\n\n group.fragments.push({\n key: selection.key,\n typename: selection.typename,\n inputType,\n outputType,\n });\n } catch (error) {\n warnings.push(\n `[prebuilt] Failed to calculate type for fragment \"${selection.key}\": ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n } else if (selection.type === \"operation\") {\n try {\n // Collect input objects used in this operation\n const usedInputObjects = collectUsedInputObjects(schema, selection.variableDefinitions);\n for (const inputName of usedInputObjects) {\n group.inputObjects.add(inputName);\n }\n\n // Generate output type with schema-specific scalar names\n // Get the root type name from schema operations (Query, Mutation, Subscription)\n const rootTypeName = schema.operations[selection.operationType as keyof typeof schema.operations];\n const outputType = calculateFieldsType(schema, selection.fields, outputFormatters, rootTypeName ?? undefined);\n\n // Generate input type with schema-specific scalar and input object names\n const inputType = generateInputType(schema, selection.variableDefinitions, inputFormatters);\n\n group.operations.push({\n key: selection.operationName,\n inputType,\n outputType,\n });\n } catch (error) {\n warnings.push(\n `[prebuilt] Failed to calculate type for operation \"${selection.operationName}\": ${error instanceof Error ? error.message : String(error)}`,\n );\n }\n }\n }\n\n return ok({ grouped, warnings, skippedFragmentCount });\n};\n\n/**\n * Extract input object names from a GraphQL TypeNode.\n */\nconst extractInputObjectsFromType = (schema: AnyGraphqlSchema, typeNode: TypeNode, inputObjects: Set<string>): void => {\n switch (typeNode.kind) {\n case Kind.NON_NULL_TYPE:\n extractInputObjectsFromType(schema, typeNode.type, inputObjects);\n break;\n case Kind.LIST_TYPE:\n extractInputObjectsFromType(schema, typeNode.type, inputObjects);\n break;\n case Kind.NAMED_TYPE: {\n const name = typeNode.name.value;\n // Check if it's an input object (not a scalar or enum)\n if (!schema.scalar[name] && !schema.enum[name] && schema.input[name]) {\n inputObjects.add(name);\n }\n break;\n }\n }\n};\n\n/**\n * Recursively collect nested input objects from schema definitions.\n * Takes a set of initial input names and expands to include all nested inputs.\n */\nconst collectNestedInputObjects = (schema: AnyGraphqlSchema, initialInputNames: Set<string>): Set<string> => {\n const inputObjects = new Set(initialInputNames);\n\n const collectNested = (inputName: string, seen: Set<string>): void => {\n if (seen.has(inputName)) {\n return;\n }\n seen.add(inputName);\n\n const inputDef = schema.input[inputName];\n if (!inputDef) {\n return;\n }\n\n for (const fieldSpec of Object.values(inputDef.fields)) {\n const parsed = parseInputSpecifier(fieldSpec);\n if (parsed.kind === \"input\" && !inputObjects.has(parsed.name)) {\n inputObjects.add(parsed.name);\n collectNested(parsed.name, seen);\n }\n }\n };\n\n for (const inputName of Array.from(initialInputNames)) {\n collectNested(inputName, new Set());\n }\n\n return inputObjects;\n};\n\n/**\n * Collect all input object types used in variable definitions.\n * Recursively collects nested input objects from the schema.\n */\nconst collectUsedInputObjects = (\n schema: AnyGraphqlSchema,\n variableDefinitions: readonly VariableDefinitionNode[],\n): Set<string> => {\n const directInputs = new Set<string>();\n for (const varDef of variableDefinitions) {\n extractInputObjectsFromType(schema, varDef.type, directInputs);\n }\n return collectNestedInputObjects(schema, directInputs);\n};\n\n/**\n * Collect all input object types used in InputTypeSpecifiers.\n * Recursively collects nested input objects from the schema.\n */\nconst _collectUsedInputObjectsFromSpecifiers = (schema: AnyGraphqlSchema, specifiers: InputTypeSpecifiers): Set<string> => {\n const directInputs = new Set<string>();\n for (const specStr of Object.values(specifiers)) {\n const parsed = parseInputSpecifier(specStr);\n if (parsed.kind === \"input\" && schema.input[parsed.name]) {\n directInputs.add(parsed.name);\n }\n }\n return collectNestedInputObjects(schema, directInputs);\n};\n\n/**\n * Collect all input object types used in VariableDefinitions (VarSpecifier objects).\n * Used for fragment variable definitions.\n */\nconst collectUsedInputObjectsFromVarDefs = (\n schema: AnyGraphqlSchema,\n varDefs: Record<string, { kind: string; name: string }>,\n): Set<string> => {\n const directInputs = new Set<string>();\n for (const varSpec of Object.values(varDefs)) {\n if (varSpec.kind === \"input\" && schema.input[varSpec.name]) {\n directInputs.add(varSpec.name);\n }\n }\n return collectNestedInputObjects(schema, directInputs);\n};\n\n/**\n * Generate type definitions for input objects.\n */\nconst generateInputObjectTypeDefinitions = (schema: AnyGraphqlSchema, schemaName: string, inputNames: Set<string>): string[] => {\n const lines: string[] = [];\n\n // Get depth config from schema (optional properties defined in AnyGraphqlSchema)\n const defaultDepth = schema.__defaultInputDepth ?? 3;\n const depthOverrides = schema.__inputDepthOverrides ?? {};\n\n // Create formatters for schema-specific type names\n const formatters: TypeFormatters = {\n scalarInput: (name) => `ScalarInput_${schemaName}<\"${name}\">`,\n inputObject: (name) => `Input_${schemaName}_${name}`,\n };\n\n // Sort for deterministic output\n const sortedNames = Array.from(inputNames).sort();\n\n for (const inputName of sortedNames) {\n const typeString = generateInputObjectType(schema, inputName, {\n defaultDepth,\n depthOverrides,\n formatters,\n });\n\n lines.push(`export type Input_${schemaName}_${inputName} = ${typeString};`);\n }\n\n return lines;\n};\n\n/**\n * Generate the TypeScript code for prebuilt types.\n */\nconst generateTypesCode = (\n grouped: Map<string, SchemaGroup>,\n schemas: Record<string, AnyGraphqlSchema>,\n injectsModulePath: string,\n): string => {\n const schemaNames = Object.keys(schemas);\n\n const lines: string[] = [\n \"/**\",\n \" * Prebuilt type registry.\",\n \" *\",\n \" * This file is auto-generated by @soda-gql/tools/typegen.\",\n \" * Do not edit manually.\",\n \" *\",\n \" * @module\",\n \" * @generated\",\n \" */\",\n \"\",\n 'import type { AssertExtends, PrebuiltTypeRegistry } from \"@soda-gql/core\";',\n ];\n\n // Generate import from _internal-injects.ts\n const scalarImports = schemaNames.map((name) => `scalar_${name}`).join(\", \");\n lines.push(`import type { ${scalarImports} } from \"${injectsModulePath}\";`);\n\n lines.push(\"\");\n\n // Generate ScalarInput and ScalarOutput helper types\n for (const schemaName of schemaNames) {\n lines.push(\n `type ScalarInput_${schemaName}<T extends keyof typeof scalar_${schemaName}> = ` +\n `typeof scalar_${schemaName}[T][\"$type\"][\"input\"];`,\n );\n lines.push(\n `type ScalarOutput_${schemaName}<T extends keyof typeof scalar_${schemaName}> = ` +\n `typeof scalar_${schemaName}[T][\"$type\"][\"output\"];`,\n );\n }\n\n lines.push(\"\");\n\n for (const [schemaName, { fragments, operations, inputObjects }] of grouped) {\n const schema = schemas[schemaName];\n\n // Generate input object type definitions if there are any\n if (inputObjects.size > 0 && schema) {\n lines.push(\"// Input object types\");\n const inputTypeLines = generateInputObjectTypeDefinitions(schema, schemaName, inputObjects);\n lines.push(...inputTypeLines);\n lines.push(\"\");\n }\n\n // Generate fragments type (deduplicate by key — last occurrence wins)\n const deduplicatedFragments = new Map<string, PrebuiltFragmentEntry>();\n for (const f of fragments) {\n deduplicatedFragments.set(f.key, f);\n }\n const fragmentEntries = Array.from(deduplicatedFragments.values())\n .sort((a, b) => a.key.localeCompare(b.key))\n .map(\n (f) =>\n ` readonly \"${f.key}\": { readonly typename: \"${f.typename}\"; readonly input: ${f.inputType}; readonly output: ${f.outputType} };`,\n );\n\n // Generate operations type (deduplicate by key — last occurrence wins)\n const deduplicatedOperations = new Map<string, PrebuiltOperationEntry>();\n for (const o of operations) {\n deduplicatedOperations.set(o.key, o);\n }\n const operationEntries = Array.from(deduplicatedOperations.values())\n .sort((a, b) => a.key.localeCompare(b.key))\n .map((o) => ` readonly \"${o.key}\": { readonly input: ${o.inputType}; readonly output: ${o.outputType} };`);\n\n lines.push(`export type PrebuiltTypes_${schemaName} = {`);\n lines.push(\" readonly fragments: {\");\n if (fragmentEntries.length > 0) {\n lines.push(...fragmentEntries);\n }\n lines.push(\" };\");\n lines.push(\" readonly operations: {\");\n if (operationEntries.length > 0) {\n lines.push(...operationEntries);\n }\n lines.push(\" };\");\n lines.push(\"};\");\n lines.push(`type _AssertPrebuiltTypes_${schemaName} = AssertExtends<PrebuiltTypes_${schemaName}, PrebuiltTypeRegistry>;`);\n lines.push(\"\");\n }\n\n return lines.join(\"\\n\");\n};\n\n/**\n * Result of emitting prebuilt types.\n */\nexport type PrebuiltTypesEmitResult = {\n readonly path: string;\n readonly warnings: readonly string[];\n readonly skippedFragmentCount: number;\n};\n\n/**\n * Emit prebuilt types to the types.prebuilt.ts file.\n *\n * This function uses a partial failure strategy: if type calculation fails for\n * individual elements (e.g., due to invalid field selections or missing schema\n * types), those elements are skipped and warnings are collected rather than\n * failing the entire emission. This allows builds to succeed even when some\n * elements have issues, while still reporting problems via warnings.\n *\n * @param options - Emitter options including schemas, field selections, and output directory\n * @returns Result containing output path and warnings, or error if a hard failure occurs\n *\n * @example\n * ```typescript\n * const result = await emitPrebuiltTypes({\n * schemas: { mySchema: schema },\n * fieldSelections,\n * outdir: \"./generated\",\n * injects: { mySchema: { scalars: \"./scalars.ts\" } },\n * });\n *\n * if (result.isOk()) {\n * console.log(`Generated: ${result.value.path}`);\n * if (result.value.warnings.length > 0) {\n * console.warn(\"Warnings:\", result.value.warnings);\n * }\n * }\n * ```\n */\nexport const emitPrebuiltTypes = async (\n options: PrebuiltTypesEmitterOptions,\n): Promise<Result<PrebuiltTypesEmitResult, BuilderError | TypegenError>> => {\n const { schemas, fieldSelections, outdir, injectsModulePath } = options;\n\n // Group selections by schema\n const groupResult = groupBySchema(fieldSelections, schemas);\n if (groupResult.isErr()) {\n return err(groupResult.error);\n }\n const { grouped, warnings, skippedFragmentCount } = groupResult.value;\n\n // Generate the types code\n const code = generateTypesCode(grouped, schemas, injectsModulePath);\n\n // Write to types.prebuilt.ts\n const typesPath = join(outdir, \"types.prebuilt.ts\");\n\n try {\n await writeFile(typesPath, code, \"utf-8\");\n return ok({ path: typesPath, warnings, skippedFragmentCount });\n } catch (error) {\n return err(\n builderErrors.writeFailed(\n typesPath,\n `Failed to write prebuilt types: ${error instanceof Error ? error.message : String(error)}`,\n error,\n ),\n );\n }\n};\n","/**\n * Error types for typegen package.\n *\n * @module\n */\n\nimport type { BuilderError } from \"@soda-gql/builder\";\n\n/**\n * Error codes specific to typegen operations.\n */\nexport type TypegenErrorCode = \"TYPEGEN_CODEGEN_REQUIRED\" | \"TYPEGEN_SCHEMA_LOAD_FAILED\" | \"TYPEGEN_BUILD_FAILED\";\n\n/**\n * Typegen-specific error type.\n */\nexport type TypegenSpecificError =\n | {\n readonly code: \"TYPEGEN_CODEGEN_REQUIRED\";\n readonly message: string;\n readonly outdir: string;\n }\n | {\n readonly code: \"TYPEGEN_SCHEMA_LOAD_FAILED\";\n readonly message: string;\n readonly schemaNames: readonly string[];\n readonly cause?: unknown;\n }\n | {\n readonly code: \"TYPEGEN_BUILD_FAILED\";\n readonly message: string;\n readonly cause?: unknown;\n };\n\n/**\n * Union of all typegen errors (specific + builder errors).\n */\nexport type TypegenError = TypegenSpecificError | BuilderError;\n\n/**\n * Error constructor helpers for concise error creation.\n */\nexport const typegenErrors = {\n codegenRequired: (outdir: string): TypegenSpecificError => ({\n code: \"TYPEGEN_CODEGEN_REQUIRED\",\n message: `Generated graphql-system module not found at '${outdir}'. Run 'soda-gql codegen' first.`,\n outdir,\n }),\n\n schemaLoadFailed: (schemaNames: readonly string[], cause?: unknown): TypegenSpecificError => ({\n code: \"TYPEGEN_SCHEMA_LOAD_FAILED\",\n message: `Failed to load schemas: ${schemaNames.join(\", \")}`,\n schemaNames,\n cause,\n }),\n\n buildFailed: (message: string, cause?: unknown): TypegenSpecificError => ({\n code: \"TYPEGEN_BUILD_FAILED\",\n message,\n cause,\n }),\n} as const;\n\n/**\n * Format TypegenError for console output (human-readable).\n */\nexport const formatTypegenError = (error: TypegenError): string => {\n const lines: string[] = [];\n\n lines.push(`Error [${error.code}]: ${error.message}`);\n\n switch (error.code) {\n case \"TYPEGEN_CODEGEN_REQUIRED\":\n lines.push(` Output directory: ${error.outdir}`);\n lines.push(\" Hint: Run 'soda-gql codegen' to generate the graphql-system module first.\");\n break;\n case \"TYPEGEN_SCHEMA_LOAD_FAILED\":\n lines.push(` Schemas: ${error.schemaNames.join(\", \")}`);\n break;\n }\n\n if (\"cause\" in error && error.cause) {\n lines.push(` Caused by: ${error.cause}`);\n }\n\n return lines.join(\"\\n\");\n};\n","/**\n * Template extractor for typegen.\n *\n * Extracts tagged template GraphQL content from TypeScript source files\n * using SWC parsing. Uses shared extraction logic from @soda-gql/common\n * but simplified for batch extraction (no position tracking, no state management).\n *\n * @module\n */\n\nimport type { GraphqlSystemIdentifyHelper } from \"@soda-gql/builder\";\nimport type { ExtractedTemplate } from \"@soda-gql/common/template-extraction\";\nimport { walkAndExtract } from \"@soda-gql/common/template-extraction\";\n\nimport { parseSync } from \"@swc/core\";\nimport type { ImportDeclaration, Module, Node } from \"@swc/types\";\n\nexport type { ExtractedTemplate, OperationKind } from \"@soda-gql/common/template-extraction\";\n\n/** Result of extracting templates from a source file. */\nexport type ExtractionResult = {\n readonly templates: readonly ExtractedTemplate[];\n readonly warnings: readonly string[];\n};\n\n/**\n * Parse TypeScript source with SWC, returning null on failure.\n */\nconst safeParseSync = (source: string, tsx: boolean): ReturnType<typeof parseSync> | null => {\n try {\n return parseSync(source, {\n syntax: \"typescript\",\n tsx,\n decorators: false,\n dynamicImport: true,\n });\n } catch {\n return null;\n }\n};\n\n/**\n * Collect gql identifiers from import declarations.\n * Finds imports like `import { gql } from \"./graphql-system\"`.\n */\nconst collectGqlIdentifiers = (module: Module, filePath: string, helper: GraphqlSystemIdentifyHelper): ReadonlySet<string> => {\n const identifiers = new Set<string>();\n\n for (const item of module.body) {\n let declaration: ImportDeclaration | null = null;\n\n if (item.type === \"ImportDeclaration\") {\n declaration = item;\n } else if (\n \"declaration\" in item &&\n item.declaration &&\n // biome-ignore lint/suspicious/noExplicitAny: SWC AST type checking\n (item.declaration as any).type === \"ImportDeclaration\"\n ) {\n declaration = item.declaration as unknown as ImportDeclaration;\n }\n\n if (!declaration) {\n continue;\n }\n\n if (!helper.isGraphqlSystemImportSpecifier({ filePath, specifier: declaration.source.value })) {\n continue;\n }\n\n for (const specifier of declaration.specifiers ?? []) {\n if (specifier.type === \"ImportSpecifier\") {\n const imported = specifier.imported ? specifier.imported.value : specifier.local.value;\n if (imported === \"gql\" && !specifier.imported) {\n identifiers.add(specifier.local.value);\n }\n }\n }\n }\n\n return identifiers;\n};\n\n/**\n * Extract all tagged templates from a TypeScript source file.\n *\n * @param filePath - Absolute path to the source file (used for import resolution)\n * @param source - TypeScript source code\n * @param helper - GraphQL system identifier for resolving gql imports\n * @returns Extracted templates and any warnings\n */\nexport const extractTemplatesFromSource = (\n filePath: string,\n source: string,\n helper: GraphqlSystemIdentifyHelper,\n): ExtractionResult => {\n const warnings: string[] = [];\n const isTsx = filePath.endsWith(\".tsx\");\n\n const program = safeParseSync(source, isTsx);\n if (!program || program.type !== \"Module\") {\n if (source.includes(\"gql\")) {\n warnings.push(`[typegen-extract] Failed to parse ${filePath}`);\n }\n return { templates: [], warnings };\n }\n\n const gqlIdentifiers = collectGqlIdentifiers(program, filePath, helper);\n if (gqlIdentifiers.size === 0) {\n return { templates: [], warnings };\n }\n\n return { templates: walkAndExtract(program as unknown as Node, gqlIdentifiers), warnings };\n};\n","/**\n * Source file scanner for tagged template extraction.\n *\n * Discovers source files from config include/exclude patterns,\n * reads them, and extracts tagged templates using the template extractor.\n *\n * @module\n */\n\nimport { readFileSync } from \"node:fs\";\nimport { normalize, resolve } from \"node:path\";\nimport type { GraphqlSystemIdentifyHelper } from \"@soda-gql/builder\";\nimport fg from \"fast-glob\";\nimport { type ExtractedTemplate, extractTemplatesFromSource } from \"./template-extractor\";\n\nexport type ScanSourceFilesOptions = {\n /** Glob patterns for source files to include. */\n readonly include: readonly string[];\n /** Glob patterns for source files to exclude. */\n readonly exclude: readonly string[];\n /** Base directory for resolving glob patterns. */\n readonly baseDir: string;\n /** Helper for identifying graphql-system imports. */\n readonly helper: GraphqlSystemIdentifyHelper;\n};\n\nexport type ScanResult = {\n /** Templates keyed by file path. */\n readonly templates: ReadonlyMap<string, readonly ExtractedTemplate[]>;\n /** Warnings from scanning. */\n readonly warnings: readonly string[];\n};\n\n/**\n * Scan source files for tagged templates.\n *\n * Uses fast-glob to discover files matching include/exclude patterns,\n * then extracts tagged templates from each file.\n */\nexport const scanSourceFiles = (options: ScanSourceFilesOptions): ScanResult => {\n const { include, exclude, baseDir, helper } = options;\n const warnings: string[] = [];\n\n // Build exclusion patterns\n const ignorePatterns = exclude.map((pattern) => (pattern.startsWith(\"!\") ? pattern.slice(1) : pattern));\n\n // Discover files via fast-glob\n const matchedFiles = fg.sync(include as string[], {\n cwd: baseDir,\n ignore: ignorePatterns,\n onlyFiles: true,\n absolute: true,\n });\n\n const templates = new Map<string, readonly ExtractedTemplate[]>();\n\n for (const filePath of matchedFiles) {\n const normalizedPath = normalize(resolve(filePath)).replace(/\\\\/g, \"/\");\n\n try {\n const source = readFileSync(normalizedPath, \"utf-8\");\n const { templates: extracted, warnings: extractionWarnings } = extractTemplatesFromSource(normalizedPath, source, helper);\n warnings.push(...extractionWarnings);\n\n if (extracted.length > 0) {\n templates.set(normalizedPath, extracted);\n }\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n warnings.push(`[typegen-scan] Failed to read ${normalizedPath}: ${message}`);\n }\n }\n\n return { templates, warnings };\n};\n","/**\n * Converts extracted tagged template GraphQL content into FieldSelectionData.\n *\n * Takes the output of template-extractor and produces FieldSelectionData entries\n * compatible with the emitter pipeline. Uses the shared field-building utilities\n * from core to produce AnyFieldsExtended from GraphQL AST.\n *\n * @module\n */\n\nimport type { FieldSelectionData, FieldSelectionsMap } from \"@soda-gql/builder\";\nimport type { CanonicalId } from \"@soda-gql/common\";\nimport {\n type AnyGraphqlSchema,\n buildFieldsFromSelectionSet,\n createSchemaIndexFromSchema,\n extractFragmentVariables,\n preprocessFragmentArgs,\n} from \"@soda-gql/core\";\nimport { Kind, parse as parseGraphql, type SelectionSetNode } from \"graphql\";\nimport type { ExtractedTemplate } from \"./template-extractor\";\n\n/** Result of converting templates to field selections. */\nexport type TemplateConversionResult = {\n readonly selections: FieldSelectionsMap;\n readonly warnings: readonly string[];\n};\n\n/**\n * Convert extracted templates into field selections for the emitter.\n *\n * @param templates - Templates extracted from source files, keyed by file path\n * @param schemas - Loaded schema objects keyed by schema name\n * @returns Map of canonical IDs to field selection data, plus any warnings\n */\nexport const convertTemplatesToSelections = (\n templates: ReadonlyMap<string, readonly ExtractedTemplate[]>,\n schemas: Record<string, AnyGraphqlSchema>,\n): TemplateConversionResult => {\n const selections = new Map<CanonicalId, FieldSelectionData>();\n const warnings: string[] = [];\n\n // Build schema indexes once per schema\n const schemaIndexes = new Map(Object.entries(schemas).map(([name, schema]) => [name, createSchemaIndexFromSchema(schema)]));\n\n for (const [filePath, fileTemplates] of templates) {\n for (const template of fileTemplates) {\n const schema = schemas[template.schemaName];\n if (!schema) {\n warnings.push(`[typegen-template] Unknown schema \"${template.schemaName}\" in ${filePath}`);\n continue;\n }\n\n const schemaIndex = schemaIndexes.get(template.schemaName);\n if (!schemaIndex) {\n continue;\n }\n\n try {\n if (template.kind === \"fragment\") {\n const selection = convertFragmentTemplate(template, schema, filePath);\n if (selection) {\n selections.set(selection.id, selection.data);\n }\n } else {\n const selection = convertOperationTemplate(template, schema, filePath);\n if (selection) {\n selections.set(selection.id, selection.data);\n }\n }\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n warnings.push(`[typegen-template] Failed to process ${template.kind} in ${filePath}: ${message}`);\n }\n }\n }\n\n return { selections, warnings };\n};\n\n/**\n * Recursively filter out __FRAG_SPREAD_ placeholder nodes from a selection set.\n * These placeholders are created by template-extractor for interpolated fragment references.\n * buildFieldsFromSelectionSet would throw on them since no interpolationMap is available.\n */\nconst filterPlaceholderSpreads = (selectionSet: SelectionSetNode): SelectionSetNode => ({\n ...selectionSet,\n selections: selectionSet.selections\n .filter((sel) => !(sel.kind === Kind.FRAGMENT_SPREAD && sel.name.value.startsWith(\"__FRAG_SPREAD_\")))\n .map((sel) => {\n if (sel.kind === Kind.FIELD && sel.selectionSet) {\n return { ...sel, selectionSet: filterPlaceholderSpreads(sel.selectionSet) };\n }\n if (sel.kind === Kind.INLINE_FRAGMENT && sel.selectionSet) {\n return { ...sel, selectionSet: filterPlaceholderSpreads(sel.selectionSet) };\n }\n return sel;\n }),\n});\n\n/** Simple matching-paren finder for template content (no comments/strings to handle). */\nconst findClosingParen = (source: string, openIndex: number): number => {\n let depth = 0;\n for (let i = openIndex; i < source.length; i++) {\n if (source[i] === \"(\") depth++;\n else if (source[i] === \")\") {\n depth--;\n if (depth === 0) return i;\n }\n }\n return -1;\n};\n\n/**\n * Reconstruct full GraphQL source from an extracted template.\n * For curried syntax (new), prepends the definition header from tag call arguments.\n * For curried fragments with Fragment Arguments, repositions variable declarations\n * before the on-clause to produce RFC-compliant syntax.\n * For old syntax, returns content as-is.\n */\nconst reconstructGraphql = (template: ExtractedTemplate): string => {\n if (template.elementName) {\n if (template.kind === \"fragment\" && template.typeName) {\n const trimmed = template.content.trim();\n if (trimmed.startsWith(\"(\")) {\n const closeIdx = findClosingParen(trimmed, 0);\n if (closeIdx !== -1) {\n const varDecls = trimmed.slice(0, closeIdx + 1);\n const selectionSet = trimmed.slice(closeIdx + 1).trim();\n return `fragment ${template.elementName}${varDecls} on ${template.typeName} ${selectionSet}`;\n }\n }\n return `fragment ${template.elementName} on ${template.typeName} ${trimmed}`;\n }\n return `${template.kind} ${template.elementName} ${template.content}`;\n }\n return template.content;\n};\n\n/**\n * Convert a fragment template into FieldSelectionData.\n */\nconst convertFragmentTemplate = (\n template: ExtractedTemplate,\n schema: AnyGraphqlSchema,\n filePath: string,\n): { id: CanonicalId; data: FieldSelectionData } | null => {\n const schemaIndex = createSchemaIndexFromSchema(schema);\n const graphqlSource = reconstructGraphql(template);\n\n // Extract variable definitions from Fragment Arguments syntax\n const variableDefinitions = extractFragmentVariables(graphqlSource, schemaIndex);\n\n // Preprocess to strip Fragment Arguments\n const { preprocessed } = preprocessFragmentArgs(graphqlSource);\n\n const document = parseGraphql(preprocessed);\n const fragDef = document.definitions.find((d) => d.kind === Kind.FRAGMENT_DEFINITION);\n if (!fragDef || fragDef.kind !== Kind.FRAGMENT_DEFINITION) {\n return null;\n }\n\n const fragmentName = fragDef.name.value;\n const onType = fragDef.typeCondition.name.value;\n\n // Build fields from selection set (filter placeholder spreads from interpolated fragments)\n const fields = buildFieldsFromSelectionSet(filterPlaceholderSpreads(fragDef.selectionSet), schema, onType);\n\n // Generate a canonical ID from file path + fragment name\n const id = `${filePath}::${fragmentName}` as CanonicalId;\n\n return {\n id,\n data: {\n type: \"fragment\",\n schemaLabel: schema.label,\n key: fragmentName,\n typename: onType,\n fields,\n variableDefinitions,\n },\n };\n};\n\n/**\n * Convert an operation template into FieldSelectionData.\n */\nconst convertOperationTemplate = (\n template: ExtractedTemplate,\n schema: AnyGraphqlSchema,\n filePath: string,\n): { id: CanonicalId; data: FieldSelectionData } | null => {\n const graphqlSource = reconstructGraphql(template);\n const document = parseGraphql(graphqlSource);\n const opDef = document.definitions.find((d) => d.kind === Kind.OPERATION_DEFINITION);\n if (!opDef || opDef.kind !== Kind.OPERATION_DEFINITION) {\n return null;\n }\n\n const operationName = opDef.name?.value ?? \"Anonymous\";\n const operationType = opDef.operation;\n\n // Determine root type name based on operation type\n const rootTypeName = getRootTypeName(schema, operationType);\n\n // Build fields from selection set (filter placeholder spreads from interpolated fragments)\n const fields = buildFieldsFromSelectionSet(filterPlaceholderSpreads(opDef.selectionSet), schema, rootTypeName);\n\n // Variable definitions from the operation AST\n const variableDefinitions = opDef.variableDefinitions ?? [];\n\n // Generate a canonical ID from file path + operation name\n const id = `${filePath}::${operationName}` as CanonicalId;\n\n return {\n id,\n data: {\n type: \"operation\",\n schemaLabel: schema.label,\n operationName,\n operationType,\n fields,\n variableDefinitions: [...variableDefinitions],\n },\n };\n};\n\n/**\n * Get the root type name for an operation type from the schema.\n */\nconst getRootTypeName = (schema: AnyGraphqlSchema, operationType: string): string => {\n switch (operationType) {\n case \"query\":\n return schema.operations.query ?? \"Query\";\n case \"mutation\":\n return schema.operations.mutation ?? \"Mutation\";\n case \"subscription\":\n return schema.operations.subscription ?? \"Subscription\";\n default:\n return \"Query\";\n }\n};\n","/**\n * Main typegen runner.\n *\n * Orchestrates the prebuilt type generation process:\n * 1. Load schemas from generated CJS bundle\n * 2. Build artifact to evaluate elements\n * 3. Extract field selections from builder\n * 4. Scan source files for tagged templates and merge selections\n * 5. Emit types.prebuilt.ts\n *\n * @module\n */\n\nimport { existsSync } from \"node:fs\";\nimport { dirname, extname, join, relative, resolve } from \"node:path\";\nimport {\n createBuilderService,\n createGraphqlSystemIdentifyHelper,\n extractFieldSelections,\n type FieldSelectionData,\n type IntermediateArtifactElement,\n loadSchemasFromBundle,\n} from \"@soda-gql/builder\";\nimport type { CanonicalId } from \"@soda-gql/common\";\nimport type { ResolvedSodaGqlConfig } from \"@soda-gql/config\";\nimport { err, ok } from \"neverthrow\";\nimport { emitPrebuiltTypes } from \"./emitter\";\nimport { typegenErrors } from \"./errors\";\nimport { scanSourceFiles } from \"./template-scanner\";\nimport { convertTemplatesToSelections } from \"./template-to-selections\";\nimport type { TypegenResult, TypegenSuccess } from \"./types\";\n\n/**\n * Options for running typegen.\n */\nexport type RunTypegenOptions = {\n /**\n * Resolved soda-gql configuration.\n */\n readonly config: ResolvedSodaGqlConfig;\n};\n\nconst extensionMap: Record<string, string> = {\n \".ts\": \".js\",\n \".tsx\": \".js\",\n \".mts\": \".mjs\",\n \".cts\": \".cjs\",\n \".js\": \".js\",\n \".mjs\": \".mjs\",\n \".cjs\": \".cjs\",\n};\n\ntype ImportSpecifierOptions = {\n includeExtension?: boolean;\n};\n\nconst toImportSpecifier = (fromPath: string, targetPath: string, options?: ImportSpecifierOptions): string => {\n const fromDir = dirname(fromPath);\n const normalized = relative(fromDir, targetPath).replace(/\\\\/g, \"/\");\n const sourceExt = extname(targetPath);\n\n // When includeExtension is false (default), strip the extension entirely\n if (!options?.includeExtension) {\n if (normalized.length === 0) {\n return `./${targetPath.slice(0, -sourceExt.length).split(\"/\").pop()}`;\n }\n const withPrefix = normalized.startsWith(\".\") ? normalized : `./${normalized}`;\n const currentExt = extname(withPrefix);\n return currentExt ? withPrefix.slice(0, -currentExt.length) : withPrefix;\n }\n\n // When includeExtension is true, convert to runtime extension\n const runtimeExt = extensionMap[sourceExt] ?? sourceExt;\n\n if (normalized.length === 0) {\n const base = runtimeExt !== sourceExt ? targetPath.slice(0, -sourceExt.length).split(\"/\").pop() : targetPath.split(\"/\").pop();\n return `./${base}${runtimeExt}`;\n }\n\n const withPrefix = normalized.startsWith(\".\") ? normalized : `./${normalized}`;\n if (!runtimeExt) {\n return withPrefix;\n }\n if (withPrefix.endsWith(runtimeExt)) {\n return withPrefix;\n }\n\n const currentExt = extname(withPrefix);\n const withoutExt = currentExt ? withPrefix.slice(0, -currentExt.length) : withPrefix;\n return `${withoutExt}${runtimeExt}`;\n};\n\n/**\n * Run the typegen process.\n *\n * This function:\n * 1. Loads schemas from the generated CJS bundle\n * 2. Creates a BuilderService and builds the artifact\n * 3. Extracts field selections from the artifact\n * 4. Scans source files for tagged templates and merges selections\n * 5. Emits types.prebuilt.ts using emitPrebuiltTypes\n *\n * @param options - Typegen options including config\n * @returns Result containing success data or error\n */\nexport const runTypegen = async (options: RunTypegenOptions): Promise<TypegenResult> => {\n const { config } = options;\n const outdir = resolve(config.outdir);\n const cjsPath = join(outdir, \"index.cjs\");\n const importSpecifierOptions = { includeExtension: config.styles.importExtension };\n\n // Step 1: Check if codegen has been run\n if (!existsSync(cjsPath)) {\n return err(typegenErrors.codegenRequired(outdir));\n }\n\n // Step 2: Load schemas from CJS bundle\n const schemaNames = Object.keys(config.schemas);\n const schemasResult = loadSchemasFromBundle(cjsPath, schemaNames);\n if (schemasResult.isErr()) {\n return err(typegenErrors.schemaLoadFailed(schemaNames, schemasResult.error));\n }\n const schemas = schemasResult.value;\n\n // Calculate import path for types.prebuilt.ts to _internal-injects.ts\n const prebuiltTypesPath = join(outdir, \"types.prebuilt.ts\");\n const injectsModulePath = toImportSpecifier(prebuiltTypesPath, join(outdir, \"_internal-injects.ts\"), importSpecifierOptions);\n\n // Step 3: Build artifact using BuilderService\n const builderService = createBuilderService({\n config,\n });\n\n const artifactResult = await builderService.buildAsync();\n\n if (artifactResult.isErr()) {\n return err(typegenErrors.buildFailed(`Builder failed: ${artifactResult.error.message}`, artifactResult.error));\n }\n\n // Step 4: Extract field selections from intermediate elements\n const intermediateElements = builderService.getIntermediateElements();\n if (!intermediateElements) {\n return err(typegenErrors.buildFailed(\"No intermediate elements available after build\", undefined));\n }\n\n const fieldSelectionsResult = extractFieldSelections(intermediateElements as Record<CanonicalId, IntermediateArtifactElement>);\n const { selections: builderSelections, warnings: extractWarnings } = fieldSelectionsResult;\n\n // Step 4b: Scan source files for tagged templates and merge selections\n const graphqlHelper = createGraphqlSystemIdentifyHelper(config);\n const scanResult = scanSourceFiles({\n include: [...config.include],\n exclude: [...config.exclude],\n baseDir: config.baseDir,\n helper: graphqlHelper,\n });\n\n const templateSelections = convertTemplatesToSelections(scanResult.templates, schemas);\n\n const fieldSelections = mergeSelections(builderSelections, templateSelections.selections, config.baseDir);\n\n const scanWarnings = [...scanResult.warnings, ...templateSelections.warnings];\n\n // Step 5: Emit types.prebuilt.ts\n const emitResult = await emitPrebuiltTypes({\n schemas,\n fieldSelections,\n outdir,\n injectsModulePath,\n });\n\n if (emitResult.isErr()) {\n return err(emitResult.error);\n }\n\n const { warnings: emitWarnings, skippedFragmentCount } = emitResult.value;\n\n // Count fragments and operations\n let fragmentCount = 0;\n let operationCount = 0;\n for (const selection of fieldSelections.values()) {\n if (selection.type === \"fragment\" && selection.key) {\n fragmentCount++;\n } else if (selection.type === \"operation\") {\n operationCount++;\n }\n }\n\n const allWarnings = [...extractWarnings, ...scanWarnings, ...emitWarnings];\n\n return ok({\n prebuiltTypesPath,\n fragmentCount,\n operationCount,\n skippedFragmentCount,\n warnings: allWarnings,\n } satisfies TypegenSuccess);\n};\n\nconst extractElementName = (data: FieldSelectionData): string | undefined =>\n data.type === \"fragment\" ? data.key : data.operationName;\n\n/**\n * Merge builder and template selections into a combined map.\n *\n * Builder selections are authoritative — VM evaluation correctly resolves\n * fragment spreads that static template analysis cannot handle.\n * Template selections serve as fallback for elements only found by the scanner.\n *\n * Deduplication is per-element (file + GraphQL name), not per-file, so that\n * callback-builder operations in files that also contain tagged templates are preserved.\n */\nexport const mergeSelections = (\n builderSelections: ReadonlyMap<CanonicalId, FieldSelectionData>,\n templateSelections: ReadonlyMap<CanonicalId, FieldSelectionData>,\n baseDir: string,\n): Map<CanonicalId, FieldSelectionData> => {\n // Builder uses relative paths (e.g. \"src/foo.ts::varName\"), template scanner uses\n // absolute paths (e.g. \"/abs/path/src/foo.ts::FragmentName\"). Normalize to relative.\n const extractFilePart = (id: string): string => {\n const filePart = id.split(\"::\")[0] ?? \"\";\n if (filePart.startsWith(\"/\")) {\n return relative(baseDir, filePart);\n }\n return filePart;\n };\n\n // Build set of (file, elementName) pairs from builder selections\n const builderElements = new Set<string>();\n for (const [id, data] of builderSelections) {\n const name = extractElementName(data);\n if (name) builderElements.add(`${extractFilePart(id)}::${name}`);\n }\n\n const fieldSelections = new Map<CanonicalId, FieldSelectionData>();\n // Builder selections first (authoritative)\n for (const [id, data] of builderSelections) {\n fieldSelections.set(id, data);\n }\n // Template selections as fallback for elements not found by builder\n for (const [id, data] of templateSelections) {\n const name = extractElementName(data);\n if (name && builderElements.has(`${extractFilePart(id)}::${name}`)) continue;\n fieldSelections.set(id, data);\n }\n\n return fieldSelections;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoGA,MAAM,iBACJ,iBACA,YAC6D;CAC7D,MAAM,UAAU,IAAI,KAA0B;CAC9C,MAAMA,WAAqB,EAAE;CAC7B,IAAI,uBAAuB;AAG3B,MAAK,MAAM,cAAc,OAAO,KAAK,QAAQ,EAAE;AAC7C,UAAQ,IAAI,YAAY;GAAE,WAAW,EAAE;GAAE,YAAY,EAAE;GAAE,cAAc,IAAI,KAAK;GAAE,CAAC;;AAGrF,MAAK,MAAM,CAAC,aAAa,cAAc,iBAAiB;EAEtD,MAAM,aAAa,UAAU;EAC7B,MAAM,SAAS,QAAQ;EACvB,MAAM,QAAQ,QAAQ,IAAI,WAAW;AAErC,MAAI,CAAC,UAAU,CAAC,OAAO;AACrB,8BAAWC,iCAAc,eAAe,YAAY,YAAY,CAAC;;EAInE,MAAMC,mBAAmC,EACvC,eAAe,SAAS,gBAAgB,WAAW,IAAI,KAAK,KAC7D;EACD,MAAMC,kBAAkC;GACtC,cAAc,SAAS,eAAe,WAAW,IAAI,KAAK;GAC1D,cAAc,SAAS,SAAS,WAAW,GAAG;GAC/C;AAED,MAAI,UAAU,SAAS,YAAY;AAEjC,OAAI,CAAC,UAAU,KAAK;AAClB;AACA,aAAS,KACP,wBAAwB,YAAY,uCAClC,0FACA,mDACH;AACD;;AAGF,OAAI;IAEF,MAAM,mBAAmB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pC,SAAO;;CAIT,MAAM,kBAAkB,IAAI,KAAa;AACzC,MAAK,MAAM,CAAC,IAAI,SAAS,mBAAmB;EAC1C,MAAM,OAAO,mBAAmB,KAAK;AACrC,MAAI,KAAM,iBAAgB,IAAI,GAAG,gBAAgB,GAAG,CAAC,IAAI,OAAO;;CAGlE,MAAM,kBAAkB,IAAI,KAAsC;AAElE,MAAK,MAAM,CAAC,IAAI,SAAS,mBAAmB;AAC1C,kBAAgB,IAAI,IAAI,KAAK;;AAG/B,MAAK,MAAM,CAAC,IAAI,SAAS,oBAAoB;EAC3C,MAAM,OAAO,mBAAmB,KAAK;AACrC,MAAI,QAAQ,gBAAgB,IAAI,GAAG,gBAAgB,GAAG,CAAC,IAAI,OAAO,CAAE;AACpE,kBAAgB,IAAI,IAAI,KAAK;;AAG/B,QAAO"}
@@ -0,0 +1,205 @@
1
+ import { Result } from "neverthrow";
2
+ import { AnyGraphqlSchema } from "@soda-gql/core";
3
+ import { ResolvedSodaGqlConfig } from "@soda-gql/config";
4
+ import { BuilderError, FieldSelectionData, FieldSelectionsMap } from "@soda-gql/builder";
5
+ import { CanonicalId } from "@soda-gql/common";
6
+
7
+ //#region packages/tools/src/typegen/errors.d.ts
8
+
9
+ /**
10
+ * Error codes specific to typegen operations.
11
+ */
12
+ type TypegenErrorCode = "TYPEGEN_CODEGEN_REQUIRED" | "TYPEGEN_SCHEMA_LOAD_FAILED" | "TYPEGEN_BUILD_FAILED";
13
+ /**
14
+ * Typegen-specific error type.
15
+ */
16
+ type TypegenSpecificError = {
17
+ readonly code: "TYPEGEN_CODEGEN_REQUIRED";
18
+ readonly message: string;
19
+ readonly outdir: string;
20
+ } | {
21
+ readonly code: "TYPEGEN_SCHEMA_LOAD_FAILED";
22
+ readonly message: string;
23
+ readonly schemaNames: readonly string[];
24
+ readonly cause?: unknown;
25
+ } | {
26
+ readonly code: "TYPEGEN_BUILD_FAILED";
27
+ readonly message: string;
28
+ readonly cause?: unknown;
29
+ };
30
+ /**
31
+ * Union of all typegen errors (specific + builder errors).
32
+ */
33
+ type TypegenError = TypegenSpecificError | BuilderError;
34
+ /**
35
+ * Error constructor helpers for concise error creation.
36
+ */
37
+ declare const typegenErrors: {
38
+ readonly codegenRequired: (outdir: string) => TypegenSpecificError;
39
+ readonly schemaLoadFailed: (schemaNames: readonly string[], cause?: unknown) => TypegenSpecificError;
40
+ readonly buildFailed: (message: string, cause?: unknown) => TypegenSpecificError;
41
+ };
42
+ /**
43
+ * Format TypegenError for console output (human-readable).
44
+ */
45
+ declare const formatTypegenError: (error: TypegenError) => string;
46
+ //#endregion
47
+ //#region packages/tools/src/typegen/emitter.d.ts
48
+
49
+ /**
50
+ * Options for emitting prebuilt types.
51
+ */
52
+ type PrebuiltTypesEmitterOptions = {
53
+ /**
54
+ * Schema definitions per schema name.
55
+ * These come from the codegen output.
56
+ */
57
+ readonly schemas: Record<string, AnyGraphqlSchema>;
58
+ /**
59
+ * Field selections extracted from the builder.
60
+ */
61
+ readonly fieldSelections: FieldSelectionsMap;
62
+ /**
63
+ * Output directory (where types.prebuilt.ts should be written).
64
+ * This should be the same as config.outdir.
65
+ */
66
+ readonly outdir: string;
67
+ /**
68
+ * Relative import path to _internal-injects.ts from types.prebuilt.ts.
69
+ * Example: "./_internal-injects"
70
+ */
71
+ readonly injectsModulePath: string;
72
+ };
73
+ /**
74
+ * Result of emitting prebuilt types.
75
+ */
76
+ type PrebuiltTypesEmitResult = {
77
+ readonly path: string;
78
+ readonly warnings: readonly string[];
79
+ readonly skippedFragmentCount: number;
80
+ };
81
+ /**
82
+ * Emit prebuilt types to the types.prebuilt.ts file.
83
+ *
84
+ * This function uses a partial failure strategy: if type calculation fails for
85
+ * individual elements (e.g., due to invalid field selections or missing schema
86
+ * types), those elements are skipped and warnings are collected rather than
87
+ * failing the entire emission. This allows builds to succeed even when some
88
+ * elements have issues, while still reporting problems via warnings.
89
+ *
90
+ * @param options - Emitter options including schemas, field selections, and output directory
91
+ * @returns Result containing output path and warnings, or error if a hard failure occurs
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * const result = await emitPrebuiltTypes({
96
+ * schemas: { mySchema: schema },
97
+ * fieldSelections,
98
+ * outdir: "./generated",
99
+ * injects: { mySchema: { scalars: "./scalars.ts" } },
100
+ * });
101
+ *
102
+ * if (result.isOk()) {
103
+ * console.log(`Generated: ${result.value.path}`);
104
+ * if (result.value.warnings.length > 0) {
105
+ * console.warn("Warnings:", result.value.warnings);
106
+ * }
107
+ * }
108
+ * ```
109
+ */
110
+ declare const emitPrebuiltTypes: (options: PrebuiltTypesEmitterOptions) => Promise<Result<PrebuiltTypesEmitResult, BuilderError | TypegenError>>;
111
+ //#endregion
112
+ //#region packages/tools/src/typegen/types.d.ts
113
+ /**
114
+ * Options for running typegen.
115
+ */
116
+ type TypegenOptions = {
117
+ /**
118
+ * Absolute path to the output directory (usually config.outdir).
119
+ * This is where the generated graphql-system module resides.
120
+ */
121
+ readonly outdir: string;
122
+ /**
123
+ * Schema names to process.
124
+ */
125
+ readonly schemaNames: readonly string[];
126
+ /**
127
+ * Inject configuration per schema.
128
+ * Maps schema name to inject file paths (absolute paths).
129
+ */
130
+ readonly injects: Record<string, {
131
+ readonly scalars: string;
132
+ }>;
133
+ /**
134
+ * Whether to include import extensions in generated code.
135
+ */
136
+ readonly importExtension?: boolean;
137
+ };
138
+ /**
139
+ * Result of a successful typegen run.
140
+ */
141
+ type TypegenSuccess = {
142
+ /**
143
+ * Path to the generated types.prebuilt.ts file.
144
+ */
145
+ readonly prebuiltTypesPath: string;
146
+ /**
147
+ * Number of fragments processed.
148
+ */
149
+ readonly fragmentCount: number;
150
+ /**
151
+ * Number of operations processed.
152
+ */
153
+ readonly operationCount: number;
154
+ /**
155
+ * Number of fragments skipped due to missing 'key' property.
156
+ */
157
+ readonly skippedFragmentCount: number;
158
+ /**
159
+ * Warnings encountered during type generation.
160
+ */
161
+ readonly warnings: readonly string[];
162
+ };
163
+ /**
164
+ * Result type for typegen operations.
165
+ */
166
+ type TypegenResult = Result<TypegenSuccess, TypegenError>;
167
+ //#endregion
168
+ //#region packages/tools/src/typegen/runner.d.ts
169
+ /**
170
+ * Options for running typegen.
171
+ */
172
+ type RunTypegenOptions = {
173
+ /**
174
+ * Resolved soda-gql configuration.
175
+ */
176
+ readonly config: ResolvedSodaGqlConfig;
177
+ };
178
+ /**
179
+ * Run the typegen process.
180
+ *
181
+ * This function:
182
+ * 1. Loads schemas from the generated CJS bundle
183
+ * 2. Creates a BuilderService and builds the artifact
184
+ * 3. Extracts field selections from the artifact
185
+ * 4. Scans source files for tagged templates and merges selections
186
+ * 5. Emits types.prebuilt.ts using emitPrebuiltTypes
187
+ *
188
+ * @param options - Typegen options including config
189
+ * @returns Result containing success data or error
190
+ */
191
+ declare const runTypegen: (options: RunTypegenOptions) => Promise<TypegenResult>;
192
+ /**
193
+ * Merge builder and template selections into a combined map.
194
+ *
195
+ * Builder selections are authoritative — VM evaluation correctly resolves
196
+ * fragment spreads that static template analysis cannot handle.
197
+ * Template selections serve as fallback for elements only found by the scanner.
198
+ *
199
+ * Deduplication is per-element (file + GraphQL name), not per-file, so that
200
+ * callback-builder operations in files that also contain tagged templates are preserved.
201
+ */
202
+ declare const mergeSelections: (builderSelections: ReadonlyMap<CanonicalId, FieldSelectionData>, templateSelections: ReadonlyMap<CanonicalId, FieldSelectionData>, baseDir: string) => Map<CanonicalId, FieldSelectionData>;
203
+ //#endregion
204
+ export { type PrebuiltTypesEmitResult, type PrebuiltTypesEmitterOptions, type RunTypegenOptions, type TypegenError, type TypegenErrorCode, type TypegenOptions, type TypegenResult, type TypegenSpecificError, type TypegenSuccess, emitPrebuiltTypes, formatTypegenError, runTypegen, typegenErrors };
205
+ //# sourceMappingURL=typegen.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typegen.d.cts","names":[],"sources":["../src/typegen/errors.ts","../src/typegen/emitter.ts","../src/typegen/types.ts","../src/typegen/runner.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAWA;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gql/core";
3
+ import { BuilderError, FieldSelectionData, FieldSelectionsMap } from "@soda-gql/builder";
4
+ import { ResolvedSodaGqlConfig } from "@soda-gql/config";
5
+ import { CanonicalId } from "@soda-gql/common";
6
+
7
+ //#region packages/tools/src/typegen/errors.d.ts
8
+
9
+ /**
10
+ * Error codes specific to typegen operations.
11
+ */
12
+ type TypegenErrorCode = "TYPEGEN_CODEGEN_REQUIRED" | "TYPEGEN_SCHEMA_LOAD_FAILED" | "TYPEGEN_BUILD_FAILED";
13
+ /**
14
+ * Typegen-specific error type.
15
+ */
16
+ type TypegenSpecificError = {
17
+ readonly code: "TYPEGEN_CODEGEN_REQUIRED";
18
+ readonly message: string;
19
+ readonly outdir: string;
20
+ } | {
21
+ readonly code: "TYPEGEN_SCHEMA_LOAD_FAILED";
22
+ readonly message: string;
23
+ readonly schemaNames: readonly string[];
24
+ readonly cause?: unknown;
25
+ } | {
26
+ readonly code: "TYPEGEN_BUILD_FAILED";
27
+ readonly message: string;
28
+ readonly cause?: unknown;
29
+ };
30
+ /**
31
+ * Union of all typegen errors (specific + builder errors).
32
+ */
33
+ type TypegenError = TypegenSpecificError | BuilderError;
34
+ /**
35
+ * Error constructor helpers for concise error creation.
36
+ */
37
+ declare const typegenErrors: {
38
+ readonly codegenRequired: (outdir: string) => TypegenSpecificError;
39
+ readonly schemaLoadFailed: (schemaNames: readonly string[], cause?: unknown) => TypegenSpecificError;
40
+ readonly buildFailed: (message: string, cause?: unknown) => TypegenSpecificError;
41
+ };
42
+ /**
43
+ * Format TypegenError for console output (human-readable).
44
+ */
45
+ declare const formatTypegenError: (error: TypegenError) => string;
46
+ //#endregion
47
+ //#region packages/tools/src/typegen/emitter.d.ts
48
+
49
+ /**
50
+ * Options for emitting prebuilt types.
51
+ */
52
+ type PrebuiltTypesEmitterOptions = {
53
+ /**
54
+ * Schema definitions per schema name.
55
+ * These come from the codegen output.
56
+ */
57
+ readonly schemas: Record<string, AnyGraphqlSchema>;
58
+ /**
59
+ * Field selections extracted from the builder.
60
+ */
61
+ readonly fieldSelections: FieldSelectionsMap;
62
+ /**
63
+ * Output directory (where types.prebuilt.ts should be written).
64
+ * This should be the same as config.outdir.
65
+ */
66
+ readonly outdir: string;
67
+ /**
68
+ * Relative import path to _internal-injects.ts from types.prebuilt.ts.
69
+ * Example: "./_internal-injects"
70
+ */
71
+ readonly injectsModulePath: string;
72
+ };
73
+ /**
74
+ * Result of emitting prebuilt types.
75
+ */
76
+ type PrebuiltTypesEmitResult = {
77
+ readonly path: string;
78
+ readonly warnings: readonly string[];
79
+ readonly skippedFragmentCount: number;
80
+ };
81
+ /**
82
+ * Emit prebuilt types to the types.prebuilt.ts file.
83
+ *
84
+ * This function uses a partial failure strategy: if type calculation fails for
85
+ * individual elements (e.g., due to invalid field selections or missing schema
86
+ * types), those elements are skipped and warnings are collected rather than
87
+ * failing the entire emission. This allows builds to succeed even when some
88
+ * elements have issues, while still reporting problems via warnings.
89
+ *
90
+ * @param options - Emitter options including schemas, field selections, and output directory
91
+ * @returns Result containing output path and warnings, or error if a hard failure occurs
92
+ *
93
+ * @example
94
+ * ```typescript
95
+ * const result = await emitPrebuiltTypes({
96
+ * schemas: { mySchema: schema },
97
+ * fieldSelections,
98
+ * outdir: "./generated",
99
+ * injects: { mySchema: { scalars: "./scalars.ts" } },
100
+ * });
101
+ *
102
+ * if (result.isOk()) {
103
+ * console.log(`Generated: ${result.value.path}`);
104
+ * if (result.value.warnings.length > 0) {
105
+ * console.warn("Warnings:", result.value.warnings);
106
+ * }
107
+ * }
108
+ * ```
109
+ */
110
+ declare const emitPrebuiltTypes: (options: PrebuiltTypesEmitterOptions) => Promise<Result<PrebuiltTypesEmitResult, BuilderError | TypegenError>>;
111
+ //#endregion
112
+ //#region packages/tools/src/typegen/types.d.ts
113
+ /**
114
+ * Options for running typegen.
115
+ */
116
+ type TypegenOptions = {
117
+ /**
118
+ * Absolute path to the output directory (usually config.outdir).
119
+ * This is where the generated graphql-system module resides.
120
+ */
121
+ readonly outdir: string;
122
+ /**
123
+ * Schema names to process.
124
+ */
125
+ readonly schemaNames: readonly string[];
126
+ /**
127
+ * Inject configuration per schema.
128
+ * Maps schema name to inject file paths (absolute paths).
129
+ */
130
+ readonly injects: Record<string, {
131
+ readonly scalars: string;
132
+ }>;
133
+ /**
134
+ * Whether to include import extensions in generated code.
135
+ */
136
+ readonly importExtension?: boolean;
137
+ };
138
+ /**
139
+ * Result of a successful typegen run.
140
+ */
141
+ type TypegenSuccess = {
142
+ /**
143
+ * Path to the generated types.prebuilt.ts file.
144
+ */
145
+ readonly prebuiltTypesPath: string;
146
+ /**
147
+ * Number of fragments processed.
148
+ */
149
+ readonly fragmentCount: number;
150
+ /**
151
+ * Number of operations processed.
152
+ */
153
+ readonly operationCount: number;
154
+ /**
155
+ * Number of fragments skipped due to missing 'key' property.
156
+ */
157
+ readonly skippedFragmentCount: number;
158
+ /**
159
+ * Warnings encountered during type generation.
160
+ */
161
+ readonly warnings: readonly string[];
162
+ };
163
+ /**
164
+ * Result type for typegen operations.
165
+ */
166
+ type TypegenResult = Result<TypegenSuccess, TypegenError>;
167
+ //#endregion
168
+ //#region packages/tools/src/typegen/runner.d.ts
169
+ /**
170
+ * Options for running typegen.
171
+ */
172
+ type RunTypegenOptions = {
173
+ /**
174
+ * Resolved soda-gql configuration.
175
+ */
176
+ readonly config: ResolvedSodaGqlConfig;
177
+ };
178
+ /**
179
+ * Run the typegen process.
180
+ *
181
+ * This function:
182
+ * 1. Loads schemas from the generated CJS bundle
183
+ * 2. Creates a BuilderService and builds the artifact
184
+ * 3. Extracts field selections from the artifact
185
+ * 4. Scans source files for tagged templates and merges selections
186
+ * 5. Emits types.prebuilt.ts using emitPrebuiltTypes
187
+ *
188
+ * @param options - Typegen options including config
189
+ * @returns Result containing success data or error
190
+ */
191
+ declare const runTypegen: (options: RunTypegenOptions) => Promise<TypegenResult>;
192
+ /**
193
+ * Merge builder and template selections into a combined map.
194
+ *
195
+ * Builder selections are authoritative — VM evaluation correctly resolves
196
+ * fragment spreads that static template analysis cannot handle.
197
+ * Template selections serve as fallback for elements only found by the scanner.
198
+ *
199
+ * Deduplication is per-element (file + GraphQL name), not per-file, so that
200
+ * callback-builder operations in files that also contain tagged templates are preserved.
201
+ */
202
+ declare const mergeSelections: (builderSelections: ReadonlyMap<CanonicalId, FieldSelectionData>, templateSelections: ReadonlyMap<CanonicalId, FieldSelectionData>, baseDir: string) => Map<CanonicalId, FieldSelectionData>;
203
+ //#endregion
204
+ export { type PrebuiltTypesEmitResult, type PrebuiltTypesEmitterOptions, type RunTypegenOptions, type TypegenError, type TypegenErrorCode, type TypegenOptions, type TypegenResult, type TypegenSpecificError, type TypegenSuccess, emitPrebuiltTypes, formatTypegenError, runTypegen, typegenErrors };
205
+ //# sourceMappingURL=typegen.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typegen.d.mts","names":[],"sources":["../src/typegen/errors.ts","../src/typegen/emitter.ts","../src/typegen/types.ts","../src/typegen/runner.ts"],"sourcesContent":[],"mappings":";;;;;;;;;AAWA;AAKA;AAqBY,KA1BA,gBAAA,GA0Be,0BAAuB,GAAA,4BAAY,GAAA,sBAAA;AAK9D;;;AAcmD,KAxCvC,oBAAA,GAwCuC;EAAoB,SAAA,IAAA,EAAA,0BAAA;EAU1D,SAAA,OAAA,EAAA,MAoBZ;;;;EC3CW,SAAA,OAAA,EAAA,MAAA;EAKuB,SAAA,WAAA,EAAA,SAAA,MAAA,EAAA;EAAf,SAAA,KAAA,CAAA,EAAA,OAAA;CAIQ,GAAA;EAAkB,SAAA,IAAA,EAAA,sBAAA;EAgYlC,SAAA,OAAA,EAAA,MAAA;EAmCC,SAAA,KAAA,CAAA,EAAA,OA8BZ;CA7BU;;;;AACA,KDpbC,YAAA,GAAe,oBCobhB,GDpbuC,YCobvC;;;;cD/aE;gDACwB;EE/BzB,SAAA,gBAAc,EAAA,CAgBN,WAAM,EAAA,SAAA,MAAA,EAAA,EAAA,KAAA,CAAA,EAAA,OAAA,EAA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