@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
package/dist/bin.d.cts ADDED
@@ -0,0 +1,839 @@
1
+ import * as neverthrow3 from "neverthrow";
2
+ import { Result } from "neverthrow";
3
+ import { ArtifactLoadError, BuilderError, FieldSelectionData, FieldSelectionsMap } from "@soda-gql/builder";
4
+ import { ConfigError, ResolvedSodaGqlConfig, TypeCategory, TypeFilterConfig } from "@soda-gql/config";
5
+ import * as graphql0 from "graphql";
6
+ import { DocumentNode, TypeNode } from "graphql";
7
+ import { AnyGraphqlSchema, DirectiveRecord, EnrichedFragment, EnrichedOperation, EnumRecord, GraphqlAnalysisError as GraphqlCompatError, InferredVariable, InputRecord, ObjectRecord, OperationTypeNames, ParseResultBase as ParseResult, ParsedFragment, ParsedSelection, ScalarRecord, SchemaIndex as SchemaIndex$1, TransformOptions, TransformResult, TypeInfo, UnionRecord, createSchemaIndex } from "@soda-gql/core";
8
+ import { CanonicalId } from "@soda-gql/common";
9
+
10
+ //#region packages/tools/src/codegen/graphql-compat/types.d.ts
11
+
12
+ /**
13
+ * Options for running graphql-compat code generation.
14
+ */
15
+ type GraphqlCompatOptions = {
16
+ /** Schema name from config */
17
+ readonly schemaName: string;
18
+ /** Resolved paths to .graphql operation files */
19
+ readonly operationFiles: readonly string[];
20
+ /** Output directory for generated files */
21
+ readonly outputDir?: string;
22
+ /** Import path for graphql-system module (e.g., "@/graphql-system") */
23
+ readonly graphqlSystemPath: string;
24
+ };
25
+ /**
26
+ * Generated file output.
27
+ */
28
+ type GeneratedFile = {
29
+ readonly path: string;
30
+ readonly content: string;
31
+ };
32
+ //#endregion
33
+ //#region packages/tools/src/codegen/graphql-compat/emitter.d.ts
34
+ /**
35
+ * Options for code emission.
36
+ */
37
+ type EmitOptions = {
38
+ /** Schema name to use in gql.schemaName() call */
39
+ readonly schemaName: string;
40
+ /** Import path for graphql-system module */
41
+ readonly graphqlSystemPath: string;
42
+ /** Schema document for type lookups (required for inline fragment support) */
43
+ readonly schemaDocument?: DocumentNode;
44
+ };
45
+ /**
46
+ * Emit TypeScript code for an operation.
47
+ */
48
+ declare const emitOperation: (operation: EnrichedOperation, options: EmitOptions) => Result<string, GraphqlCompatError>;
49
+ /**
50
+ * Emit TypeScript code for a fragment.
51
+ */
52
+ declare const emitFragment: (fragment: EnrichedFragment, options: EmitOptions) => Result<string, GraphqlCompatError>;
53
+ //#endregion
54
+ //#region packages/tools/src/codegen/graphql-compat/parser.d.ts
55
+ /**
56
+ * Parse a single .graphql file and extract operations and fragments.
57
+ */
58
+ declare const parseGraphqlFile: (filePath: string) => Result<ParseResult, GraphqlCompatError>;
59
+ /**
60
+ * Parse GraphQL source string directly.
61
+ */
62
+ declare const parseGraphqlSource: (source: string, sourceFile: string) => Result<ParseResult, GraphqlCompatError>;
63
+ /**
64
+ * Parse a GraphQL TypeNode into type name and modifier.
65
+ *
66
+ * Format: inner nullability + list modifiers
67
+ * - Inner: `!` (non-null) or `?` (nullable)
68
+ * - List: `[]!` (non-null list) or `[]?` (nullable list)
69
+ */
70
+ declare const parseTypeNode: (node: TypeNode) => TypeInfo;
71
+ //#endregion
72
+ //#region packages/tools/src/codegen/defs-generator.d.ts
73
+ /**
74
+ * Definition file generator for split codegen.
75
+ * Generates separate files for each definition category (enums, inputs, objects, unions).
76
+ */
77
+ type DefinitionCategory = "enums" | "inputs" | "objects" | "unions";
78
+ type DefinitionVar = {
79
+ readonly name: string;
80
+ readonly code: string;
81
+ };
82
+ /**
83
+ * Split an array into chunks of the specified size.
84
+ */
85
+ declare const chunkArray: <T>(array: readonly T[], size: number) => T[][];
86
+ /**
87
+ * Determine if chunking is needed based on the number of definitions.
88
+ */
89
+ declare const needsChunking: (vars: readonly DefinitionVar[], chunkSize: number) => boolean;
90
+ type DefinitionFileOptions = {
91
+ readonly category: DefinitionCategory;
92
+ readonly schemaName: string;
93
+ readonly vars: readonly DefinitionVar[];
94
+ readonly needsDefineEnum: boolean;
95
+ };
96
+ /**
97
+ * Generate a single definition file content.
98
+ */
99
+ declare const generateDefinitionFile: (options: DefinitionFileOptions) => string;
100
+ type ChunkFileOptions = {
101
+ readonly category: DefinitionCategory;
102
+ readonly schemaName: string;
103
+ readonly vars: readonly DefinitionVar[];
104
+ readonly chunkIndex: number;
105
+ readonly needsDefineEnum: boolean;
106
+ };
107
+ /**
108
+ * Generate a chunk file content.
109
+ */
110
+ declare const generateChunkFile: (options: ChunkFileOptions) => string;
111
+ type ChunkIndexOptions = {
112
+ readonly category: DefinitionCategory;
113
+ readonly chunkCount: number;
114
+ readonly varNames: readonly string[];
115
+ };
116
+ /**
117
+ * Generate the index file that re-exports all chunks.
118
+ */
119
+ declare const generateChunkIndex: (options: ChunkIndexOptions) => string;
120
+ type ChunkedDefinitionFiles = {
121
+ readonly indexContent: string;
122
+ readonly chunks: ReadonlyArray<{
123
+ readonly chunkIndex: number;
124
+ readonly content: string;
125
+ readonly varNames: readonly string[];
126
+ }>;
127
+ };
128
+ /**
129
+ * Generate chunked definition files.
130
+ */
131
+ declare const generateChunkedDefinitionFiles: (category: DefinitionCategory, schemaName: string, vars: readonly DefinitionVar[], chunkSize: number) => ChunkedDefinitionFiles;
132
+ type DefsDirectoryStructure = {
133
+ readonly files: ReadonlyArray<{
134
+ readonly relativePath: string;
135
+ readonly content: string;
136
+ }>;
137
+ readonly importPaths: Record<DefinitionCategory, string>;
138
+ };
139
+ type CategoryVars = {
140
+ readonly enums: readonly DefinitionVar[];
141
+ readonly inputs: readonly DefinitionVar[];
142
+ readonly objects: readonly DefinitionVar[];
143
+ readonly unions: readonly DefinitionVar[];
144
+ };
145
+ /**
146
+ * Generate the complete _defs directory structure.
147
+ */
148
+ declare const generateDefsStructure: (schemaName: string, categoryVars: CategoryVars, chunkSize: number) => DefsDirectoryStructure;
149
+ //#endregion
150
+ //#region packages/tools/src/codegen/generator.d.ts
151
+ type DefsFile = {
152
+ readonly relativePath: string;
153
+ readonly content: string;
154
+ };
155
+ type GeneratedModule = {
156
+ readonly code: string;
157
+ readonly injectsCode?: string;
158
+ readonly defsFiles?: readonly DefsFile[];
159
+ readonly categoryVars?: Record<string, CategoryVars>;
160
+ readonly stats: {
161
+ readonly objects: number;
162
+ readonly enums: number;
163
+ readonly inputs: number;
164
+ readonly unions: number;
165
+ };
166
+ };
167
+ type PerSchemaInjection = {
168
+ readonly scalarImportPath: string;
169
+ readonly adapterImportPath?: string;
170
+ };
171
+ type RuntimeGenerationOptions = {
172
+ readonly injection?: Map<string, PerSchemaInjection>;
173
+ readonly defaultInputDepth?: Map<string, number>;
174
+ readonly inputDepthOverrides?: Map<string, Readonly<Record<string, number>>>;
175
+ readonly chunkSize?: number;
176
+ readonly typeFilters?: Map<string, TypeFilterConfig>;
177
+ };
178
+ declare const generateMultiSchemaModule: (schemas: Map<string, DocumentNode>, options?: RuntimeGenerationOptions) => GeneratedModule;
179
+ /**
180
+ * Generate a stub `types.prebuilt.ts` file with empty PrebuiltTypes registries.
181
+ * This stub is only written when `types.prebuilt.ts` does not already exist.
182
+ * Typegen will later overwrite it with the real type registry.
183
+ */
184
+ declare const generatePrebuiltStub: (schemaNames: string[]) => string;
185
+ /**
186
+ * Generate the `index.ts` module that re-exports from `_internal`
187
+ * and constructs the `gql` object from individual `__gql_*` exports.
188
+ *
189
+ * The `gql` object preserves the original inferred types from schema inference.
190
+ * PrebuiltContext types will be integrated once the type resolution strategy
191
+ * is redesigned to match the tagged template runtime API.
192
+ */
193
+ declare const generateIndexModule: (schemaNames: string[], allFieldNames?: ReadonlyMap<string, readonly string[]>) => string;
194
+ //#endregion
195
+ //#region packages/tools/src/codegen/graphql-compat/transformer.d.ts
196
+ /**
197
+ * Schema index type extracted from generator.
198
+ */
199
+ type SchemaIndex = ReturnType<typeof createSchemaIndex>;
200
+ /**
201
+ * Check if source modifier can be assigned to target modifier.
202
+ * Implements GraphQL List Coercion: depth difference of 0 or 1 is allowed.
203
+ *
204
+ * Rules:
205
+ * - A single value can be coerced into a list (depth diff = 1)
206
+ * - At each level, non-null can be assigned to nullable (but not vice versa)
207
+ *
208
+ * @param source - The modifier of the value being assigned (variable's type)
209
+ * @param target - The modifier expected by the position (field argument's type)
210
+ * @returns true if assignment is valid
211
+ */
212
+ declare const isModifierAssignable: (source: string, target: string) => boolean;
213
+ /**
214
+ * Merge two modifiers by taking the stricter constraint at each level.
215
+ * - Non-null (!) is stricter than nullable (?)
216
+ * - List depths must match
217
+ *
218
+ * @param a - First modifier
219
+ * @param b - Second modifier
220
+ * @returns Merged modifier or error if incompatible
221
+ */
222
+ declare const mergeModifiers: (a: string, b: string) => {
223
+ ok: true;
224
+ value: string;
225
+ } | {
226
+ ok: false;
227
+ reason: string;
228
+ };
229
+ /**
230
+ * Intermediate type for tracking variable usages before merging.
231
+ */
232
+ type VariableUsage = {
233
+ readonly name: string;
234
+ readonly typeName: string;
235
+ /** The modifier expected by the field/argument position */
236
+ readonly expectedModifier: string;
237
+ /** The minimum modifier the variable needs (after applying List Coercion) */
238
+ readonly minimumModifier: string;
239
+ readonly typeKind: "scalar" | "enum" | "input";
240
+ };
241
+ /**
242
+ * Get the expected type for a field argument from the schema.
243
+ * Returns null if the field or argument is not found.
244
+ */
245
+ declare const getArgumentType: (schema: SchemaIndex, parentTypeName: string, fieldName: string, argumentName: string) => TypeInfo | null;
246
+ /**
247
+ * Get the expected type for an input object field from the schema.
248
+ */
249
+ declare const getInputFieldType: (schema: SchemaIndex, inputTypeName: string, fieldName: string) => TypeInfo | null;
250
+ /**
251
+ * Recursively collect all variable usages from selections.
252
+ */
253
+ declare const collectVariableUsages: (selections: readonly ParsedSelection[], parentTypeName: string, schema: SchemaIndex) => Result<VariableUsage[], GraphqlCompatError>;
254
+ /**
255
+ * Get the return type of a field (unwrapped from modifiers).
256
+ */
257
+ declare const getFieldReturnType: (schema: SchemaIndex, parentTypeName: string, fieldName: string) => string | null;
258
+ /**
259
+ * Merge multiple variable usages into a single InferredVariable.
260
+ * Validates type compatibility and merges modifiers using List Coercion rules.
261
+ *
262
+ * The algorithm:
263
+ * 1. Validate all usages have the same type name
264
+ * 2. Merge minimumModifiers to find the candidate (shallowest type that could work)
265
+ * 3. Verify the candidate can satisfy ALL expected modifiers via isModifierAssignable
266
+ */
267
+ declare const mergeVariableUsages: (variableName: string, usages: readonly VariableUsage[]) => Result<InferredVariable, GraphqlCompatError>;
268
+ /**
269
+ * Infer variables from collected usages.
270
+ * Groups by variable name and merges each group.
271
+ */
272
+ declare const inferVariablesFromUsages: (usages: readonly VariableUsage[]) => Result<InferredVariable[], GraphqlCompatError>;
273
+ /**
274
+ * Topologically sort fragments so dependencies come before dependents.
275
+ * Detects circular dependencies.
276
+ *
277
+ * Note: Uses the existing collectFragmentDependencies function defined below.
278
+ */
279
+ declare const sortFragmentsByDependency: (fragments: readonly ParsedFragment[]) => Result<ParsedFragment[], GraphqlCompatError>;
280
+ /**
281
+ * Transform parsed operations/fragments by enriching them with schema information.
282
+ *
283
+ * This resolves variable type kinds (scalar, enum, input), collects
284
+ * fragment dependencies, and infers variables for fragments.
285
+ */
286
+ declare const transformParsedGraphql: (parsed: ParseResult, options: TransformOptions) => Result<TransformResult, GraphqlCompatError>;
287
+ //#endregion
288
+ //#region packages/tools/src/codegen/types.d.ts
289
+ type CodegenFormat = "json" | "human";
290
+ type CodegenInjectConfig = {
291
+ readonly scalars: string;
292
+ readonly adapter?: string;
293
+ };
294
+ type CodegenSchemaConfig = {
295
+ readonly schema: readonly string[];
296
+ readonly inject: CodegenInjectConfig;
297
+ readonly defaultInputDepth?: number;
298
+ readonly inputDepthOverrides?: Readonly<Record<string, number>>;
299
+ readonly typeFilter?: TypeFilterConfig;
300
+ };
301
+ type CodegenOptions = {
302
+ readonly schemas: Record<string, CodegenSchemaConfig>;
303
+ readonly outPath: string;
304
+ readonly format: CodegenFormat;
305
+ readonly importExtension?: boolean;
306
+ readonly chunkSize?: number;
307
+ /** Pre-loaded schema documents. Skips file loading when provided. */
308
+ readonly preloadedSchemas?: ReadonlyMap<string, graphql0.DocumentNode>;
309
+ };
310
+ type CodegenCliCommand = {
311
+ readonly kind: "generate";
312
+ readonly options: CodegenOptions;
313
+ } | {
314
+ readonly kind: "emitInjectTemplate";
315
+ readonly outPath: string;
316
+ readonly format: CodegenFormat;
317
+ };
318
+ type CodegenError = {
319
+ readonly code: "SCHEMA_NOT_FOUND";
320
+ readonly message: string;
321
+ readonly schemaPath: string;
322
+ } | {
323
+ readonly code: "SCHEMA_INVALID";
324
+ readonly message: string;
325
+ readonly schemaPath: string;
326
+ } | {
327
+ readonly code: "EMIT_FAILED";
328
+ readonly message: string;
329
+ readonly outPath: string;
330
+ } | {
331
+ readonly code: "INJECT_MODULE_REQUIRED";
332
+ readonly message: string;
333
+ } | {
334
+ readonly code: "INJECT_MODULE_NOT_FOUND";
335
+ readonly message: string;
336
+ readonly injectPath: string;
337
+ } | {
338
+ readonly code: "INJECT_TEMPLATE_EXISTS";
339
+ readonly message: string;
340
+ readonly outPath: string;
341
+ } | {
342
+ readonly code: "INJECT_TEMPLATE_FAILED";
343
+ readonly message: string;
344
+ readonly outPath: string;
345
+ } | {
346
+ readonly code: "REMOVE_FAILED";
347
+ readonly message: string;
348
+ readonly outPath: string;
349
+ } | {
350
+ readonly code: "READ_FAILED";
351
+ readonly message: string;
352
+ readonly outPath: string;
353
+ };
354
+ type CodegenSuccess = {
355
+ readonly schemas: Record<string, {
356
+ readonly schemaHash: string;
357
+ readonly objects: number;
358
+ readonly enums: number;
359
+ readonly inputs: number;
360
+ readonly unions: number;
361
+ }>;
362
+ readonly outPath: string;
363
+ readonly internalPath: string;
364
+ readonly injectsPath: string;
365
+ readonly cjsPath: string;
366
+ readonly defsPaths?: readonly string[];
367
+ };
368
+ type CodegenResult = Result<CodegenSuccess, CodegenError>;
369
+ //#endregion
370
+ //#region packages/tools/src/codegen/inject-template.d.ts
371
+ declare const writeInjectTemplate: (outPath: string) => neverthrow3.Err<void, CodegenError> | neverthrow3.Ok<void, CodegenError>;
372
+ declare const getInjectTemplate: () => string;
373
+ //#endregion
374
+ //#region packages/tools/src/codegen/type-filter.d.ts
375
+ type FilterContext = {
376
+ readonly name: string;
377
+ readonly category: TypeCategory;
378
+ };
379
+ type CompiledFilter = (context: FilterContext) => boolean;
380
+ declare const compileTypeFilter: (config: TypeFilterConfig | undefined) => CompiledFilter;
381
+ declare const buildExclusionSet: (filter: CompiledFilter, typeNames: Map<TypeCategory, readonly string[]>) => Set<string>;
382
+ //#endregion
383
+ //#region packages/tools/src/codegen/reachability.d.ts
384
+ type ReachabilityResult = {
385
+ readonly filter: (context: FilterContext) => boolean;
386
+ readonly warnings: readonly string[];
387
+ };
388
+ /**
389
+ * Compute a filter function that includes only types reachable from root types
390
+ * to the specified target types.
391
+ *
392
+ * When targetTypes is empty, returns a pass-all filter (no filtering).
393
+ * Warns when target types are not found in the schema.
394
+ *
395
+ * @param document - The parsed GraphQL schema document
396
+ * @param targetTypes - Set of type names that fragments target (e.g., from ParsedFragment.onType)
397
+ * @returns Filter function and any warnings
398
+ */
399
+ declare const computeReachabilityFilter: (document: DocumentNode, targetTypes: ReadonlySet<string>, usedArgumentTypes?: ReadonlySet<string>) => ReachabilityResult;
400
+ //#endregion
401
+ //#region packages/tools/src/codegen/runner.d.ts
402
+ declare const runCodegen: (options: CodegenOptions) => Promise<CodegenResult>;
403
+ //#endregion
404
+ //#region packages/tools/src/codegen/schema.d.ts
405
+ /**
406
+ * Load a single schema file.
407
+ * @internal Use loadSchema for public API.
408
+ */
409
+ declare const loadSingleSchema: (schemaPath: string) => neverthrow3.Err<DocumentNode, CodegenError> | neverthrow3.Ok<DocumentNode, CodegenError>;
410
+ /**
411
+ * Load and merge multiple schema files into a single DocumentNode.
412
+ * Uses GraphQL's concatAST to combine definitions from all files.
413
+ */
414
+ declare const loadSchema: (schemaPaths: readonly string[]) => neverthrow3.Err<DocumentNode, CodegenError> | neverthrow3.Ok<DocumentNode, CodegenError>;
415
+ declare const hashSchema: (document: DocumentNode) => string;
416
+ //#endregion
417
+ //#region packages/tools/src/typegen/errors.d.ts
418
+ /**
419
+ * Error codes specific to typegen operations.
420
+ */
421
+ type TypegenErrorCode = "TYPEGEN_CODEGEN_REQUIRED" | "TYPEGEN_SCHEMA_LOAD_FAILED" | "TYPEGEN_BUILD_FAILED";
422
+ /**
423
+ * Typegen-specific error type.
424
+ */
425
+ type TypegenSpecificError = {
426
+ readonly code: "TYPEGEN_CODEGEN_REQUIRED";
427
+ readonly message: string;
428
+ readonly outdir: string;
429
+ } | {
430
+ readonly code: "TYPEGEN_SCHEMA_LOAD_FAILED";
431
+ readonly message: string;
432
+ readonly schemaNames: readonly string[];
433
+ readonly cause?: unknown;
434
+ } | {
435
+ readonly code: "TYPEGEN_BUILD_FAILED";
436
+ readonly message: string;
437
+ readonly cause?: unknown;
438
+ };
439
+ /**
440
+ * Union of all typegen errors (specific + builder errors).
441
+ */
442
+ type TypegenError = TypegenSpecificError | BuilderError;
443
+ /**
444
+ * Error constructor helpers for concise error creation.
445
+ */
446
+ declare const typegenErrors: {
447
+ readonly codegenRequired: (outdir: string) => TypegenSpecificError;
448
+ readonly schemaLoadFailed: (schemaNames: readonly string[], cause?: unknown) => TypegenSpecificError;
449
+ readonly buildFailed: (message: string, cause?: unknown) => TypegenSpecificError;
450
+ };
451
+ /**
452
+ * Format TypegenError for console output (human-readable).
453
+ */
454
+ declare const formatTypegenError: (error: TypegenError) => string;
455
+ //#endregion
456
+ //#region packages/tools/src/typegen/emitter.d.ts
457
+ /**
458
+ * Options for emitting prebuilt types.
459
+ */
460
+ type PrebuiltTypesEmitterOptions = {
461
+ /**
462
+ * Schema definitions per schema name.
463
+ * These come from the codegen output.
464
+ */
465
+ readonly schemas: Record<string, AnyGraphqlSchema>;
466
+ /**
467
+ * Field selections extracted from the builder.
468
+ */
469
+ readonly fieldSelections: FieldSelectionsMap;
470
+ /**
471
+ * Output directory (where types.prebuilt.ts should be written).
472
+ * This should be the same as config.outdir.
473
+ */
474
+ readonly outdir: string;
475
+ /**
476
+ * Relative import path to _internal-injects.ts from types.prebuilt.ts.
477
+ * Example: "./_internal-injects"
478
+ */
479
+ readonly injectsModulePath: string;
480
+ };
481
+ /**
482
+ * Result of emitting prebuilt types.
483
+ */
484
+ type PrebuiltTypesEmitResult = {
485
+ readonly path: string;
486
+ readonly warnings: readonly string[];
487
+ readonly skippedFragmentCount: number;
488
+ };
489
+ /**
490
+ * Emit prebuilt types to the types.prebuilt.ts file.
491
+ *
492
+ * This function uses a partial failure strategy: if type calculation fails for
493
+ * individual elements (e.g., due to invalid field selections or missing schema
494
+ * types), those elements are skipped and warnings are collected rather than
495
+ * failing the entire emission. This allows builds to succeed even when some
496
+ * elements have issues, while still reporting problems via warnings.
497
+ *
498
+ * @param options - Emitter options including schemas, field selections, and output directory
499
+ * @returns Result containing output path and warnings, or error if a hard failure occurs
500
+ *
501
+ * @example
502
+ * ```typescript
503
+ * const result = await emitPrebuiltTypes({
504
+ * schemas: { mySchema: schema },
505
+ * fieldSelections,
506
+ * outdir: "./generated",
507
+ * injects: { mySchema: { scalars: "./scalars.ts" } },
508
+ * });
509
+ *
510
+ * if (result.isOk()) {
511
+ * console.log(`Generated: ${result.value.path}`);
512
+ * if (result.value.warnings.length > 0) {
513
+ * console.warn("Warnings:", result.value.warnings);
514
+ * }
515
+ * }
516
+ * ```
517
+ */
518
+ declare const emitPrebuiltTypes: (options: PrebuiltTypesEmitterOptions) => Promise<Result<PrebuiltTypesEmitResult, BuilderError | TypegenError>>;
519
+ //#endregion
520
+ //#region packages/tools/src/typegen/types.d.ts
521
+ /**
522
+ * Options for running typegen.
523
+ */
524
+ type TypegenOptions = {
525
+ /**
526
+ * Absolute path to the output directory (usually config.outdir).
527
+ * This is where the generated graphql-system module resides.
528
+ */
529
+ readonly outdir: string;
530
+ /**
531
+ * Schema names to process.
532
+ */
533
+ readonly schemaNames: readonly string[];
534
+ /**
535
+ * Inject configuration per schema.
536
+ * Maps schema name to inject file paths (absolute paths).
537
+ */
538
+ readonly injects: Record<string, {
539
+ readonly scalars: string;
540
+ }>;
541
+ /**
542
+ * Whether to include import extensions in generated code.
543
+ */
544
+ readonly importExtension?: boolean;
545
+ };
546
+ /**
547
+ * Result of a successful typegen run.
548
+ */
549
+ type TypegenSuccess = {
550
+ /**
551
+ * Path to the generated types.prebuilt.ts file.
552
+ */
553
+ readonly prebuiltTypesPath: string;
554
+ /**
555
+ * Number of fragments processed.
556
+ */
557
+ readonly fragmentCount: number;
558
+ /**
559
+ * Number of operations processed.
560
+ */
561
+ readonly operationCount: number;
562
+ /**
563
+ * Number of fragments skipped due to missing 'key' property.
564
+ */
565
+ readonly skippedFragmentCount: number;
566
+ /**
567
+ * Warnings encountered during type generation.
568
+ */
569
+ readonly warnings: readonly string[];
570
+ };
571
+ /**
572
+ * Result type for typegen operations.
573
+ */
574
+ type TypegenResult = Result<TypegenSuccess, TypegenError>;
575
+ //#endregion
576
+ //#region packages/tools/src/typegen/runner.d.ts
577
+ /**
578
+ * Options for running typegen.
579
+ */
580
+ type RunTypegenOptions = {
581
+ /**
582
+ * Resolved soda-gql configuration.
583
+ */
584
+ readonly config: ResolvedSodaGqlConfig;
585
+ };
586
+ /**
587
+ * Run the typegen process.
588
+ *
589
+ * This function:
590
+ * 1. Loads schemas from the generated CJS bundle
591
+ * 2. Creates a BuilderService and builds the artifact
592
+ * 3. Extracts field selections from the artifact
593
+ * 4. Scans source files for tagged templates and merges selections
594
+ * 5. Emits types.prebuilt.ts using emitPrebuiltTypes
595
+ *
596
+ * @param options - Typegen options including config
597
+ * @returns Result containing success data or error
598
+ */
599
+ declare const runTypegen: (options: RunTypegenOptions) => Promise<TypegenResult>;
600
+ /**
601
+ * Merge builder and template selections into a combined map.
602
+ *
603
+ * Builder selections are authoritative — VM evaluation correctly resolves
604
+ * fragment spreads that static template analysis cannot handle.
605
+ * Template selections serve as fallback for elements only found by the scanner.
606
+ *
607
+ * Deduplication is per-element (file + GraphQL name), not per-file, so that
608
+ * callback-builder operations in files that also contain tagged templates are preserved.
609
+ */
610
+ declare const mergeSelections: (builderSelections: ReadonlyMap<CanonicalId, FieldSelectionData>, templateSelections: ReadonlyMap<CanonicalId, FieldSelectionData>, baseDir: string) => Map<CanonicalId, FieldSelectionData>;
611
+ //#endregion
612
+ //#region packages/tools/src/cli/errors.d.ts
613
+ /**
614
+ * CLI-specific error codes.
615
+ */
616
+ type CliErrorCode = "CLI_ARGS_INVALID" | "CLI_UNKNOWN_COMMAND" | "CLI_UNKNOWN_SUBCOMMAND" | "CLI_FILE_EXISTS" | "CLI_FILE_NOT_FOUND" | "CLI_WRITE_FAILED" | "CLI_READ_FAILED" | "CLI_NO_PATTERNS" | "CLI_FORMATTER_NOT_INSTALLED" | "CLI_PARSE_ERROR" | "CLI_FORMAT_ERROR" | "CLI_DUPLICATE_FRAGMENT" | "CLI_FRAGMENT_NOT_FOUND" | "CLI_UNEXPECTED";
617
+ /**
618
+ * Unified CLI error discriminated union.
619
+ * Wraps external errors (codegen, builder, config, typegen) and defines CLI-specific errors.
620
+ */
621
+ type CliError = {
622
+ readonly category: "codegen";
623
+ readonly error: CodegenError;
624
+ } | {
625
+ readonly category: "builder";
626
+ readonly error: BuilderError;
627
+ } | {
628
+ readonly category: "artifact";
629
+ readonly error: ArtifactLoadError;
630
+ } | {
631
+ readonly category: "config";
632
+ readonly error: ConfigError;
633
+ } | {
634
+ readonly category: "typegen";
635
+ readonly error: TypegenError;
636
+ } | {
637
+ readonly category: "cli";
638
+ readonly code: "CLI_ARGS_INVALID";
639
+ readonly message: string;
640
+ readonly command: string;
641
+ } | {
642
+ readonly category: "cli";
643
+ readonly code: "CLI_UNKNOWN_COMMAND";
644
+ readonly message: string;
645
+ readonly command: string;
646
+ } | {
647
+ readonly category: "cli";
648
+ readonly code: "CLI_UNKNOWN_SUBCOMMAND";
649
+ readonly message: string;
650
+ readonly parent: string;
651
+ readonly subcommand: string;
652
+ } | {
653
+ readonly category: "cli";
654
+ readonly code: "CLI_FILE_EXISTS";
655
+ readonly message: string;
656
+ readonly filePath: string;
657
+ } | {
658
+ readonly category: "cli";
659
+ readonly code: "CLI_FILE_NOT_FOUND";
660
+ readonly message: string;
661
+ readonly filePath: string;
662
+ } | {
663
+ readonly category: "cli";
664
+ readonly code: "CLI_WRITE_FAILED";
665
+ readonly message: string;
666
+ readonly filePath: string;
667
+ readonly cause?: unknown;
668
+ } | {
669
+ readonly category: "cli";
670
+ readonly code: "CLI_READ_FAILED";
671
+ readonly message: string;
672
+ readonly filePath: string;
673
+ readonly cause?: unknown;
674
+ } | {
675
+ readonly category: "cli";
676
+ readonly code: "CLI_NO_PATTERNS";
677
+ readonly message: string;
678
+ } | {
679
+ readonly category: "cli";
680
+ readonly code: "CLI_FORMATTER_NOT_INSTALLED";
681
+ readonly message: string;
682
+ } | {
683
+ readonly category: "cli";
684
+ readonly code: "CLI_PARSE_ERROR";
685
+ readonly message: string;
686
+ readonly filePath?: string;
687
+ } | {
688
+ readonly category: "cli";
689
+ readonly code: "CLI_FORMAT_ERROR";
690
+ readonly message: string;
691
+ readonly filePath?: string;
692
+ } | {
693
+ readonly category: "cli";
694
+ readonly code: "CLI_DUPLICATE_FRAGMENT";
695
+ readonly message: string;
696
+ readonly fragmentName: string;
697
+ readonly existingFile: string;
698
+ readonly newFile: string;
699
+ } | {
700
+ readonly category: "cli";
701
+ readonly code: "CLI_FRAGMENT_NOT_FOUND";
702
+ readonly message: string;
703
+ readonly fragmentName: string;
704
+ readonly referencedIn: string;
705
+ } | {
706
+ readonly category: "cli";
707
+ readonly code: "CLI_UNEXPECTED";
708
+ readonly message: string;
709
+ readonly cause?: unknown;
710
+ };
711
+ /**
712
+ * Result type for CLI operations.
713
+ */
714
+ type CliResult<T> = Result<T, CliError>;
715
+ type CliArgsInvalidError = Extract<CliError, {
716
+ code: "CLI_ARGS_INVALID";
717
+ }>;
718
+ type CliUnknownCommandError = Extract<CliError, {
719
+ code: "CLI_UNKNOWN_COMMAND";
720
+ }>;
721
+ type CliUnknownSubcommandError = Extract<CliError, {
722
+ code: "CLI_UNKNOWN_SUBCOMMAND";
723
+ }>;
724
+ type CliFileExistsError = Extract<CliError, {
725
+ code: "CLI_FILE_EXISTS";
726
+ }>;
727
+ type CliFileNotFoundError = Extract<CliError, {
728
+ code: "CLI_FILE_NOT_FOUND";
729
+ }>;
730
+ type CliWriteFailedError = Extract<CliError, {
731
+ code: "CLI_WRITE_FAILED";
732
+ }>;
733
+ type CliReadFailedError = Extract<CliError, {
734
+ code: "CLI_READ_FAILED";
735
+ }>;
736
+ type CliNoPatternsError = Extract<CliError, {
737
+ code: "CLI_NO_PATTERNS";
738
+ }>;
739
+ type CliFormatterNotInstalledError = Extract<CliError, {
740
+ code: "CLI_FORMATTER_NOT_INSTALLED";
741
+ }>;
742
+ type CliParseErrorError = Extract<CliError, {
743
+ code: "CLI_PARSE_ERROR";
744
+ }>;
745
+ type CliFormatErrorError = Extract<CliError, {
746
+ code: "CLI_FORMAT_ERROR";
747
+ }>;
748
+ type CliDuplicateFragmentError = Extract<CliError, {
749
+ code: "CLI_DUPLICATE_FRAGMENT";
750
+ }>;
751
+ type CliFragmentNotFoundError = Extract<CliError, {
752
+ code: "CLI_FRAGMENT_NOT_FOUND";
753
+ }>;
754
+ type CliUnexpectedError = Extract<CliError, {
755
+ code: "CLI_UNEXPECTED";
756
+ }>;
757
+ type CliCodegenError = Extract<CliError, {
758
+ category: "codegen";
759
+ }>;
760
+ type CliBuilderError = Extract<CliError, {
761
+ category: "builder";
762
+ }>;
763
+ type CliArtifactError = Extract<CliError, {
764
+ category: "artifact";
765
+ }>;
766
+ type CliConfigError = Extract<CliError, {
767
+ category: "config";
768
+ }>;
769
+ type CliTypegenError = Extract<CliError, {
770
+ category: "typegen";
771
+ }>;
772
+ /**
773
+ * Error constructor helpers for concise error creation.
774
+ * Each function returns a specific error type for better type inference.
775
+ */
776
+ declare const cliErrors: {
777
+ readonly argsInvalid: (command: string, message: string) => CliArgsInvalidError;
778
+ readonly unknownCommand: (command: string) => CliUnknownCommandError;
779
+ readonly unknownSubcommand: (parent: string, subcommand: string) => CliUnknownSubcommandError;
780
+ readonly fileExists: (filePath: string, message?: string) => CliFileExistsError;
781
+ readonly fileNotFound: (filePath: string, message?: string) => CliFileNotFoundError;
782
+ readonly writeFailed: (filePath: string, message?: string, cause?: unknown) => CliWriteFailedError;
783
+ readonly readFailed: (filePath: string, message?: string, cause?: unknown) => CliReadFailedError;
784
+ readonly noPatterns: (message?: string) => CliNoPatternsError;
785
+ readonly formatterNotInstalled: (message?: string) => CliFormatterNotInstalledError;
786
+ readonly parseError: (message: string, filePath?: string) => CliParseErrorError;
787
+ readonly formatError: (message: string, filePath?: string) => CliFormatErrorError;
788
+ readonly duplicateFragment: (fragmentName: string, existingFile: string, newFile: string) => CliDuplicateFragmentError;
789
+ readonly fragmentNotFound: (fragmentName: string, referencedIn: string) => CliFragmentNotFoundError;
790
+ readonly unexpected: (message: string, cause?: unknown) => CliUnexpectedError;
791
+ readonly fromCodegen: (error: CodegenError) => CliCodegenError;
792
+ readonly fromBuilder: (error: BuilderError) => CliBuilderError;
793
+ readonly fromArtifact: (error: ArtifactLoadError) => CliArtifactError;
794
+ readonly fromConfig: (error: ConfigError) => CliConfigError;
795
+ readonly fromTypegen: (error: TypegenError) => CliTypegenError;
796
+ };
797
+ /**
798
+ * Convenience helper to create an err Result from CliError.
799
+ */
800
+ declare const cliErr: <T = never>(error: CliError) => CliResult<T>;
801
+ /**
802
+ * Type guard to check if error is a CLI-specific error.
803
+ */
804
+ declare const isCliError: (error: CliError) => error is CliError & {
805
+ category: "cli";
806
+ };
807
+ /**
808
+ * Extract error code from any CliError variant.
809
+ */
810
+ declare const getErrorCode: (error: CliError) => string;
811
+ /**
812
+ * Extract error message from any CliError variant.
813
+ */
814
+ declare const getErrorMessage: (error: CliError) => string;
815
+ //#endregion
816
+ //#region packages/tools/src/cli/types.d.ts
817
+ /**
818
+ * Result type for all CLI commands.
819
+ */
820
+ type CommandResult<T = CommandSuccess> = Result<T, CliError>;
821
+ /**
822
+ * Standard success response for commands.
823
+ */
824
+ type CommandSuccess = {
825
+ readonly message: string;
826
+ };
827
+ /**
828
+ * Output format for CLI responses.
829
+ */
830
+ type OutputFormat = "human" | "json";
831
+ //#endregion
832
+ //#region packages/tools/src/cli/index.d.ts
833
+ type DispatchResult = CommandResult<CommandSuccess & {
834
+ exitCode?: number;
835
+ }>;
836
+ declare const dispatch: (argv: readonly string[]) => Promise<DispatchResult>;
837
+ //#endregion
838
+ export { dispatch };
839
+ //# sourceMappingURL=bin.d.cts.map