@soda-gql/typegen 0.10.1 → 0.11.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/dist/index.d.mts CHANGED
@@ -4,6 +4,71 @@ import { DocumentNode } from "graphql";
4
4
  import { Result } from "neverthrow";
5
5
  import { ResolvedSodaGqlConfig } from "@soda-gql/config";
6
6
 
7
+ //#region packages/typegen/src/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" | "TYPEGEN_EMIT_FAILED" | "TYPEGEN_BUNDLE_FAILED" | "TYPEGEN_FRAGMENT_MISSING_KEY";
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
+ readonly code: "TYPEGEN_EMIT_FAILED";
31
+ readonly message: string;
32
+ readonly path: string;
33
+ readonly cause?: unknown;
34
+ } | {
35
+ readonly code: "TYPEGEN_BUNDLE_FAILED";
36
+ readonly message: string;
37
+ readonly path: string;
38
+ readonly cause?: unknown;
39
+ } | {
40
+ readonly code: "TYPEGEN_FRAGMENT_MISSING_KEY";
41
+ readonly message: string;
42
+ readonly fragments: readonly {
43
+ readonly canonicalId: string;
44
+ readonly typename: string;
45
+ readonly schemaLabel: string;
46
+ }[];
47
+ };
48
+ /**
49
+ * Union of all typegen errors (specific + builder errors).
50
+ */
51
+ type TypegenError = TypegenSpecificError | BuilderError;
52
+ /**
53
+ * Error constructor helpers for concise error creation.
54
+ */
55
+ declare const typegenErrors: {
56
+ readonly codegenRequired: (outdir: string) => TypegenSpecificError;
57
+ readonly schemaLoadFailed: (schemaNames: readonly string[], cause?: unknown) => TypegenSpecificError;
58
+ readonly buildFailed: (message: string, cause?: unknown) => TypegenSpecificError;
59
+ readonly emitFailed: (path: string, message: string, cause?: unknown) => TypegenSpecificError;
60
+ readonly bundleFailed: (path: string, message: string, cause?: unknown) => TypegenSpecificError;
61
+ readonly fragmentMissingKey: (fragments: readonly {
62
+ canonicalId: string;
63
+ typename: string;
64
+ schemaLabel: string;
65
+ }[]) => TypegenSpecificError;
66
+ };
67
+ /**
68
+ * Format TypegenError for console output (human-readable).
69
+ */
70
+ declare const formatTypegenError: (error: TypegenError) => string;
71
+ //#endregion
7
72
  //#region packages/typegen/src/emitter.d.ts
8
73
 
9
74
  /**
@@ -25,12 +90,10 @@ type PrebuiltTypesEmitterOptions = {
25
90
  */
26
91
  readonly outdir: string;
27
92
  /**
28
- * Inject configuration per schema.
29
- * Maps schema name to inject file paths (absolute paths).
93
+ * Relative import path to _internal-injects.ts from types.prebuilt.ts.
94
+ * Example: "./_internal-injects"
30
95
  */
31
- readonly injects: Record<string, {
32
- readonly scalars: string;
33
- }>;
96
+ readonly injectsModulePath: string;
34
97
  };
35
98
  /**
36
99
  * Result of emitting prebuilt types.
@@ -68,85 +131,38 @@ type PrebuiltTypesEmitResult = {
68
131
  * }
69
132
  * ```
70
133
  */
71
- declare const emitPrebuiltTypes: (options: PrebuiltTypesEmitterOptions) => Promise<Result<PrebuiltTypesEmitResult, BuilderError>>;
72
- //#endregion
73
- //#region packages/typegen/src/errors.d.ts
74
- /**
75
- * Error codes specific to typegen operations.
76
- */
77
- type TypegenErrorCode = "TYPEGEN_CODEGEN_REQUIRED" | "TYPEGEN_SCHEMA_LOAD_FAILED" | "TYPEGEN_BUILD_FAILED" | "TYPEGEN_EMIT_FAILED" | "TYPEGEN_BUNDLE_FAILED";
78
- /**
79
- * Typegen-specific error type.
80
- */
81
- type TypegenSpecificError = {
82
- readonly code: "TYPEGEN_CODEGEN_REQUIRED";
83
- readonly message: string;
84
- readonly outdir: string;
85
- } | {
86
- readonly code: "TYPEGEN_SCHEMA_LOAD_FAILED";
87
- readonly message: string;
88
- readonly schemaNames: readonly string[];
89
- readonly cause?: unknown;
90
- } | {
91
- readonly code: "TYPEGEN_BUILD_FAILED";
92
- readonly message: string;
93
- readonly cause?: unknown;
94
- } | {
95
- readonly code: "TYPEGEN_EMIT_FAILED";
96
- readonly message: string;
97
- readonly path: string;
98
- readonly cause?: unknown;
99
- } | {
100
- readonly code: "TYPEGEN_BUNDLE_FAILED";
101
- readonly message: string;
102
- readonly path: string;
103
- readonly cause?: unknown;
104
- };
105
- /**
106
- * Union of all typegen errors (specific + builder errors).
107
- */
108
- type TypegenError = TypegenSpecificError | BuilderError;
109
- /**
110
- * Error constructor helpers for concise error creation.
111
- */
112
- declare const typegenErrors: {
113
- readonly codegenRequired: (outdir: string) => TypegenSpecificError;
114
- readonly schemaLoadFailed: (schemaNames: readonly string[], cause?: unknown) => TypegenSpecificError;
115
- readonly buildFailed: (message: string, cause?: unknown) => TypegenSpecificError;
116
- readonly emitFailed: (path: string, message: string, cause?: unknown) => TypegenSpecificError;
117
- readonly bundleFailed: (path: string, message: string, cause?: unknown) => TypegenSpecificError;
118
- };
119
- /**
120
- * Format TypegenError for console output (human-readable).
121
- */
122
- declare const formatTypegenError: (error: TypegenError) => string;
134
+ declare const emitPrebuiltTypes: (options: PrebuiltTypesEmitterOptions) => Promise<Result<PrebuiltTypesEmitResult, BuilderError | TypegenError>>;
123
135
  //#endregion
124
136
  //#region packages/typegen/src/prebuilt-generator.d.ts
125
137
  type PrebuiltGeneratorOptions = {
126
138
  /**
127
- * Relative import path to the main gql module.
128
- * Example: "../index" (from prebuilt/index.ts to index.ts)
139
+ * Relative import path to the internal module.
140
+ * Example: "./_internal" (from index.prebuilt.ts to _internal.ts)
141
+ */
142
+ readonly internalModulePath: string;
143
+ /**
144
+ * Relative import path to the injects module.
145
+ * Example: "./_internal-injects" (from index.prebuilt.ts to _internal-injects.ts)
129
146
  */
130
- readonly mainModulePath: string;
147
+ readonly injectsModulePath: string;
131
148
  /**
132
- * Per-schema injection config (adapter import paths).
149
+ * Per-schema injection config.
150
+ * Maps schema name to whether it has an adapter.
133
151
  */
134
152
  readonly injection?: Map<string, {
135
- readonly adapterImportPath?: string;
153
+ readonly hasAdapter?: boolean;
136
154
  }>;
137
155
  };
138
156
  type PrebuiltGeneratedModule = {
139
- /** The generated code for prebuilt/index.ts */
157
+ /** The generated code for index.prebuilt.ts */
140
158
  readonly indexCode: string;
141
- /** The generated code for prebuilt/types.ts (placeholder) */
142
- readonly typesCode: string;
143
159
  };
144
160
  /**
145
- * Generate the prebuilt module code.
161
+ * Generate the prebuilt index module code.
146
162
  *
147
- * This generates:
148
- * - prebuilt/index.ts: Uses createPrebuiltGqlElementComposer with types from PrebuiltTypes
149
- * - prebuilt/types.ts: Placeholder types that typegen will populate
163
+ * Generates index.prebuilt.ts with builder-level type resolution.
164
+ * Types are resolved at the fragment/operation builder level using TKey/TName,
165
+ * eliminating the need for ResolvePrebuiltElement at the composer level.
150
166
  */
151
167
  declare const generatePrebuiltModule: (schemas: Map<string, DocumentNode>, options: PrebuiltGeneratorOptions) => PrebuiltGeneratedModule;
152
168
  //#endregion
@@ -221,10 +237,10 @@ type RunTypegenOptions = {
221
237
  *
222
238
  * This function:
223
239
  * 1. Loads schemas from the generated CJS bundle
224
- * 2. Generates prebuilt/index.ts using generatePrebuiltModule
240
+ * 2. Generates index.prebuilt.ts using generatePrebuiltModule
225
241
  * 3. Creates a BuilderService and builds the artifact
226
242
  * 4. Extracts field selections from the artifact
227
- * 5. Emits prebuilt/types.ts using emitPrebuiltTypes
243
+ * 5. Emits types.prebuilt.ts using emitPrebuiltTypes
228
244
  * 6. Bundles the prebuilt module
229
245
  *
230
246
  * @param options - Typegen options including config
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/emitter.ts","../src/errors.ts","../src/prebuilt-generator.ts","../src/types.ts","../src/runner.ts"],"sourcesContent":[],"mappings":";;;;;;;;AC2DA;;;AAcmD,KDrCvC,2BAAA,GCqCuC;EAMa;;;AAkBhE;oBDxDoB,eAAe;;;AE9BnC;EAiBY,SAAA,eAAA,EFiBgB,kBEjBO;EActB;;;;EAGV,SAAA,MAAA,EAAA,MAAA;EA6FF;;;;EC9HW,SAAA,OAAA,EH2CQ,MG3CM,CAAA,MAgBN,EAAA;IAWR,SAAA,OAAc,EAAA,MAAA;EA8Bd,CAAA,CAAA;CAAuB;;;;KHoUvB,uBAAA;;;AIrWZ,CAAA;AA4HA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cJ2Qa,6BACF,gCACR,QAAQ,OAAO,yBAAyB;;;;AAzY3C;;AAKoB,KC9BR,gBAAA,GD8BQ,0BAAA,GAAA,4BAAA,GAAA,sBAAA,GAAA,qBAAA,GAAA,uBAAA;;;;AAgWR,KCpXA,oBAAA,GDoXuB;EAkCtB,SAAA,IAAA,EAAA,0BA8BZ;EA7BU,SAAA,OAAA,EAAA,MAAA;EACO,SAAA,MAAA,EAAA,MAAA;CAAyB,GAAA;EAAhC,SAAA,IAAA,EAAA,4BAAA;EAAR,SAAA,OAAA,EAAA,MAAA;EAAO,SAAA,WAAA,EAAA,SAAA,MAAA,EAAA;;;;EClaE,SAAA,OAAA,EAAA,MAAgB;EAUhB,SAAA,KAAA,CAAA,EAAA,OAAoB;AAiChC,CAAA,GAAY;EAKC,SAAA,IAAA,EAAA,qBAiCH;EAhC2B,SAAA,OAAA,EAAA,MAAA;EAMkC,SAAA,IAAA,EAAA,MAAA;EAOpB,SAAA,KAAA,CAAA,EAAA,OAAA;CAMa,GAAA;EAOE,SAAA,IAAA,EAAA,uBAAA;EAAoB,SAAA,OAAA,EAAA,MAAA;EAWzE,SAAA,IAAA,EAAA,MAwBZ;;;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