@soda-gql/builder 0.0.9 → 0.1.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.
package/README.md ADDED
@@ -0,0 +1,125 @@
1
+ # @soda-gql/builder
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@soda-gql/builder.svg)](https://www.npmjs.com/package/@soda-gql/builder)
4
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
+
6
+ Static analysis and artifact generation engine for soda-gql.
7
+
8
+ ## Installation
9
+
10
+ ```bash
11
+ bun add -D @soda-gql/builder
12
+ ```
13
+
14
+ > **Note**: This package is typically used indirectly via build plugins or the CLI. Direct usage is only needed for advanced integration scenarios.
15
+
16
+ ## Overview
17
+
18
+ This package provides the core static analysis engine that powers soda-gql's build-time transformations:
19
+
20
+ - Source code analysis for `gql.default()` calls
21
+ - Canonical ID generation for operation tracking
22
+ - Artifact generation for runtime transformations
23
+ - Support for TypeScript and SWC analyzers
24
+
25
+ ## Features
26
+
27
+ - **Static Analysis**: Analyzes TypeScript source files to discover GraphQL operations
28
+ - **Canonical ID Tracking**: Generates unique identifiers for each operation based on file path and AST location
29
+ - **Artifact Generation**: Creates build artifacts used by transformation plugins
30
+ - **Multi-Analyzer Support**: Works with both TypeScript and SWC parsers
31
+
32
+ ## Programmatic Usage
33
+
34
+ For custom build tool integrations:
35
+
36
+ ```typescript
37
+ import { createBuilder } from "@soda-gql/builder";
38
+
39
+ const builder = await createBuilder({
40
+ config: {
41
+ outdir: "./graphql-system",
42
+ include: ["./src/**/*.ts"],
43
+ analyzer: "ts",
44
+ schemas: {
45
+ default: {
46
+ schema: "./schema.graphql",
47
+ runtimeAdapter: "./runtime-adapter.ts",
48
+ scalars: "./scalars.ts",
49
+ },
50
+ },
51
+ },
52
+ });
53
+
54
+ // Analyze source files
55
+ const analysisResult = await builder.analyze();
56
+
57
+ if (analysisResult.isOk()) {
58
+ const artifact = analysisResult.value;
59
+ // Use artifact for transformations
60
+ }
61
+ ```
62
+
63
+ ## API Reference
64
+
65
+ ### `createBuilder(options)`
66
+
67
+ Creates a builder instance for static analysis:
68
+
69
+ ```typescript
70
+ const builder = await createBuilder({
71
+ config: SodaGqlConfig,
72
+ cwd?: string,
73
+ });
74
+ ```
75
+
76
+ ### Builder Methods
77
+
78
+ - `build(options?)` - Synchronously analyze source files and generate artifacts
79
+ - `buildAsync(options?)` - Asynchronously analyze source files (supports parallel I/O)
80
+ - `getGeneration()` - Get the current build generation number
81
+ - `getCurrentArtifact()` - Retrieve the current build artifact
82
+
83
+ ### Async Build API
84
+
85
+ For better performance in large codebases, use the async build API:
86
+
87
+ ```typescript
88
+ import { createBuilder } from "@soda-gql/builder";
89
+
90
+ const builder = await createBuilder({ config });
91
+
92
+ // Async build with parallel file I/O
93
+ const result = await builder.buildAsync();
94
+
95
+ if (result.isOk()) {
96
+ const artifact = result.value;
97
+ // Use artifact for transformations
98
+ }
99
+
100
+ // Incremental rebuild (only processes changed files)
101
+ const incrementalResult = await builder.buildAsync();
102
+ ```
103
+
104
+ The async API is recommended for:
105
+ - Large codebases with many source files
106
+ - Build tools that benefit from parallel I/O
107
+ - Environments where non-blocking operations are preferred
108
+
109
+ ## Analyzer Options
110
+
111
+ | Analyzer | Description | Use Case |
112
+ |----------|-------------|----------|
113
+ | `"ts"` | TypeScript compiler API | Best type accuracy, slower |
114
+ | `"swc"` | SWC parser | Faster parsing, good for large codebases |
115
+
116
+ ## Related Packages
117
+
118
+ - [@soda-gql/cli](../cli) - Command-line interface
119
+ - [@soda-gql/babel-plugin](../babel-plugin) - Babel transformation plugin
120
+ - [@soda-gql/tsc-plugin](../tsc-plugin) - TypeScript transformation plugin
121
+ - [@soda-gql/plugin-common](../plugin-common) - Shared plugin utilities
122
+
123
+ ## License
124
+
125
+ MIT