@soda-gql/builder 0.0.1

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.
@@ -0,0 +1,820 @@
1
+ import { CanonicalId, CanonicalId as CanonicalId$1, CanonicalPathTracker, ScopeFrame, ScopeHandle, buildAstPath, createCanonicalId, createCanonicalTracker, createOccurrenceTracker, createPathTracker } from "@soda-gql/common";
2
+ import { ZodSchema, z } from "zod";
3
+ import * as neverthrow0 from "neverthrow";
4
+ import { Result } from "neverthrow";
5
+ import { Script } from "node:vm";
6
+ import { AnyComposedOperation, AnyInlineOperation, AnyModel, AnySlice } from "@soda-gql/core";
7
+ import { RuntimeComposedOperationInput, RuntimeInlineOperationInput, RuntimeModelInput, RuntimeSliceInput } from "@soda-gql/core/runtime";
8
+ import { ResolvedSodaGqlConfig } from "@soda-gql/config";
9
+
10
+ //#region packages/builder/src/intermediate-module/types.d.ts
11
+ type IntermediateModule = {
12
+ readonly filePath: string;
13
+ readonly canonicalIds: readonly string[];
14
+ readonly sourceCode: string;
15
+ readonly transpiledCode: string;
16
+ readonly contentHash: string;
17
+ readonly script: Script;
18
+ };
19
+ type IntermediateArtifactElement = {
20
+ readonly type: "model";
21
+ readonly element: AnyModel;
22
+ } | {
23
+ readonly type: "slice";
24
+ readonly element: AnySlice;
25
+ } | {
26
+ readonly type: "operation";
27
+ readonly element: AnyComposedOperation;
28
+ } | {
29
+ readonly type: "inlineOperation";
30
+ readonly element: AnyInlineOperation;
31
+ };
32
+ //#endregion
33
+ //#region packages/builder/src/internal/graphql-system.d.ts
34
+ type GraphqlSystemIdentifyHelper = {
35
+ readonly isGraphqlSystemFile: (input: {
36
+ filePath: string;
37
+ }) => boolean;
38
+ readonly isGraphqlSystemImportSpecifier: (input: {
39
+ filePath: string;
40
+ specifier: string;
41
+ }) => boolean;
42
+ };
43
+ /**
44
+ * Create a GraphqlSystemIdentifyHelper from the resolved config.
45
+ * Uses canonical path comparison to handle casing, symlinks, and aliases.
46
+ */
47
+ declare const createGraphqlSystemIdentifyHelper: (config: ResolvedSodaGqlConfig) => GraphqlSystemIdentifyHelper;
48
+ //#endregion
49
+ //#region packages/builder/src/errors.d.ts
50
+ /**
51
+ * Comprehensive error code taxonomy for Builder operations.
52
+ */
53
+ type BuilderErrorCode = "ENTRY_NOT_FOUND" | "CONFIG_NOT_FOUND" | "CONFIG_INVALID" | "DISCOVERY_IO_ERROR" | "FINGERPRINT_FAILED" | "UNSUPPORTED_ANALYZER" | "CANONICAL_PATH_INVALID" | "CANONICAL_SCOPE_MISMATCH" | "GRAPH_CIRCULAR_DEPENDENCY" | "GRAPH_MISSING_IMPORT" | "DOC_DUPLICATE" | "WRITE_FAILED" | "CACHE_CORRUPTED" | "RUNTIME_MODULE_LOAD_FAILED" | "ARTIFACT_REGISTRATION_FAILED" | "INTERNAL_INVARIANT";
54
+ /**
55
+ * Structured error type for all Builder operations.
56
+ */
57
+ type BuilderError = {
58
+ readonly code: "ENTRY_NOT_FOUND";
59
+ readonly message: string;
60
+ readonly entry: string;
61
+ } | {
62
+ readonly code: "CONFIG_NOT_FOUND";
63
+ readonly message: string;
64
+ readonly path: string;
65
+ } | {
66
+ readonly code: "CONFIG_INVALID";
67
+ readonly message: string;
68
+ readonly path: string;
69
+ readonly cause?: unknown;
70
+ } | {
71
+ readonly code: "DISCOVERY_IO_ERROR";
72
+ readonly message: string;
73
+ readonly path: string;
74
+ readonly errno?: string | number;
75
+ readonly cause?: unknown;
76
+ } | {
77
+ readonly code: "FINGERPRINT_FAILED";
78
+ readonly message: string;
79
+ readonly filePath: string;
80
+ readonly cause?: unknown;
81
+ } | {
82
+ readonly code: "UNSUPPORTED_ANALYZER";
83
+ readonly message: string;
84
+ readonly analyzer: string;
85
+ } | {
86
+ readonly code: "CANONICAL_PATH_INVALID";
87
+ readonly message: string;
88
+ readonly path: string;
89
+ readonly reason?: string;
90
+ } | {
91
+ readonly code: "CANONICAL_SCOPE_MISMATCH";
92
+ readonly message: string;
93
+ readonly expected: string;
94
+ readonly actual: string;
95
+ } | {
96
+ readonly code: "GRAPH_CIRCULAR_DEPENDENCY";
97
+ readonly message: string;
98
+ readonly chain: readonly string[];
99
+ } | {
100
+ readonly code: "GRAPH_MISSING_IMPORT";
101
+ readonly message: string;
102
+ readonly importer: string;
103
+ readonly importee: string;
104
+ } | {
105
+ readonly code: "DOC_DUPLICATE";
106
+ readonly message: string;
107
+ readonly name: string;
108
+ readonly sources: readonly string[];
109
+ } | {
110
+ readonly code: "WRITE_FAILED";
111
+ readonly message: string;
112
+ readonly outPath: string;
113
+ readonly cause?: unknown;
114
+ } | {
115
+ readonly code: "CACHE_CORRUPTED";
116
+ readonly message: string;
117
+ readonly cachePath?: string;
118
+ readonly cause?: unknown;
119
+ } | {
120
+ readonly code: "RUNTIME_MODULE_LOAD_FAILED";
121
+ readonly message: string;
122
+ readonly filePath: string;
123
+ readonly astPath: string;
124
+ readonly cause?: unknown;
125
+ } | {
126
+ readonly code: "ARTIFACT_REGISTRATION_FAILED";
127
+ readonly message: string;
128
+ readonly elementId: string;
129
+ readonly reason: string;
130
+ } | {
131
+ readonly code: "INTERNAL_INVARIANT";
132
+ readonly message: string;
133
+ readonly context?: string;
134
+ readonly cause?: unknown;
135
+ };
136
+ /**
137
+ * Helper type for Builder operation results.
138
+ */
139
+ type BuilderResult<T> = Result<T, BuilderError>;
140
+ /**
141
+ * Error constructor helpers for concise error creation.
142
+ */
143
+ declare const builderErrors: {
144
+ readonly entryNotFound: (entry: string, message?: string) => BuilderError;
145
+ readonly configNotFound: (path: string, message?: string) => BuilderError;
146
+ readonly configInvalid: (path: string, message: string, cause?: unknown) => BuilderError;
147
+ readonly discoveryIOError: (path: string, message: string, errno?: string | number, cause?: unknown) => BuilderError;
148
+ readonly fingerprintFailed: (filePath: string, message: string, cause?: unknown) => BuilderError;
149
+ readonly unsupportedAnalyzer: (analyzer: string, message?: string) => BuilderError;
150
+ readonly canonicalPathInvalid: (path: string, reason?: string) => BuilderError;
151
+ readonly canonicalScopeMismatch: (expected: string, actual: string) => BuilderError;
152
+ readonly graphCircularDependency: (chain: readonly string[]) => BuilderError;
153
+ readonly graphMissingImport: (importer: string, importee: string) => BuilderError;
154
+ readonly docDuplicate: (name: string, sources: readonly string[]) => BuilderError;
155
+ readonly writeFailed: (outPath: string, message: string, cause?: unknown) => BuilderError;
156
+ readonly cacheCorrupted: (message: string, cachePath?: string, cause?: unknown) => BuilderError;
157
+ readonly runtimeModuleLoadFailed: (filePath: string, astPath: string, message: string, cause?: unknown) => BuilderError;
158
+ readonly artifactRegistrationFailed: (elementId: string, reason: string) => BuilderError;
159
+ readonly internalInvariant: (message: string, context?: string, cause?: unknown) => BuilderError;
160
+ };
161
+ /**
162
+ * Convenience helper to create an err Result from BuilderError.
163
+ */
164
+ declare const builderErr: <T = never>(error: BuilderError) => BuilderResult<T>;
165
+ /**
166
+ * Type guard for BuilderError.
167
+ */
168
+ declare const isBuilderError: (error: unknown) => error is BuilderError;
169
+ /**
170
+ * Format BuilderError for console output (human-readable).
171
+ */
172
+ declare const formatBuilderError: (error: BuilderError) => string;
173
+ /**
174
+ * Assert unreachable code path (for exhaustiveness checks).
175
+ * This is the ONLY acceptable throw in builder code.
176
+ */
177
+ declare const assertUnreachable: (value: never, context?: string) => never;
178
+ //#endregion
179
+ //#region packages/builder/src/types.d.ts
180
+ type BuilderMode = "runtime" | "zero-runtime";
181
+ type BuilderFormat = "json" | "human";
182
+ type BuilderAnalyzer = "ts" | "swc";
183
+ type BuilderInput = Record<string, never>;
184
+ type BuilderOptions = BuilderInput & {
185
+ readonly outPath: string;
186
+ readonly format: BuilderFormat;
187
+ };
188
+ //#endregion
189
+ //#region packages/builder/src/ast/types.d.ts
190
+ type SourcePosition = {
191
+ readonly line: number;
192
+ readonly column: number;
193
+ };
194
+ type SourceLocation = {
195
+ readonly start: SourcePosition;
196
+ readonly end: SourcePosition;
197
+ };
198
+ type ModuleDefinition = {
199
+ readonly canonicalId: CanonicalId$1;
200
+ /** AST-derived path uniquely identifying this definition's location (e.g., "MyComponent.useQuery.def") */
201
+ readonly astPath: string;
202
+ /** Whether this definition is at the top level of the module */
203
+ readonly isTopLevel: boolean;
204
+ /** Whether this definition is exported from the module */
205
+ readonly isExported: boolean;
206
+ /** The export binding name if this definition is exported */
207
+ readonly exportBinding?: string;
208
+ readonly loc: SourceLocation;
209
+ readonly expression: string;
210
+ };
211
+ type ModuleDiagnostic = {
212
+ readonly code: "NON_TOP_LEVEL_DEFINITION";
213
+ readonly message: string;
214
+ readonly loc: SourceLocation;
215
+ };
216
+ type ModuleImport = {
217
+ readonly source: string;
218
+ readonly imported: string;
219
+ readonly local: string;
220
+ readonly kind: "named" | "namespace" | "default";
221
+ readonly isTypeOnly: boolean;
222
+ };
223
+ type ModuleExport = {
224
+ readonly kind: "named";
225
+ readonly exported: string;
226
+ readonly local: string;
227
+ readonly source?: undefined;
228
+ readonly isTypeOnly: boolean;
229
+ } | {
230
+ readonly kind: "reexport";
231
+ readonly exported: string;
232
+ readonly source: string;
233
+ readonly local?: string;
234
+ readonly isTypeOnly: boolean;
235
+ };
236
+ type ModuleAnalysis = {
237
+ readonly filePath: string;
238
+ readonly signature: string;
239
+ readonly definitions: readonly ModuleDefinition[];
240
+ readonly diagnostics: readonly ModuleDiagnostic[];
241
+ readonly imports: readonly ModuleImport[];
242
+ readonly exports: readonly ModuleExport[];
243
+ };
244
+ type AnalyzeModuleInput = {
245
+ readonly filePath: string;
246
+ readonly source: string;
247
+ };
248
+ //#endregion
249
+ //#region packages/builder/src/ast/index.d.ts
250
+ declare const createAstAnalyzer: ({
251
+ analyzer,
252
+ graphqlHelper
253
+ }: {
254
+ readonly analyzer: BuilderAnalyzer;
255
+ readonly graphqlHelper: GraphqlSystemIdentifyHelper;
256
+ }) => {
257
+ type: BuilderAnalyzer;
258
+ analyze: (input: AnalyzeModuleInput) => ModuleAnalysis;
259
+ };
260
+ declare const getAstAnalyzer: (analyzer: BuilderAnalyzer) => never;
261
+ //#endregion
262
+ //#region packages/builder/src/intermediate-module/evaluation.d.ts
263
+ type BuildIntermediateModulesInput = {
264
+ readonly analyses: Map<string, ModuleAnalysis>;
265
+ readonly targetFiles: Set<string>;
266
+ };
267
+ /**
268
+ * Build intermediate modules from dependency graph.
269
+ * Each intermediate module corresponds to one source file.
270
+ */
271
+ declare const generateIntermediateModules: ({
272
+ analyses,
273
+ targetFiles
274
+ }: BuildIntermediateModulesInput) => Generator<IntermediateModule, void, undefined>;
275
+ declare const evaluateIntermediateModules: ({
276
+ intermediateModules,
277
+ graphqlSystemPath
278
+ }: {
279
+ intermediateModules: Map<string, IntermediateModule>;
280
+ graphqlSystemPath: string;
281
+ }) => Record<string, IntermediateArtifactElement>;
282
+ //#endregion
283
+ //#region packages/builder/src/artifact/types.d.ts
284
+ type IntermediateElements = Record<CanonicalId$1, IntermediateArtifactElement>;
285
+ type BuilderArtifactElementMetadata = {
286
+ readonly sourcePath: string;
287
+ readonly sourceHash: string;
288
+ readonly contentHash: string;
289
+ };
290
+ type BuilderArtifactElementBase = {
291
+ readonly id: CanonicalId$1;
292
+ readonly metadata: BuilderArtifactElementMetadata;
293
+ };
294
+ type BuilderArtifactOperation = BuilderArtifactElementBase & {
295
+ readonly type: "operation";
296
+ readonly prebuild: RuntimeComposedOperationInput["prebuild"];
297
+ };
298
+ type BuilderArtifactInlineOperation = BuilderArtifactElementBase & {
299
+ readonly type: "inlineOperation";
300
+ readonly prebuild: RuntimeInlineOperationInput["prebuild"];
301
+ };
302
+ type BuilderArtifactSlice = BuilderArtifactElementBase & {
303
+ readonly type: "slice";
304
+ readonly prebuild: RuntimeSliceInput["prebuild"];
305
+ };
306
+ type BuilderArtifactModel = BuilderArtifactElementBase & {
307
+ readonly type: "model";
308
+ readonly prebuild: RuntimeModelInput["prebuild"];
309
+ };
310
+ type BuilderArtifactElement = BuilderArtifactOperation | BuilderArtifactInlineOperation | BuilderArtifactSlice | BuilderArtifactModel;
311
+ type BuilderArtifact = {
312
+ readonly elements: Record<CanonicalId$1, BuilderArtifactElement>;
313
+ readonly report: {
314
+ readonly durationMs: number;
315
+ readonly warnings: readonly string[];
316
+ readonly stats: {
317
+ readonly hits: number;
318
+ readonly misses: number;
319
+ readonly skips: number;
320
+ };
321
+ };
322
+ };
323
+ //#endregion
324
+ //#region packages/builder/src/discovery/fingerprint.d.ts
325
+ /**
326
+ * File fingerprint containing hash, size, and modification time
327
+ */
328
+ type FileFingerprint = {
329
+ /** xxHash hash of file contents */
330
+ hash: string;
331
+ /** File size in bytes */
332
+ sizeBytes: number;
333
+ /** Last modification time in milliseconds since epoch */
334
+ mtimeMs: number;
335
+ };
336
+ /**
337
+ * Fingerprint computation error types
338
+ */
339
+ type FingerprintError = {
340
+ code: "FILE_NOT_FOUND";
341
+ path: string;
342
+ message: string;
343
+ } | {
344
+ code: "NOT_A_FILE";
345
+ path: string;
346
+ message: string;
347
+ } | {
348
+ code: "READ_ERROR";
349
+ path: string;
350
+ message: string;
351
+ };
352
+ /**
353
+ * Compute file fingerprint with memoization.
354
+ * Uses mtime to short-circuit re-hashing unchanged files.
355
+ *
356
+ * @param path - Absolute path to file
357
+ * @returns Result containing FileFingerprint or FingerprintError
358
+ */
359
+ declare function computeFingerprint(path: string): Result<FileFingerprint, FingerprintError>;
360
+ /**
361
+ * Invalidate cached fingerprint for a specific path
362
+ *
363
+ * @param path - Absolute path to invalidate
364
+ */
365
+ declare function invalidateFingerprint(path: string): void;
366
+ /**
367
+ * Clear all cached fingerprints
368
+ */
369
+ declare function clearFingerprintCache(): void;
370
+ //#endregion
371
+ //#region packages/builder/src/discovery/types.d.ts
372
+ /**
373
+ * Result of resolving a single import specifier encountered during discovery.
374
+ */
375
+ type DiscoveredDependency = {
376
+ /** Module specifier exactly as it appeared in source. */
377
+ readonly specifier: string;
378
+ /** Absolute, normalized path when the specifier points to a local file; null for bare package imports. */
379
+ readonly resolvedPath: string | null;
380
+ /** True when the specifier targets an external package (i.e. no local snapshot will exist). */
381
+ readonly isExternal: boolean;
382
+ };
383
+ /**
384
+ * Immutable cacheable record produced by the discovery phase for a single source file.
385
+ * Captures analyzer output, dependency fan-out, and bookkeeping metadata.
386
+ */
387
+ type DiscoverySnapshot = {
388
+ /** Absolute path to the analyzed file (preserves original casing). */
389
+ readonly filePath: string;
390
+ /** Normalized path (POSIX separators) used as a stable cache key. */
391
+ readonly normalizedFilePath: string;
392
+ /** Signature of the source contents used to validate cache entries. */
393
+ readonly signature: string;
394
+ /** File fingerprint for fast cache invalidation. */
395
+ readonly fingerprint: FileFingerprint;
396
+ /** Analyzer type identifier for cache versioning. */
397
+ readonly analyzer: string;
398
+ /** Milliseconds since epoch when this snapshot was created. */
399
+ readonly createdAtMs: number;
400
+ /** Raw analyzer output (imports, exports, definitions, diagnostics). */
401
+ readonly analysis: ModuleAnalysis;
402
+ /** Resolved graph edges for relative imports encountered in the file. */
403
+ readonly dependencies: readonly DiscoveredDependency[];
404
+ };
405
+ /**
406
+ * Cache abstraction for storing and retrieving discovery snapshots.
407
+ * Implementations can back onto disk, memory, or remote stores.
408
+ */
409
+ interface DiscoveryCache {
410
+ /**
411
+ * Look up a snapshot by file path and signature.
412
+ * Returns null when the cache entry is missing or stale.
413
+ */
414
+ load(filePath: string, signature: string): DiscoverySnapshot | null;
415
+ /**
416
+ * Peek at cached snapshot without signature validation.
417
+ * Used for fingerprint-based cache invalidation.
418
+ * Returns null when the cache entry is missing.
419
+ */
420
+ peek(filePath: string): DiscoverySnapshot | null;
421
+ /**
422
+ * Persist the provided snapshot.
423
+ */
424
+ store(snapshot: DiscoverySnapshot): void;
425
+ /**
426
+ * Remove a snapshot when a file is deleted or invalidated.
427
+ */
428
+ delete(filePath: string): void;
429
+ /**
430
+ * Enumerate all cached snapshots (used to seed incremental builds).
431
+ */
432
+ entries(): IterableIterator<DiscoverySnapshot>;
433
+ /**
434
+ * Drop every cached entry (useful when analyzer versions change).
435
+ */
436
+ clear(): void;
437
+ /**
438
+ * Total number of entries currently stored.
439
+ */
440
+ size(): number;
441
+ }
442
+ type ModuleLoadStats = {
443
+ readonly hits: number;
444
+ readonly misses: number;
445
+ readonly skips: number;
446
+ };
447
+ //#endregion
448
+ //#region packages/builder/src/schemas/artifact.d.ts
449
+ declare const BuilderArtifactElementSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
450
+ id: z.core.$ZodType<CanonicalId$1, CanonicalId$1, z.core.$ZodTypeInternals<CanonicalId$1, CanonicalId$1>>;
451
+ type: z.ZodLiteral<"operation">;
452
+ metadata: z.ZodObject<{
453
+ sourcePath: z.ZodString;
454
+ sourceHash: z.ZodString;
455
+ contentHash: z.ZodString;
456
+ }, z.core.$strip>;
457
+ prebuild: z.ZodObject<{
458
+ operationType: z.ZodEnum<{
459
+ query: "query";
460
+ mutation: "mutation";
461
+ subscription: "subscription";
462
+ }>;
463
+ operationName: z.ZodString;
464
+ document: z.ZodUnknown;
465
+ variableNames: z.ZodArray<z.ZodString>;
466
+ projectionPathGraph: z.ZodUnknown;
467
+ }, z.core.$strip>;
468
+ }, z.core.$strip>, z.ZodObject<{
469
+ id: z.core.$ZodType<CanonicalId$1, CanonicalId$1, z.core.$ZodTypeInternals<CanonicalId$1, CanonicalId$1>>;
470
+ type: z.ZodLiteral<"slice">;
471
+ metadata: z.ZodObject<{
472
+ sourcePath: z.ZodString;
473
+ sourceHash: z.ZodString;
474
+ contentHash: z.ZodString;
475
+ }, z.core.$strip>;
476
+ prebuild: z.ZodObject<{
477
+ operationType: z.ZodEnum<{
478
+ query: "query";
479
+ mutation: "mutation";
480
+ subscription: "subscription";
481
+ }>;
482
+ }, z.core.$strip>;
483
+ }, z.core.$strip>, z.ZodObject<{
484
+ id: z.core.$ZodType<CanonicalId$1, CanonicalId$1, z.core.$ZodTypeInternals<CanonicalId$1, CanonicalId$1>>;
485
+ type: z.ZodLiteral<"model">;
486
+ metadata: z.ZodObject<{
487
+ sourcePath: z.ZodString;
488
+ sourceHash: z.ZodString;
489
+ contentHash: z.ZodString;
490
+ }, z.core.$strip>;
491
+ prebuild: z.ZodObject<{
492
+ typename: z.ZodString;
493
+ }, z.core.$strip>;
494
+ }, z.core.$strip>], "type">;
495
+ declare const BuilderArtifactSchema: z.ZodObject<{
496
+ elements: z.ZodRecord<z.core.$ZodType<CanonicalId$1, CanonicalId$1, z.core.$ZodTypeInternals<CanonicalId$1, CanonicalId$1>>, z.ZodDiscriminatedUnion<[z.ZodObject<{
497
+ id: z.core.$ZodType<CanonicalId$1, CanonicalId$1, z.core.$ZodTypeInternals<CanonicalId$1, CanonicalId$1>>;
498
+ type: z.ZodLiteral<"operation">;
499
+ metadata: z.ZodObject<{
500
+ sourcePath: z.ZodString;
501
+ sourceHash: z.ZodString;
502
+ contentHash: z.ZodString;
503
+ }, z.core.$strip>;
504
+ prebuild: z.ZodObject<{
505
+ operationType: z.ZodEnum<{
506
+ query: "query";
507
+ mutation: "mutation";
508
+ subscription: "subscription";
509
+ }>;
510
+ operationName: z.ZodString;
511
+ document: z.ZodUnknown;
512
+ variableNames: z.ZodArray<z.ZodString>;
513
+ projectionPathGraph: z.ZodUnknown;
514
+ }, z.core.$strip>;
515
+ }, z.core.$strip>, z.ZodObject<{
516
+ id: z.core.$ZodType<CanonicalId$1, CanonicalId$1, z.core.$ZodTypeInternals<CanonicalId$1, CanonicalId$1>>;
517
+ type: z.ZodLiteral<"slice">;
518
+ metadata: z.ZodObject<{
519
+ sourcePath: z.ZodString;
520
+ sourceHash: z.ZodString;
521
+ contentHash: z.ZodString;
522
+ }, z.core.$strip>;
523
+ prebuild: z.ZodObject<{
524
+ operationType: z.ZodEnum<{
525
+ query: "query";
526
+ mutation: "mutation";
527
+ subscription: "subscription";
528
+ }>;
529
+ }, z.core.$strip>;
530
+ }, z.core.$strip>, z.ZodObject<{
531
+ id: z.core.$ZodType<CanonicalId$1, CanonicalId$1, z.core.$ZodTypeInternals<CanonicalId$1, CanonicalId$1>>;
532
+ type: z.ZodLiteral<"model">;
533
+ metadata: z.ZodObject<{
534
+ sourcePath: z.ZodString;
535
+ sourceHash: z.ZodString;
536
+ contentHash: z.ZodString;
537
+ }, z.core.$strip>;
538
+ prebuild: z.ZodObject<{
539
+ typename: z.ZodString;
540
+ }, z.core.$strip>;
541
+ }, z.core.$strip>], "type">>;
542
+ report: z.ZodObject<{
543
+ durationMs: z.ZodNumber;
544
+ warnings: z.ZodArray<z.ZodString>;
545
+ stats: z.ZodObject<{
546
+ hits: z.ZodNumber;
547
+ misses: z.ZodNumber;
548
+ skips: z.ZodNumber;
549
+ }, z.core.$strip>;
550
+ }, z.core.$strip>;
551
+ }, z.core.$strip>;
552
+ type BuilderArtifact$1 = z.infer<typeof BuilderArtifactSchema>;
553
+ type BuilderArtifactElement$1 = z.infer<typeof BuilderArtifactElementSchema>;
554
+ //#endregion
555
+ //#region packages/builder/src/service.d.ts
556
+ /**
557
+ * Configuration for BuilderService.
558
+ * Mirrors BuilderInput shape.
559
+ */
560
+ type BuilderServiceConfig = {
561
+ readonly config: ResolvedSodaGqlConfig;
562
+ readonly entrypointsOverride?: readonly string[] | ReadonlySet<string>;
563
+ };
564
+ /**
565
+ * Builder service interface providing artifact generation.
566
+ */
567
+ interface BuilderService {
568
+ /**
569
+ * Generate artifacts from configured entry points.
570
+ *
571
+ * The service automatically detects file changes using an internal file tracker.
572
+ * On first call, performs full build. Subsequent calls perform incremental builds
573
+ * based on detected file changes (added/updated/removed).
574
+ *
575
+ * @param options - Optional build options
576
+ * @param options.force - If true, bypass change detection and force full rebuild
577
+ * @returns Result containing BuilderArtifact on success or BuilderError on failure.
578
+ */
579
+ build(options?: {
580
+ force?: boolean;
581
+ }): Result<BuilderArtifact, BuilderError>;
582
+ /**
583
+ * Get the current generation number of the artifact.
584
+ * Increments on each successful build.
585
+ * Returns 0 if no artifact has been built yet.
586
+ */
587
+ getGeneration(): number;
588
+ /**
589
+ * Get the most recent artifact without triggering a new build.
590
+ * Returns null if no artifact has been built yet.
591
+ */
592
+ getCurrentArtifact(): BuilderArtifact | null;
593
+ }
594
+ /**
595
+ * Create a builder service instance with session support.
596
+ *
597
+ * The service maintains a long-lived session for incremental builds.
598
+ * File changes are automatically detected using an internal file tracker.
599
+ * First build() call initializes the session, subsequent calls perform
600
+ * incremental builds based on detected file changes.
601
+ *
602
+ * Note: Empty entry arrays will produce ENTRY_NOT_FOUND errors at build time.
603
+ *
604
+ * @param config - Builder configuration including entry patterns, analyzer, mode, and optional debugDir
605
+ * @returns BuilderService instance
606
+ */
607
+ declare const createBuilderService: ({
608
+ config,
609
+ entrypointsOverride
610
+ }: BuilderServiceConfig) => BuilderService;
611
+ //#endregion
612
+ //#region packages/builder/src/cache/json-cache.d.ts
613
+ type CacheNamespace = readonly string[];
614
+ type JsonCacheFactoryOptions = {
615
+ readonly rootDir: string;
616
+ readonly prefix?: CacheNamespace;
617
+ };
618
+ type JsonCacheStoreOptions<_K extends string, V> = {
619
+ readonly namespace: CacheNamespace;
620
+ readonly schema: z.ZodType<V>;
621
+ readonly version?: string;
622
+ };
623
+ type JsonCacheStore<K extends string, V> = {
624
+ load(key: K): V | null;
625
+ store(key: K, value: V): void;
626
+ delete(key: K): void;
627
+ entries(): IterableIterator<[K, V]>;
628
+ clear(): void;
629
+ size(): number;
630
+ };
631
+ type JsonCacheFactory = {
632
+ createStore<K extends string, V>(options: JsonCacheStoreOptions<K, V>): JsonCacheStore<K, V>;
633
+ clearAll(): void;
634
+ };
635
+ declare const createJsonCache: ({
636
+ rootDir,
637
+ prefix
638
+ }: JsonCacheFactoryOptions) => JsonCacheFactory;
639
+ //#endregion
640
+ //#region packages/builder/src/cache/json-entity-cache.d.ts
641
+ type JsonEntityCacheOptions<V> = {
642
+ readonly factory: JsonCacheFactory;
643
+ readonly namespace: readonly string[];
644
+ readonly schema: ZodSchema<V>;
645
+ readonly version: string;
646
+ readonly keyNormalizer?: (key: string) => string;
647
+ };
648
+ /**
649
+ * Abstract base class for JSON-based entity caches.
650
+ * Provides common caching functionality with signature-based eviction.
651
+ */
652
+ declare abstract class JsonEntityCache<K extends string, V> {
653
+ protected readonly cacheStore: JsonCacheStore<K, V>;
654
+ private readonly keyNormalizer;
655
+ constructor(options: JsonEntityCacheOptions<V>);
656
+ /**
657
+ * Normalize a key for consistent cache lookups.
658
+ */
659
+ protected normalizeKey(key: string): K;
660
+ /**
661
+ * Load raw value from cache without signature validation.
662
+ */
663
+ protected loadRaw(key: K): V | null;
664
+ /**
665
+ * Store raw value to cache.
666
+ */
667
+ protected storeRaw(key: K, value: V): void;
668
+ /**
669
+ * Delete an entry from the cache.
670
+ */
671
+ delete(key: string): void;
672
+ /**
673
+ * Get all cached entries.
674
+ * Subclasses should override this to provide custom iteration.
675
+ */
676
+ protected baseEntries(): IterableIterator<V>;
677
+ /**
678
+ * Clear all entries from the cache.
679
+ */
680
+ clear(): void;
681
+ /**
682
+ * Get the number of entries in the cache.
683
+ */
684
+ size(): number;
685
+ }
686
+ //#endregion
687
+ //#region packages/builder/src/discovery/cache.d.ts
688
+ type DiscoveryCacheOptions = {
689
+ readonly factory: JsonCacheFactory;
690
+ readonly analyzer: string;
691
+ readonly evaluatorId: string;
692
+ readonly namespacePrefix?: readonly string[];
693
+ readonly version?: string;
694
+ };
695
+ declare class JsonDiscoveryCache extends JsonEntityCache<string, DiscoverySnapshot> implements DiscoveryCache {
696
+ constructor(options: DiscoveryCacheOptions);
697
+ load(filePath: string, expectedSignature: string): DiscoverySnapshot | null;
698
+ peek(filePath: string): DiscoverySnapshot | null;
699
+ store(snapshot: DiscoverySnapshot): void;
700
+ entries(): IterableIterator<DiscoverySnapshot>;
701
+ }
702
+ declare const createDiscoveryCache: (options: DiscoveryCacheOptions) => DiscoveryCache;
703
+ //#endregion
704
+ //#region packages/builder/src/discovery/discoverer.d.ts
705
+ type DiscoverModulesOptions = {
706
+ readonly entryPaths: readonly string[];
707
+ readonly astAnalyzer: ReturnType<typeof createAstAnalyzer>;
708
+ /** Set of file paths explicitly invalidated (from BuilderChangeSet) */
709
+ readonly incremental?: {
710
+ readonly cache: DiscoveryCache;
711
+ readonly changedFiles: Set<string>;
712
+ readonly removedFiles: Set<string>;
713
+ readonly affectedFiles: Set<string>;
714
+ };
715
+ };
716
+ type DiscoverModulesResult = {
717
+ readonly snapshots: readonly DiscoverySnapshot[];
718
+ readonly cacheHits: number;
719
+ readonly cacheMisses: number;
720
+ readonly cacheSkips: number;
721
+ };
722
+ /**
723
+ * Discover and analyze all modules starting from entry points.
724
+ * Uses AST parsing instead of RegExp for reliable dependency extraction.
725
+ * Supports caching with fingerprint-based invalidation to skip re-parsing unchanged files.
726
+ */
727
+ declare const discoverModules: ({
728
+ entryPaths,
729
+ astAnalyzer,
730
+ incremental
731
+ }: DiscoverModulesOptions) => BuilderResult<DiscoverModulesResult>;
732
+ //#endregion
733
+ //#region packages/builder/src/discovery/entry-paths.d.ts
734
+ /**
735
+ * Resolve entry file paths from glob patterns or direct paths.
736
+ * Used by the discovery system to find entry points for module traversal.
737
+ * All paths are normalized to POSIX format for consistent cache key matching.
738
+ * Uses Node.js normalize() + backslash replacement to match normalizePath from @soda-gql/common.
739
+ */
740
+ declare const resolveEntryPaths: (entries: readonly string[]) => neverthrow0.Err<readonly string[], BuilderError> | neverthrow0.Ok<readonly string[], BuilderError>;
741
+ //#endregion
742
+ //#region packages/builder/src/artifact/builder.d.ts
743
+ type BuildArtifactInput = {
744
+ readonly elements: IntermediateElements;
745
+ readonly analyses: ReadonlyMap<string, ModuleAnalysis>;
746
+ readonly stats: ModuleLoadStats;
747
+ };
748
+ declare const buildArtifact: ({
749
+ elements,
750
+ analyses,
751
+ stats: cache
752
+ }: BuildArtifactInput) => Result<BuilderArtifact, BuilderError>;
753
+ //#endregion
754
+ //#region packages/builder/src/session/builder-session.d.ts
755
+ /**
756
+ * Builder session interface for incremental builds.
757
+ */
758
+ interface BuilderSession {
759
+ /**
760
+ * Perform build fully or incrementally.
761
+ * The session automatically detects file changes using the file tracker.
762
+ */
763
+ build(options?: {
764
+ force?: boolean;
765
+ }): Result<BuilderArtifact, BuilderError>;
766
+ /**
767
+ * Get the current generation number.
768
+ */
769
+ getGeneration(): number;
770
+ /**
771
+ * Get the current artifact.
772
+ */
773
+ getCurrentArtifact(): BuilderArtifact | null;
774
+ }
775
+ /**
776
+ * Create a new builder session.
777
+ *
778
+ * The session maintains in-memory state across builds to enable incremental processing.
779
+ */
780
+ declare const createBuilderSession: (options: {
781
+ readonly evaluatorId?: string;
782
+ readonly entrypointsOverride?: readonly string[] | ReadonlySet<string>;
783
+ readonly config: ResolvedSodaGqlConfig;
784
+ }) => BuilderSession;
785
+ //#endregion
786
+ //#region packages/builder/src/session/dependency-validation.d.ts
787
+ type DependencyGraphError = {
788
+ readonly code: "MISSING_IMPORT";
789
+ readonly chain: readonly [importingFile: string, importSpecifier: string];
790
+ };
791
+ declare const validateModuleDependencies: ({
792
+ analyses
793
+ }: {
794
+ analyses: Map<string, ModuleAnalysis>;
795
+ }) => Result<null, DependencyGraphError>;
796
+ //#endregion
797
+ //#region packages/builder/src/session/module-adjacency.d.ts
798
+ /**
799
+ * Extract module-level adjacency from dependency graph.
800
+ * Returns Map of file path -> set of files that import it.
801
+ * All paths are normalized to POSIX format for consistent cache key matching.
802
+ */
803
+ declare const extractModuleAdjacency: ({
804
+ snapshots
805
+ }: {
806
+ snapshots: Map<string, DiscoverySnapshot>;
807
+ }) => Map<string, Set<string>>;
808
+ /**
809
+ * Collect all modules affected by changes, including transitive dependents.
810
+ * Uses BFS to traverse module adjacency graph.
811
+ * All paths are already normalized from extractModuleAdjacency.
812
+ */
813
+ declare const collectAffectedFiles: (input: {
814
+ changedFiles: Set<string>;
815
+ removedFiles: Set<string>;
816
+ previousModuleAdjacency: Map<string, Set<string>>;
817
+ }) => Set<string>;
818
+ //#endregion
819
+ export { type BuilderAnalyzer, type BuilderArtifact, type BuilderArtifactElement, type BuilderArtifactElementMetadata, type BuilderArtifactInlineOperation, type BuilderArtifactModel, type BuilderArtifactOperation, BuilderArtifactSchema, type BuilderArtifactSlice, type BuilderError, type BuilderFormat, type BuilderInput, type BuilderMode, type BuilderOptions, type BuilderService, type BuilderServiceConfig, type BuilderSession, type CanonicalId, type CanonicalPathTracker, type DiscoveredDependency, type DiscoveryCache, type DiscoverySnapshot, type ScopeFrame, type ScopeHandle, buildAstPath, createBuilderService, createBuilderSession, createCanonicalId, createCanonicalTracker, createOccurrenceTracker, createPathTracker };
820
+ //# sourceMappingURL=index.d.ts.map