@soda-gql/tsc 0.11.9 → 0.11.11
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.cjs +1 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/plugin.cjs +1 -1
- package/dist/plugin.mjs +1 -1
- package/dist/{transformer-BE1nwZtg.cjs → transformer-BK2-HeJT.cjs} +12 -8
- package/dist/transformer-BK2-HeJT.cjs.map +1 -0
- package/dist/{transformer-Dk0Nnpg_.mjs → transformer-CQGLchIQ.mjs} +12 -8
- package/dist/transformer-CQGLchIQ.mjs.map +1 -0
- package/package.json +6 -6
- package/dist/transformer-BE1nwZtg.cjs.map +0 -1
- package/dist/transformer-Dk0Nnpg_.mjs.map +0 -1
package/dist/index.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_transformer = require('./transformer-
|
|
1
|
+
const require_transformer = require('./transformer-BK2-HeJT.cjs');
|
|
2
2
|
|
|
3
3
|
exports.createAfterStubTransformer = require_transformer.createAfterStubTransformer;
|
|
4
4
|
exports.createTransformer = require_transformer.createTransformer;
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/ast/imports.ts","../src/transformer.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;cAoMa;;;;cAIC,EAAA,CAAG;+BACc;MAC3B,EAAA,CAAG,mBAAmB,EAAA,CAAG;;;;;;AADE,KCtLnB,aAAA,GDsLmB;EACF,SAAA,UAAA,ECtLN,IAAA,CAAG,UDsLG;EAAtB,SAAA,OAAA,ECrLa,IAAA,CAAG,qBDqLhB;CAAkB;cCpKZ;;;;AAAb;4BAK4B,IAAA,CAAG;mBACZ;EAzBP,SAAA,QAAa,EA0BJ,eAzBK;AAkB1B,CAAA,EAAA,GAAa;EAAqB,SAAA,EAAA,CAAA;IAAA,UAAA;IAAA;EAKN,CALM,EAAA;IAAA,UAAA,
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/ast/imports.ts","../src/transformer.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;cAoMa;;;;cAIC,EAAA,CAAG;+BACc;MAC3B,EAAA,CAAG,mBAAmB,EAAA,CAAG;;;;;;AADE,KCtLnB,aAAA,GDsLmB;EACF,SAAA,UAAA,ECtLN,IAAA,CAAG,UDsLG;EAAtB,SAAA,OAAA,ECrLa,IAAA,CAAG,qBDqLhB;CAAkB;cCpKZ;;;;AAAb;4BAK4B,IAAA,CAAG;mBACZ;EAzBP,SAAA,QAAa,EA0BJ,eAzBK;AAkB1B,CAAA,EAAA,GAAa;EAAqB,SAAA,EAAA,CAAA;IAAA,UAAA;IAAA;EAKN,CALM,EAAA;IAAA,UAAA,EAuFqB,IAAA,CAAG,UAvFxB;IAAA,OAAA,EAuF6C,IAAA,CAAG,qBAvFhD;EAKN,CAAA,EAAG,GAAA;IACZ,WAAA,EAAA,OAAA;IACE,UAAA,iBAAA"}
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/ast/imports.ts","../src/transformer.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;cAoMa;;;;cAIC,EAAA,CAAG;+BACc;MAC3B,EAAA,CAAG,mBAAmB,EAAA,CAAG;;;;;;AADE,KCtLnB,aAAA,GDsLmB;EACF,SAAA,UAAA,ECtLN,IAAA,CAAG,UDsLG;EAAtB,SAAA,OAAA,ECrLa,IAAA,CAAG,qBDqLhB;CAAkB;cCpKZ;;;;AAAb;4BAK4B,IAAA,CAAG;mBACZ;EAzBP,SAAA,QAAa,EA0BJ,eAzBK;AAkB1B,CAAA,EAAA,GAAa;EAAqB,SAAA,EAAA,CAAA;IAAA,UAAA;IAAA;EAKN,CALM,EAAA;IAAA,UAAA,
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/ast/imports.ts","../src/transformer.ts"],"sourcesContent":[],"mappings":";;;;;;;;;;;;;;cAoMa;;;;cAIC,EAAA,CAAG;+BACc;MAC3B,EAAA,CAAG,mBAAmB,EAAA,CAAG;;;;;;AADE,KCtLnB,aAAA,GDsLmB;EACF,SAAA,UAAA,ECtLN,IAAA,CAAG,UDsLG;EAAtB,SAAA,OAAA,ECrLa,IAAA,CAAG,qBDqLhB;CAAkB;cCpKZ;;;;AAAb;4BAK4B,IAAA,CAAG;mBACZ;EAzBP,SAAA,QAAa,EA0BJ,eAzBK;AAkB1B,CAAA,EAAA,GAAa;EAAqB,SAAA,EAAA,CAAA;IAAA,UAAA;IAAA;EAKN,CALM,EAAA;IAAA,UAAA,EAuFqB,IAAA,CAAG,UAvFxB;IAAA,OAAA,EAuF6C,IAAA,CAAG,qBAvFhD;EAKN,CAAA,EAAG,GAAA;IACZ,WAAA,EAAA,OAAA;IACE,UAAA,iBAAA"}
|
package/dist/index.mjs
CHANGED
package/dist/plugin.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_transformer = require('./transformer-
|
|
1
|
+
const require_transformer = require('./transformer-BK2-HeJT.cjs');
|
|
2
2
|
let __soda_gql_builder = require("@soda-gql/builder");
|
|
3
3
|
let __soda_gql_common = require("@soda-gql/common");
|
|
4
4
|
let __soda_gql_config = require("@soda-gql/config");
|
package/dist/plugin.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as createTransformer } from "./transformer-
|
|
1
|
+
import { t as createTransformer } from "./transformer-CQGLchIQ.mjs";
|
|
2
2
|
import { createBuilderService } from "@soda-gql/builder";
|
|
3
3
|
import { cachedFn } from "@soda-gql/common";
|
|
4
4
|
import { loadConfig } from "@soda-gql/config";
|
|
@@ -161,10 +161,11 @@ const extractRequireTargetSpecifier = (expr) => {
|
|
|
161
161
|
|
|
162
162
|
//#endregion
|
|
163
163
|
//#region packages/tsc/src/ast/metadata.ts
|
|
164
|
-
const collectGqlDefinitionMetadata = ({ sourceFile, filename, createTracker }) => {
|
|
164
|
+
const collectGqlDefinitionMetadata = ({ sourceFile, filename, createTracker, baseDir }) => {
|
|
165
165
|
const exportBindings = collectExportBindings(sourceFile);
|
|
166
166
|
const tracker = (createTracker ?? __soda_gql_common.createCanonicalTracker)({
|
|
167
167
|
filePath: filename,
|
|
168
|
+
baseDir,
|
|
168
169
|
getExportName: (localName) => exportBindings.get(localName)
|
|
169
170
|
});
|
|
170
171
|
const getAnonymousName = createAnonymousNameFactory();
|
|
@@ -345,10 +346,10 @@ const maybeEnterScope = (node, tracker, getAnonymousName, typescript$1) => {
|
|
|
345
346
|
|
|
346
347
|
//#endregion
|
|
347
348
|
//#region packages/tsc/src/ast/analysis.ts
|
|
348
|
-
const extractGqlCall = ({ callNode, filename, metadata, getArtifact }) => {
|
|
349
|
+
const extractGqlCall = ({ callNode, filename, metadata, getArtifact, baseDir }) => {
|
|
349
350
|
const meta = metadata.get(callNode);
|
|
350
351
|
if (!meta) return (0, neverthrow.err)(createMetadataMissingError({ filename }));
|
|
351
|
-
const canonicalId = (0, __soda_gql_builder_plugin_support.resolveCanonicalId)(filename, meta.astPath);
|
|
352
|
+
const canonicalId = (0, __soda_gql_builder_plugin_support.resolveCanonicalId)(filename, meta.astPath, { baseDir });
|
|
352
353
|
const artifact = getArtifact(canonicalId);
|
|
353
354
|
if (!artifact) return (0, neverthrow.err)(createArtifactMissingError({
|
|
354
355
|
filename,
|
|
@@ -452,13 +453,14 @@ const buildOperationRuntimeComponents = ({ gqlCall, factory, isCJS }) => {
|
|
|
452
453
|
|
|
453
454
|
//#endregion
|
|
454
455
|
//#region packages/tsc/src/ast/transformer.ts
|
|
455
|
-
const transformCallExpression = ({ callNode, filename, metadata, getArtifact, factory, isCJS }) => {
|
|
456
|
+
const transformCallExpression = ({ callNode, filename, metadata, getArtifact, factory, isCJS, baseDir }) => {
|
|
456
457
|
if (!metadata.has(callNode)) return (0, neverthrow.ok)({ transformed: false });
|
|
457
458
|
const gqlCallResult = extractGqlCall({
|
|
458
459
|
callNode,
|
|
459
460
|
filename,
|
|
460
461
|
metadata,
|
|
461
|
-
getArtifact
|
|
462
|
+
getArtifact,
|
|
463
|
+
baseDir
|
|
462
464
|
});
|
|
463
465
|
if (gqlCallResult.isErr()) return (0, neverthrow.err)(gqlCallResult.error);
|
|
464
466
|
const gqlCall = gqlCallResult.value;
|
|
@@ -521,7 +523,8 @@ const createTransformer = ({ compilerOptions, config, artifact }) => {
|
|
|
521
523
|
let transformed = false;
|
|
522
524
|
const metadata = collectGqlDefinitionMetadata({
|
|
523
525
|
sourceFile,
|
|
524
|
-
filename: sourceFile.fileName
|
|
526
|
+
filename: sourceFile.fileName,
|
|
527
|
+
baseDir: config.baseDir
|
|
525
528
|
});
|
|
526
529
|
const runtimeCallsFromLastTransform = [];
|
|
527
530
|
const visitor = (node) => {
|
|
@@ -532,7 +535,8 @@ const createTransformer = ({ compilerOptions, config, artifact }) => {
|
|
|
532
535
|
metadata,
|
|
533
536
|
getArtifact: (canonicalId) => artifact.elements[canonicalId],
|
|
534
537
|
factory: context.factory,
|
|
535
|
-
isCJS
|
|
538
|
+
isCJS,
|
|
539
|
+
baseDir: config.baseDir
|
|
536
540
|
});
|
|
537
541
|
if (result.isErr()) {
|
|
538
542
|
console.error(`[@soda-gql/tsc] ${(0, __soda_gql_builder_plugin_support.formatPluginError)(result.error)}`);
|
|
@@ -613,4 +617,4 @@ Object.defineProperty(exports, 'createTransformer', {
|
|
|
613
617
|
return createTransformer;
|
|
614
618
|
}
|
|
615
619
|
});
|
|
616
|
-
//# sourceMappingURL=transformer-
|
|
620
|
+
//# sourceMappingURL=transformer-BK2-HeJT.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformer-BK2-HeJT.cjs","names":["ts","newStatements","sourceFile","createCanonicalTracker","ts","bindings: ExportBindingMap","typescript","prebuildProps: Record<string, ts.Expression>","ts","runtimeCallsFromLastTransform: ts.Expression[]"],"sources":["../src/ast/imports.ts","../src/ast/metadata.ts","../src/ast/analysis.ts","../src/ast/ast.ts","../src/ast/runtime.ts","../src/ast/transformer.ts","../src/transformer.ts"],"sourcesContent":["import type { GraphqlSystemIdentifyHelper } from \"@soda-gql/builder\";\nimport ts from \"typescript\";\n\nconst RUNTIME_MODULE = \"@soda-gql/runtime\";\n\n/**\n * Ensure that the gqlRuntime require exists in the source file for CJS output.\n * Injects: const __soda_gql_runtime = require(\"@soda-gql/runtime\");\n * Returns an updated source file with the require added if needed.\n */\nexport const ensureGqlRuntimeRequire = ({\n sourceFile,\n factory,\n}: {\n sourceFile: ts.SourceFile;\n factory: ts.NodeFactory;\n}): ts.SourceFile => {\n // Check if the require already exists\n const existing = sourceFile.statements.find(\n (statement): statement is ts.VariableStatement =>\n ts.isVariableStatement(statement) &&\n statement.declarationList.declarations.some((decl) => {\n if (!ts.isIdentifier(decl.name) || decl.name.text !== \"__soda_gql_runtime\") {\n return false;\n }\n if (!decl.initializer || !ts.isCallExpression(decl.initializer)) {\n return false;\n }\n const callExpr = decl.initializer;\n if (!ts.isIdentifier(callExpr.expression) || callExpr.expression.text !== \"require\") {\n return false;\n }\n const arg = callExpr.arguments[0];\n return arg && ts.isStringLiteral(arg) && arg.text === RUNTIME_MODULE;\n }),\n );\n\n if (existing) {\n return sourceFile;\n }\n\n // Create: const __soda_gql_runtime = require(\"@soda-gql/runtime\");\n const requireCall = factory.createCallExpression(factory.createIdentifier(\"require\"), undefined, [\n factory.createStringLiteral(RUNTIME_MODULE),\n ]);\n\n const variableDeclaration = factory.createVariableDeclaration(\n factory.createIdentifier(\"__soda_gql_runtime\"),\n undefined,\n undefined,\n requireCall,\n );\n\n const variableStatement = factory.createVariableStatement(\n undefined,\n factory.createVariableDeclarationList([variableDeclaration], ts.NodeFlags.Const),\n );\n\n // Insert at the beginning of the file\n const newStatements = [variableStatement, ...sourceFile.statements];\n return factory.updateSourceFile(sourceFile, newStatements);\n};\n\n/**\n * Ensure that the gqlRuntime import exists in the source file.\n * gqlRuntime is always imported from @soda-gql/runtime.\n * Returns an updated source file with the import added or merged.\n */\nexport const ensureGqlRuntimeImport = ({\n sourceFile,\n factory,\n}: {\n sourceFile: ts.SourceFile;\n factory: ts.NodeFactory;\n}): ts.SourceFile => {\n const existing = sourceFile.statements.find(\n (statement): statement is ts.ImportDeclaration =>\n ts.isImportDeclaration(statement) &&\n ts.isStringLiteral(statement.moduleSpecifier) &&\n statement.moduleSpecifier.text === RUNTIME_MODULE,\n );\n\n if (existing?.importClause?.namedBindings && ts.isNamedImports(existing.importClause.namedBindings)) {\n const hasSpecifier = existing.importClause.namedBindings.elements.some(\n (element) => ts.isIdentifier(element.name) && element.name.text === \"gqlRuntime\",\n );\n\n if (hasSpecifier) {\n return sourceFile;\n }\n\n // Add gqlRuntime to existing import\n const newElements = [\n ...existing.importClause.namedBindings.elements,\n factory.createImportSpecifier(false, undefined, factory.createIdentifier(\"gqlRuntime\")),\n ];\n\n const newNamedBindings = factory.createNamedImports(newElements);\n const newImportClause = factory.createImportClause(false, undefined, newNamedBindings);\n const newImportDeclaration = factory.createImportDeclaration(\n undefined,\n newImportClause,\n factory.createStringLiteral(RUNTIME_MODULE),\n undefined,\n );\n\n const newStatements = sourceFile.statements.map((stmt) => (stmt === existing ? newImportDeclaration : stmt));\n return factory.updateSourceFile(sourceFile, newStatements);\n }\n\n // Create new import declaration\n const newImportDeclaration = factory.createImportDeclaration(\n undefined,\n factory.createImportClause(\n false,\n undefined,\n factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier(\"gqlRuntime\"))]),\n ),\n factory.createStringLiteral(RUNTIME_MODULE),\n undefined,\n );\n\n const newStatements = [newImportDeclaration, ...sourceFile.statements];\n return factory.updateSourceFile(sourceFile, newStatements);\n};\n\n/**\n * Remove the graphql-system import (runtimeModule) and gql-related exports from the source file.\n * After transformation, gqlRuntime is imported from @soda-gql/runtime instead,\n * so the original graphql-system import should be completely removed.\n *\n * This handles both ESM imports and CommonJS require() statements (including interop helpers).\n */\nexport const removeGraphqlSystemImports = ({\n sourceFile,\n factory,\n graphqlSystemIdentifyHelper,\n}: {\n sourceFile: ts.SourceFile;\n factory: ts.NodeFactory;\n graphqlSystemIdentifyHelper: GraphqlSystemIdentifyHelper;\n}): ts.SourceFile => {\n // After transformation, all gql usage should be replaced with gqlRuntime\n // So we can safely remove the graphql-system import and all gql-related exports\n const updatedStatements = Array.from(sourceFile.statements).filter((statement) => {\n // Remove ESM import declarations for the runtimeModule\n // - import { gql } from \"@/graphql-system\";\n // - import * as gql from \"@/graphql-system\";\n // - import gql from \"@/graphql-system\";\n // - import { gql as gqlRuntime } from \"@/graphql-system\";\n // - import * as gqlRuntime from \"@/graphql-system\";\n // - import gqlRuntime from \"@/graphql-system\";\n if (ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier)) {\n return !graphqlSystemIdentifyHelper.isGraphqlSystemImportSpecifier({\n filePath: sourceFile.fileName,\n specifier: statement.moduleSpecifier.text,\n });\n }\n\n // Remove CommonJS require() statements for the runtimeModule\n // TypeScript emits these when downleveling ESM to CJS:\n // - const graphql_system_1 = require(\"../../graphql-system\");\n // - const { gql } = require(\"@/graphql-system\");\n // - const foo = __importDefault(require(\"@/graphql-system\"));\n // - const foo = __importStar(require(\"@/graphql-system\"));\n if (ts.isVariableStatement(statement)) {\n return !statement.declarationList.declarations.every((decl) => {\n const specifier = extractRequireTargetSpecifier(decl.initializer);\n if (!specifier) {\n return false;\n }\n\n return graphqlSystemIdentifyHelper.isGraphqlSystemImportSpecifier({\n filePath: sourceFile.fileName,\n specifier: specifier,\n });\n });\n }\n\n return true;\n });\n\n if (updatedStatements.length === sourceFile.statements.length) {\n return sourceFile;\n }\n\n return factory.updateSourceFile(sourceFile, updatedStatements);\n};\n\n/**\n * Create an \"after\" transformer that stubs out require() calls for the runtimeModule.\n * This runs after TypeScript's own transformers (including CommonJS down-leveling),\n * so we can replace `const X = require(\"@/graphql-system\")` with a lightweight stub.\n *\n * This prevents the heavy graphql-system module from being loaded at runtime.\n */\nexport const createAfterStubTransformer = ({\n sourceFile,\n graphqlSystemIdentifyHelper,\n}: {\n sourceFile: ts.SourceFile;\n graphqlSystemIdentifyHelper: GraphqlSystemIdentifyHelper;\n}): ts.TransformerFactory<ts.SourceFile> => {\n return (context) => {\n const factory = context.factory;\n\n const visitor = (node: ts.Node): ts.Node => {\n // Replace variable statements that require the runtimeModule with a stub\n if (ts.isVariableStatement(node)) {\n let transformed = false;\n\n const newDeclarations = node.declarationList.declarations.map((decl) => {\n const specifier = extractRequireTargetSpecifier(decl.initializer);\n if (!specifier) {\n return decl;\n }\n\n const isGraphqlSystemImport = graphqlSystemIdentifyHelper.isGraphqlSystemImportSpecifier({\n filePath: sourceFile.fileName,\n specifier,\n });\n if (!isGraphqlSystemImport) {\n return decl;\n }\n\n // Create stub: const X = /*#__PURE__*/Object.create(null);\n const stub = factory.createCallExpression(\n factory.createPropertyAccessExpression(factory.createIdentifier(\"Object\"), \"create\"),\n undefined,\n [factory.createNull()],\n );\n\n // Add /*#__PURE__*/ comment for tree-shaking\n ts.addSyntheticLeadingComment(stub, ts.SyntaxKind.MultiLineCommentTrivia, \"#__PURE__\", false);\n\n transformed = true;\n\n return factory.updateVariableDeclaration(decl, decl.name, decl.exclamationToken, decl.type, stub);\n });\n\n if (transformed) {\n return factory.updateVariableStatement(\n node,\n node.modifiers,\n factory.updateVariableDeclarationList(node.declarationList, newDeclarations),\n );\n }\n }\n\n return ts.visitEachChild(node, visitor, context);\n };\n\n return (sourceFile) => ts.visitNode(sourceFile, visitor) as ts.SourceFile;\n };\n};\n\n/**\n * Check if an expression is a require() call for the runtimeModule.\n * Handles multiple patterns:\n * - require(\"@/graphql-system\")\n * - __importDefault(require(\"@/graphql-system\"))\n * - __importStar(require(\"@/graphql-system\"))\n */\nconst extractRequireTargetSpecifier = (expr: ts.Expression | undefined): string | undefined => {\n if (!expr) {\n return undefined;\n }\n\n // Direct require(\"@/graphql-system\")\n if (ts.isCallExpression(expr)) {\n if (ts.isIdentifier(expr.expression) && expr.expression.text === \"require\") {\n const arg = expr.arguments[0];\n if (arg && ts.isStringLiteral(arg)) {\n return arg.text;\n }\n }\n\n // __importDefault(require(\"@/graphql-system\")) or __importStar(require(\"@/graphql-system\"))\n if (ts.isIdentifier(expr.expression)) {\n const helperName = expr.expression.text;\n if (helperName === \"__importDefault\" || helperName === \"__importStar\") {\n const arg = expr.arguments[0];\n if (arg && ts.isCallExpression(arg)) {\n if (ts.isIdentifier(arg.expression) && arg.expression.text === \"require\") {\n const requireArg = arg.arguments[0];\n if (requireArg && ts.isStringLiteral(requireArg)) {\n return requireArg.text;\n }\n }\n }\n }\n }\n }\n\n return undefined;\n};\n","import type { GqlDefinitionMetadata } from \"@soda-gql/builder/plugin-support\";\nimport type { CanonicalPathTracker } from \"@soda-gql/common\";\nimport { createCanonicalTracker } from \"@soda-gql/common\";\nimport * as ts from \"typescript\";\n\nexport type GqlDefinitionMetadataMap = WeakMap<ts.CallExpression, GqlDefinitionMetadata>;\n\ntype CanonicalTrackerFactory = typeof createCanonicalTracker;\n\ntype CollectArgs = {\n readonly sourceFile: ts.SourceFile;\n readonly filename: string;\n readonly createTracker?: CanonicalTrackerFactory;\n /**\n * Base directory for relative path computation.\n * When provided, canonical IDs use paths relative to this directory.\n */\n readonly baseDir?: string;\n};\n\ntype ScopeHandle = ReturnType<CanonicalPathTracker[\"enterScope\"]>;\ntype ExportBindingMap = Map<string, string>;\n\nexport const collectGqlDefinitionMetadata = ({\n sourceFile,\n filename,\n createTracker,\n baseDir,\n}: CollectArgs): GqlDefinitionMetadataMap => {\n const exportBindings = collectExportBindings(sourceFile);\n const trackerFactory = createTracker ?? createCanonicalTracker;\n const tracker = trackerFactory({\n filePath: filename,\n baseDir,\n getExportName: (localName) => exportBindings.get(localName),\n });\n\n const getAnonymousName = createAnonymousNameFactory();\n const scopeHandles = new WeakMap<ts.Node, ScopeHandle>();\n const metadata = new WeakMap<ts.CallExpression, GqlDefinitionMetadata>();\n\n const visit = (node: ts.Node): void => {\n // Handle GraphQL definition calls\n if (ts.isCallExpression(node) && isGqlDefinitionCall(node, ts)) {\n const depthBeforeRegister = tracker.currentDepth();\n const { astPath } = tracker.registerDefinition();\n const isTopLevel = depthBeforeRegister <= 1;\n const exportInfo = isTopLevel ? resolveTopLevelExport(node, exportBindings, ts) : null;\n\n metadata.set(node, {\n astPath,\n isTopLevel,\n isExported: exportInfo?.isExported ?? false,\n exportBinding: exportInfo?.exportBinding,\n });\n\n // Skip visiting children of gql calls\n return;\n }\n\n // Enter scope if this node creates one\n const handle = maybeEnterScope(node, tracker, getAnonymousName, ts);\n if (handle) {\n scopeHandles.set(node, handle);\n }\n\n // Visit children\n ts.forEachChild(node, visit);\n\n // Exit scope if we entered one\n const scopeHandle = scopeHandles.get(node);\n if (scopeHandle) {\n tracker.exitScope(scopeHandle);\n scopeHandles.delete(node);\n }\n };\n\n visit(sourceFile);\n\n return metadata;\n};\n\nconst collectExportBindings = (sourceFile: ts.SourceFile): ExportBindingMap => {\n const bindings: ExportBindingMap = new Map();\n\n for (const statement of sourceFile.statements) {\n // ESM exports: export const foo = ...\n if (ts.isExportDeclaration(statement) && statement.exportClause && ts.isNamedExports(statement.exportClause)) {\n for (const element of statement.exportClause.elements) {\n const name = element.name.text;\n bindings.set(name, name);\n }\n continue;\n }\n\n // Export variable declaration: export const foo = ...\n if (ts.isVariableStatement(statement) && statement.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)) {\n for (const declaration of statement.declarationList.declarations) {\n if (ts.isIdentifier(declaration.name)) {\n bindings.set(declaration.name.text, declaration.name.text);\n }\n }\n continue;\n }\n\n // Export function/class: export function foo() {} or export class Foo {}\n if (\n (ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement)) &&\n statement.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword) &&\n statement.name\n ) {\n bindings.set(statement.name.text, statement.name.text);\n continue;\n }\n\n // CommonJS exports: exports.foo = ... or module.exports.foo = ...\n if (ts.isExpressionStatement(statement) && ts.isBinaryExpression(statement.expression)) {\n const exportName = getCommonJsExportName(statement.expression.left);\n if (exportName) {\n bindings.set(exportName, exportName);\n }\n }\n }\n\n return bindings;\n};\n\nconst getCommonJsExportName = (node: ts.Node): string | null => {\n if (!ts.isPropertyAccessExpression(node)) {\n return null;\n }\n\n // Check if it's exports.foo or module.exports.foo\n const isExports = ts.isIdentifier(node.expression) && node.expression.text === \"exports\";\n const isModuleExports =\n ts.isPropertyAccessExpression(node.expression) &&\n ts.isIdentifier(node.expression.expression) &&\n node.expression.expression.text === \"module\" &&\n ts.isIdentifier(node.expression.name) &&\n node.expression.name.text === \"exports\";\n\n if (!isExports && !isModuleExports) {\n return null;\n }\n\n // Extract property name\n if (ts.isIdentifier(node.name)) {\n return node.name.text;\n }\n\n return null;\n};\n\nconst createAnonymousNameFactory = (): ((kind: string) => string) => {\n const counters = new Map<string, number>();\n return (kind) => {\n const count = counters.get(kind) ?? 0;\n counters.set(kind, count + 1);\n return `${kind}#${count}`;\n };\n};\n\nconst isGqlDefinitionCall = (node: ts.Node, typescript: typeof ts): node is ts.CallExpression => {\n if (!typescript.isCallExpression(node)) {\n return false;\n }\n if (!typescript.isPropertyAccessExpression(node.expression)) {\n return false;\n }\n if (!isGqlReference(node.expression.expression, typescript)) {\n return false;\n }\n if (node.arguments.length === 0) {\n return false;\n }\n const firstArg = node.arguments[0];\n if (firstArg === undefined) {\n return false;\n }\n return typescript.isArrowFunction(firstArg);\n};\n\nconst isGqlReference = (expr: ts.Expression, typescript: typeof ts): boolean => {\n if (typescript.isIdentifier(expr) && expr.text === \"gql\") {\n return true;\n }\n if (!typescript.isPropertyAccessExpression(expr)) {\n return false;\n }\n if (typescript.isIdentifier(expr.name) && expr.name.text === \"gql\") {\n return true;\n }\n return isGqlReference(expr.expression, typescript);\n};\n\nconst resolveTopLevelExport = (\n callNode: ts.CallExpression,\n exportBindings: ExportBindingMap,\n typescript: typeof ts,\n): { readonly isExported: true; readonly exportBinding: string } | null => {\n // ESM: const foo = gql.default(...); export { foo };\n const parent = callNode.parent;\n if (!parent) {\n return null;\n }\n\n if (typescript.isVariableDeclaration(parent)) {\n const { name } = parent;\n if (typescript.isIdentifier(name)) {\n const exportBinding = exportBindings.get(name.text);\n if (exportBinding) {\n return { isExported: true, exportBinding };\n }\n }\n }\n\n // CommonJS: exports.foo = gql.default(...);\n if (typescript.isBinaryExpression(parent)) {\n const exportName = getCommonJsExportName(parent.left);\n if (exportName && exportBindings.has(exportName)) {\n return { isExported: true, exportBinding: exportName };\n }\n }\n\n return null;\n};\n\nconst maybeEnterScope = (\n node: ts.Node,\n tracker: CanonicalPathTracker,\n getAnonymousName: (kind: string) => string,\n typescript: typeof ts,\n): ScopeHandle | null => {\n // CommonJS exports: exports.foo = ... or module.exports.foo = ...\n if (typescript.isBinaryExpression(node)) {\n const exportName = getCommonJsExportName(node.left);\n if (exportName) {\n return tracker.enterScope({ segment: exportName, kind: \"variable\", stableKey: `var:${exportName}` });\n }\n }\n\n if (typescript.isVariableDeclaration(node) && typescript.isIdentifier(node.name)) {\n const name = node.name.text;\n return tracker.enterScope({ segment: name, kind: \"variable\", stableKey: `var:${name}` });\n }\n\n if (typescript.isArrowFunction(node)) {\n const name = getAnonymousName(\"arrow\");\n return tracker.enterScope({ segment: name, kind: \"function\", stableKey: \"arrow\" });\n }\n\n if (typescript.isFunctionDeclaration(node) || typescript.isFunctionExpression(node)) {\n const explicitName = node.name?.text;\n const name = explicitName ?? getAnonymousName(\"function\");\n return tracker.enterScope({ segment: name, kind: \"function\", stableKey: `func:${name}` });\n }\n\n if (typescript.isClassDeclaration(node)) {\n const explicitName = node.name?.text;\n const name = explicitName ?? getAnonymousName(\"class\");\n return tracker.enterScope({ segment: name, kind: \"class\", stableKey: `class:${name}` });\n }\n\n if (typescript.isMethodDeclaration(node) && typescript.isIdentifier(node.name)) {\n const name = node.name.text;\n return tracker.enterScope({ segment: name, kind: \"method\", stableKey: `member:${name}` });\n }\n\n if (typescript.isPropertyDeclaration(node) && typescript.isIdentifier(node.name)) {\n const name = node.name.text;\n return tracker.enterScope({ segment: name, kind: \"property\", stableKey: `member:${name}` });\n }\n\n if (typescript.isPropertyAssignment(node)) {\n const key = node.name;\n const name = typescript.isIdentifier(key) ? key.text : typescript.isStringLiteral(key) ? key.text : null;\n if (name) {\n return tracker.enterScope({ segment: name, kind: \"property\", stableKey: `prop:${name}` });\n }\n }\n\n return null;\n};\n","import type { BuilderArtifactElement } from \"@soda-gql/builder\";\nimport type {\n GqlCallFragment,\n GqlCallOperation,\n PluginAnalysisArtifactMissingError,\n PluginAnalysisMetadataMissingError,\n PluginAnalysisUnsupportedArtifactTypeError,\n PluginError,\n} from \"@soda-gql/builder/plugin-support\";\nimport { resolveCanonicalId } from \"@soda-gql/builder/plugin-support\";\nimport type { CanonicalId } from \"@soda-gql/common\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport type * as ts from \"typescript\";\nimport type { GqlDefinitionMetadataMap } from \"./metadata\";\n\nexport type ArtifactLookup = (canonicalId: CanonicalId) => BuilderArtifactElement | undefined;\n\n// TypeScript-specific GqlCall types\nexport type TsGqlCallFragment = GqlCallFragment & { readonly callNode: ts.CallExpression };\nexport type TsGqlCallOperation = GqlCallOperation & { readonly callNode: ts.CallExpression };\n\nexport type TsGqlCall = TsGqlCallFragment | TsGqlCallOperation;\n\nexport type ExtractGqlCallArgs = {\n readonly callNode: ts.CallExpression;\n readonly filename: string;\n readonly metadata: GqlDefinitionMetadataMap;\n readonly getArtifact: ArtifactLookup;\n /**\n * Base directory for relative path computation.\n * When provided, canonical IDs use paths relative to this directory.\n */\n readonly baseDir?: string;\n};\n\nexport const extractGqlCall = ({\n callNode,\n filename,\n metadata,\n getArtifact,\n baseDir,\n}: ExtractGqlCallArgs): Result<TsGqlCall, PluginError> => {\n const meta = metadata.get(callNode);\n if (!meta) {\n return err(createMetadataMissingError({ filename }));\n }\n\n const canonicalId = resolveCanonicalId(filename, meta.astPath, { baseDir });\n const artifact = getArtifact(canonicalId);\n\n if (!artifact) {\n return err(createArtifactMissingError({ filename, canonicalId }));\n }\n\n if (artifact.type === \"fragment\") {\n return ok({ callNode, canonicalId, type: \"fragment\", artifact });\n }\n\n if (artifact.type === \"operation\") {\n return ok({ callNode, canonicalId, type: \"operation\", artifact });\n }\n\n return err(\n createUnsupportedArtifactTypeError({\n filename,\n canonicalId,\n artifactType: (artifact as { type: string }).type,\n }),\n );\n};\n\ntype MetadataErrorInput = { readonly filename: string };\ntype ArtifactMissingErrorInput = { readonly filename: string; readonly canonicalId: CanonicalId };\ntype UnsupportedArtifactTypeInput = {\n readonly filename: string;\n readonly canonicalId: CanonicalId;\n readonly artifactType: string;\n};\n\nconst createMetadataMissingError = ({ filename }: MetadataErrorInput): PluginAnalysisMetadataMissingError => ({\n type: \"PluginError\",\n stage: \"analysis\",\n code: \"SODA_GQL_METADATA_NOT_FOUND\",\n message: `No GraphQL metadata found for ${filename}`,\n cause: { filename },\n filename,\n});\n\nconst createArtifactMissingError = ({\n filename,\n canonicalId,\n}: ArtifactMissingErrorInput): PluginAnalysisArtifactMissingError => ({\n type: \"PluginError\",\n stage: \"analysis\",\n code: \"SODA_GQL_ANALYSIS_ARTIFACT_NOT_FOUND\",\n message: `No builder artifact found for canonical ID ${canonicalId}`,\n cause: { filename, canonicalId },\n filename,\n canonicalId,\n});\n\nconst createUnsupportedArtifactTypeError = ({\n filename,\n canonicalId,\n artifactType,\n}: UnsupportedArtifactTypeInput): PluginAnalysisUnsupportedArtifactTypeError => ({\n type: \"PluginError\",\n stage: \"analysis\",\n code: \"SODA_GQL_UNSUPPORTED_ARTIFACT_TYPE\",\n message: `Unsupported builder artifact type \"${artifactType}\" for canonical ID ${canonicalId}`,\n cause: { filename, canonicalId, artifactType },\n filename,\n canonicalId,\n artifactType,\n});\n","import type { PluginError, PluginTransformUnsupportedValueTypeError } from \"@soda-gql/builder/plugin-support\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport * as ts from \"typescript\";\n\nconst createUnsupportedValueTypeError = (valueType: string): PluginTransformUnsupportedValueTypeError => ({\n type: \"PluginError\",\n stage: \"transform\",\n code: \"SODA_GQL_TRANSFORM_UNSUPPORTED_VALUE_TYPE\",\n message: `Unsupported value type: ${valueType}`,\n cause: { valueType },\n valueType,\n});\n\n/**\n * Build a literal expression from a primitive value.\n * Mirrors Babel's buildLiteralFromValue.\n */\nexport const buildLiteralFromValue = (factory: ts.NodeFactory, value: unknown): Result<ts.Expression, PluginError> => {\n if (value === null) {\n return ok(factory.createNull());\n }\n if (typeof value === \"string\") {\n return ok(factory.createStringLiteral(value));\n }\n if (typeof value === \"number\") {\n return ok(factory.createNumericLiteral(value));\n }\n if (typeof value === \"boolean\") {\n return ok(value ? factory.createTrue() : factory.createFalse());\n }\n if (Array.isArray(value)) {\n const elements: ts.Expression[] = [];\n for (const item of value) {\n const result = buildLiteralFromValue(factory, item);\n if (result.isErr()) {\n return result;\n }\n elements.push(result.value);\n }\n return ok(factory.createArrayLiteralExpression(elements));\n }\n if (typeof value === \"object\") {\n const properties: ts.PropertyAssignment[] = [];\n for (const [key, val] of Object.entries(value)) {\n const result = buildLiteralFromValue(factory, val);\n if (result.isErr()) {\n return result;\n }\n properties.push(factory.createPropertyAssignment(factory.createIdentifier(key), result.value));\n }\n return ok(factory.createObjectLiteralExpression(properties));\n }\n return err(createUnsupportedValueTypeError(typeof value));\n};\n\n/**\n * Clone a TypeScript node deeply.\n * TypeScript nodes are immutable, so we need to use visitEachChild for deep cloning.\n */\nexport const clone = <T extends ts.Node>(node: T): T => {\n const cloneVisitor = (n: ts.Node): ts.Node => ts.visitEachChild(n, cloneVisitor, undefined);\n return cloneVisitor(node) as T;\n};\n\n/**\n * Build an object literal expression from a record of properties.\n */\nexport const buildObjectExpression = <K extends string>(\n factory: ts.NodeFactory,\n properties: Record<K, ts.Expression>,\n): ts.ObjectLiteralExpression => {\n const propertyAssignments = Object.entries<ts.Expression>(properties).map(([key, value]) =>\n factory.createPropertyAssignment(factory.createIdentifier(key), value),\n );\n return factory.createObjectLiteralExpression(propertyAssignments);\n};\n\n/**\n * Build a JSON.parse expression from an object value.\n * This is used to emit large objects as JSON strings to reduce the calculation cost of both the compiler and the runtime.\n */\nexport const buildJsonParseExpression = <T extends object>(factory: ts.NodeFactory, value: T): ts.Expression =>\n factory.createCallExpression(\n factory.createPropertyAccessExpression(factory.createIdentifier(\"JSON\"), factory.createIdentifier(\"parse\")),\n undefined,\n [factory.createStringLiteral(JSON.stringify(value))],\n );\n","import type { PluginError } from \"@soda-gql/builder/plugin-support\";\nimport type { RuntimeOperationInput } from \"@soda-gql/core/runtime\";\nimport { ok, type Result } from \"neverthrow\";\nimport type * as ts from \"typescript\";\nimport type { TsGqlCallFragment, TsGqlCallOperation } from \"./analysis\";\nimport { buildJsonParseExpression, buildObjectExpression } from \"./ast\";\n\nconst createRuntimeAccessor = ({ isCJS, factory }: { isCJS: boolean; factory: ts.NodeFactory }) =>\n isCJS\n ? factory.createPropertyAccessExpression(\n factory.createIdentifier(\"__soda_gql_runtime\"),\n factory.createIdentifier(\"gqlRuntime\"),\n )\n : factory.createIdentifier(\"gqlRuntime\");\n\nexport const buildFragmentRuntimeCall = ({\n gqlCall,\n factory,\n isCJS,\n}: {\n gqlCall: TsGqlCallFragment;\n factory: ts.NodeFactory;\n isCJS: boolean;\n filename: string;\n}): Result<ts.Expression, PluginError> => {\n const prebuildProps: Record<string, ts.Expression> = {\n typename: factory.createStringLiteral(gqlCall.artifact.prebuild.typename),\n };\n if (gqlCall.artifact.prebuild.key !== undefined) {\n prebuildProps.key = factory.createStringLiteral(gqlCall.artifact.prebuild.key);\n }\n\n return ok(\n factory.createCallExpression(\n factory.createPropertyAccessExpression(createRuntimeAccessor({ isCJS, factory }), factory.createIdentifier(\"fragment\")),\n undefined,\n [\n buildObjectExpression(factory, {\n prebuild: buildObjectExpression(factory, prebuildProps),\n }),\n ],\n ),\n );\n};\n\nexport const buildOperationRuntimeComponents = ({\n gqlCall,\n factory,\n isCJS,\n}: {\n gqlCall: TsGqlCallOperation;\n factory: ts.NodeFactory;\n isCJS: boolean;\n}): Result<{ referenceCall: ts.Expression; runtimeCall: ts.Expression }, PluginError> => {\n const runtimeCall = factory.createCallExpression(\n factory.createPropertyAccessExpression(createRuntimeAccessor({ isCJS, factory }), factory.createIdentifier(\"operation\")),\n undefined,\n [\n buildObjectExpression(factory, {\n prebuild: buildJsonParseExpression<RuntimeOperationInput[\"prebuild\"]>(factory, gqlCall.artifact.prebuild),\n runtime: buildObjectExpression(factory, {}),\n }),\n ],\n );\n\n const referenceCall = factory.createCallExpression(\n factory.createPropertyAccessExpression(createRuntimeAccessor({ isCJS, factory }), factory.createIdentifier(\"getOperation\")),\n undefined,\n [factory.createStringLiteral(gqlCall.artifact.prebuild.operationName)],\n );\n\n return ok({\n referenceCall,\n runtimeCall,\n });\n};\n","import type { PluginError } from \"@soda-gql/builder/plugin-support\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport type * as ts from \"typescript\";\nimport type { ArtifactLookup, TsGqlCall } from \"./analysis\";\nimport { extractGqlCall } from \"./analysis\";\nimport type { GqlDefinitionMetadataMap } from \"./metadata\";\nimport { buildFragmentRuntimeCall, buildOperationRuntimeComponents } from \"./runtime\";\n\ntype TransformCallExpressionArgs = {\n readonly callNode: ts.CallExpression;\n readonly filename: string;\n readonly metadata: GqlDefinitionMetadataMap;\n readonly getArtifact: ArtifactLookup;\n readonly factory: ts.NodeFactory;\n readonly isCJS: boolean;\n /**\n * Base directory for relative path computation.\n * When provided, canonical IDs use paths relative to this directory.\n */\n readonly baseDir?: string;\n};\n\ntype TransformCallExpressionResult =\n | { readonly transformed: false }\n | { readonly transformed: true; readonly replacement: ts.Expression; readonly runtimeCall?: ts.Expression };\n\nexport const transformCallExpression = ({\n callNode,\n filename,\n metadata,\n getArtifact,\n factory,\n isCJS,\n baseDir,\n}: TransformCallExpressionArgs): Result<TransformCallExpressionResult, PluginError> => {\n // Skip if this call doesn't have GQL metadata\n if (!metadata.has(callNode)) {\n return ok({ transformed: false });\n }\n\n const gqlCallResult = extractGqlCall({\n callNode,\n filename,\n metadata,\n getArtifact,\n baseDir,\n });\n\n if (gqlCallResult.isErr()) {\n return err(gqlCallResult.error);\n }\n\n const gqlCall = gqlCallResult.value;\n\n return replaceWithRuntimeCall({ gqlCall, factory, isCJS, filename });\n};\n\nconst replaceWithRuntimeCall = ({\n gqlCall,\n factory,\n isCJS,\n filename,\n}: {\n gqlCall: TsGqlCall;\n factory: ts.NodeFactory;\n isCJS: boolean;\n filename: string;\n}): Result<TransformCallExpressionResult, PluginError> => {\n if (gqlCall.type === \"fragment\") {\n const result = buildFragmentRuntimeCall({ gqlCall, factory, isCJS, filename });\n if (result.isErr()) {\n return err(result.error);\n }\n return ok({ transformed: true, replacement: result.value as ts.Expression });\n }\n\n if (gqlCall.type === \"operation\") {\n const result = buildOperationRuntimeComponents({ gqlCall, factory, isCJS });\n if (result.isErr()) {\n return err(result.error);\n }\n const { referenceCall, runtimeCall } = result.value;\n return ok({ transformed: true, replacement: referenceCall, runtimeCall });\n }\n\n return ok({ transformed: false });\n};\n","/**\n * TypeScript implementation of the TransformAdapter interface.\n */\n\nimport type { BuilderArtifact } from \"@soda-gql/builder\";\nimport { createGraphqlSystemIdentifyHelper } from \"@soda-gql/builder\";\nimport { formatPluginError } from \"@soda-gql/builder/plugin-support\";\nimport type { CanonicalId } from \"@soda-gql/common\";\nimport type { ResolvedSodaGqlConfig } from \"@soda-gql/config\";\nimport * as ts from \"typescript\";\nimport { ensureGqlRuntimeImport, ensureGqlRuntimeRequire, removeGraphqlSystemImports } from \"./ast/imports\";\nimport { collectGqlDefinitionMetadata } from \"./ast/metadata\";\nimport { transformCallExpression } from \"./ast/transformer\";\n\nexport { createAfterStubTransformer } from \"./ast/imports\";\n\n/**\n * TypeScript-specific environment required for the adapter.\n */\nexport type TypeScriptEnv = {\n readonly sourceFile: ts.SourceFile;\n readonly context: ts.TransformationContext;\n};\n\nconst findLastImportIndex = ({ sourceFile }: { sourceFile: ts.SourceFile }): number => {\n let lastIndex = -1;\n const statements = sourceFile.statements;\n\n for (let i = 0; i < statements.length; i++) {\n const statement = statements[i];\n if (statement && ts.isImportDeclaration(statement)) {\n lastIndex = i;\n }\n }\n\n return lastIndex;\n};\n\nexport const createTransformer = ({\n compilerOptions,\n config,\n artifact,\n}: {\n readonly compilerOptions: ts.CompilerOptions;\n readonly config: ResolvedSodaGqlConfig;\n readonly artifact: BuilderArtifact;\n}) => {\n const isCJS = compilerOptions.module === ts.ModuleKind.CommonJS || compilerOptions.target === ts.ScriptTarget.ES5;\n\n // Create graphql system identify helper using builder's implementation\n const graphqlSystemIdentifyHelper = createGraphqlSystemIdentifyHelper(config);\n\n const makeSourceFileEmpty = ({ factory, sourceFile }: { factory: ts.NodeFactory; sourceFile: ts.SourceFile }) => {\n return factory.updateSourceFile(sourceFile, [\n factory.createExportDeclaration(undefined, false, factory.createNamedExports([]), undefined),\n ]);\n };\n\n const transformGqlCalls = ({ sourceFile, context }: { sourceFile: ts.SourceFile; context: ts.TransformationContext }) => {\n let transformed = false;\n\n const metadata = collectGqlDefinitionMetadata({\n sourceFile,\n filename: sourceFile.fileName,\n baseDir: config.baseDir,\n });\n\n const runtimeCallsFromLastTransform: ts.Expression[] = [];\n const visitor = (node: ts.Node): ts.Node => {\n if (ts.isCallExpression(node)) {\n const result = transformCallExpression({\n callNode: node,\n filename: sourceFile.fileName,\n metadata,\n getArtifact: (canonicalId: CanonicalId) => artifact.elements[canonicalId],\n factory: context.factory,\n isCJS,\n baseDir: config.baseDir,\n });\n\n if (result.isErr()) {\n // Log error and continue - don't fail the entire build for a single error\n console.error(`[@soda-gql/tsc] ${formatPluginError(result.error)}`);\n return node;\n }\n\n const transformResult = result.value;\n if (transformResult.transformed) {\n transformed = true;\n\n if (transformResult.runtimeCall) {\n runtimeCallsFromLastTransform.push(transformResult.runtimeCall);\n }\n\n return transformResult.replacement;\n }\n }\n\n return ts.visitEachChild(node, visitor, context);\n };\n\n const visitedNode = ts.visitNode(sourceFile, visitor);\n if (!visitedNode || !ts.isSourceFile(visitedNode)) {\n console.error(`[@soda-gql/tsc] Failed to transform source file: ${sourceFile.fileName}`);\n return sourceFile;\n }\n\n if (!transformed) {\n return sourceFile;\n }\n\n if (runtimeCallsFromLastTransform.length === 0) {\n return visitedNode;\n }\n\n const lastImportIndex = findLastImportIndex({ sourceFile });\n\n return context.factory.updateSourceFile(visitedNode, [\n ...visitedNode.statements.slice(0, lastImportIndex + 1),\n ...runtimeCallsFromLastTransform.map((expr) => context.factory.createExpressionStatement(expr)),\n ...visitedNode.statements.slice(lastImportIndex + 1),\n ]);\n };\n\n return {\n transform: ({ sourceFile, context }: { sourceFile: ts.SourceFile; context: ts.TransformationContext }) => {\n // Stub internal modules (graphql-system and inject files)\n // These modules are only needed at build time and should be empty at runtime\n if (graphqlSystemIdentifyHelper.isInternalModuleFile({ filePath: sourceFile.fileName })) {\n const transformedSourceFile = makeSourceFileEmpty({ factory: context.factory, sourceFile: sourceFile });\n return { transformed: true, sourceFile: transformedSourceFile };\n }\n\n const original = sourceFile;\n let current = sourceFile;\n current = transformGqlCalls({ sourceFile: current, context });\n\n if (current !== sourceFile) {\n current = isCJS\n ? ensureGqlRuntimeRequire({ sourceFile: current, factory: context.factory })\n : ensureGqlRuntimeImport({ sourceFile: current, factory: context.factory });\n }\n\n current = removeGraphqlSystemImports({\n sourceFile: current,\n factory: context.factory,\n graphqlSystemIdentifyHelper,\n });\n\n return { transformed: current !== original, sourceFile: current };\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,MAAM,iBAAiB;;;;;;AAOvB,MAAa,2BAA2B,EACtC,YACA,cAImB;AAqBnB,KAnBiB,WAAW,WAAW,MACpC,cACCA,mBAAG,oBAAoB,UAAU,IACjC,UAAU,gBAAgB,aAAa,MAAM,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AQ;AACrD,MAAI,CAAC,eAAe,CAACA,WAAG,aAAa,YAAY,EAAE;AACjD,WAAQ,MAAM,oDAAoD,WAAW,WAAW;AACxF,UAAO;;AAGT,MAAI,CAAC,YACH,QAAO;AAGT,MAAI,8BAA8B,WAAW,EAC3C,QAAO;EAGT,MAAM,kBAAkB,oBAAoB,EAAE,YAAY,CAAC;AAE3D,SAAO,QAAQ,QAAQ,iBAAiB,aAAa;GACnD,GAAG,YAAY,WAAW,MAAM,GAAG,kBAAkB,EAAE;GACvD,GAAG,8BAA8B,KAAK,SAAS,QAAQ,QAAQ,0BAA0B,KAAK,CAAC;GAC/F,GAAG,YAAY,WAAW,MAAM,kBAAkB,EAAE;GACrD,CAAC;;AAGJ,QAAO,EACL,YAAY,EAAE,YAAY,cAAgF;AAGxG,MAAI,4BAA4B,qBAAqB,EAAE,UAAU,WAAW,UAAU,CAAC,CAErF,QAAO;GAAE,aAAa;GAAM,YADE,oBAAoB;IAAE,SAAS,QAAQ;IAAqB;IAAY,CAAC;GACxC;EAGjE,MAAM,WAAW;EACjB,IAAI,UAAU;AACd,YAAU,kBAAkB;GAAE,YAAY;GAAS;GAAS,CAAC;AAE7D,MAAI,YAAY,WACd,WAAU,QACN,wBAAwB;GAAE,YAAY;GAAS,SAAS,QAAQ;GAAS,CAAC,GAC1E,uBAAuB;GAAE,YAAY;GAAS,SAAS,QAAQ;GAAS,CAAC;AAG/E,YAAU,2BAA2B;GACnC,YAAY;GACZ,SAAS,QAAQ;GACjB;GACD,CAAC;AAEF,SAAO;GAAE,aAAa,YAAY;GAAU,YAAY;GAAS;IAEpE"}
|
|
@@ -134,10 +134,11 @@ const extractRequireTargetSpecifier = (expr) => {
|
|
|
134
134
|
|
|
135
135
|
//#endregion
|
|
136
136
|
//#region packages/tsc/src/ast/metadata.ts
|
|
137
|
-
const collectGqlDefinitionMetadata = ({ sourceFile, filename, createTracker }) => {
|
|
137
|
+
const collectGqlDefinitionMetadata = ({ sourceFile, filename, createTracker, baseDir }) => {
|
|
138
138
|
const exportBindings = collectExportBindings(sourceFile);
|
|
139
139
|
const tracker = (createTracker ?? createCanonicalTracker)({
|
|
140
140
|
filePath: filename,
|
|
141
|
+
baseDir,
|
|
141
142
|
getExportName: (localName) => exportBindings.get(localName)
|
|
142
143
|
});
|
|
143
144
|
const getAnonymousName = createAnonymousNameFactory();
|
|
@@ -318,10 +319,10 @@ const maybeEnterScope = (node, tracker, getAnonymousName, typescript) => {
|
|
|
318
319
|
|
|
319
320
|
//#endregion
|
|
320
321
|
//#region packages/tsc/src/ast/analysis.ts
|
|
321
|
-
const extractGqlCall = ({ callNode, filename, metadata, getArtifact }) => {
|
|
322
|
+
const extractGqlCall = ({ callNode, filename, metadata, getArtifact, baseDir }) => {
|
|
322
323
|
const meta = metadata.get(callNode);
|
|
323
324
|
if (!meta) return err(createMetadataMissingError({ filename }));
|
|
324
|
-
const canonicalId = resolveCanonicalId(filename, meta.astPath);
|
|
325
|
+
const canonicalId = resolveCanonicalId(filename, meta.astPath, { baseDir });
|
|
325
326
|
const artifact = getArtifact(canonicalId);
|
|
326
327
|
if (!artifact) return err(createArtifactMissingError({
|
|
327
328
|
filename,
|
|
@@ -425,13 +426,14 @@ const buildOperationRuntimeComponents = ({ gqlCall, factory, isCJS }) => {
|
|
|
425
426
|
|
|
426
427
|
//#endregion
|
|
427
428
|
//#region packages/tsc/src/ast/transformer.ts
|
|
428
|
-
const transformCallExpression = ({ callNode, filename, metadata, getArtifact, factory, isCJS }) => {
|
|
429
|
+
const transformCallExpression = ({ callNode, filename, metadata, getArtifact, factory, isCJS, baseDir }) => {
|
|
429
430
|
if (!metadata.has(callNode)) return ok({ transformed: false });
|
|
430
431
|
const gqlCallResult = extractGqlCall({
|
|
431
432
|
callNode,
|
|
432
433
|
filename,
|
|
433
434
|
metadata,
|
|
434
|
-
getArtifact
|
|
435
|
+
getArtifact,
|
|
436
|
+
baseDir
|
|
435
437
|
});
|
|
436
438
|
if (gqlCallResult.isErr()) return err(gqlCallResult.error);
|
|
437
439
|
const gqlCall = gqlCallResult.value;
|
|
@@ -494,7 +496,8 @@ const createTransformer = ({ compilerOptions, config, artifact }) => {
|
|
|
494
496
|
let transformed = false;
|
|
495
497
|
const metadata = collectGqlDefinitionMetadata({
|
|
496
498
|
sourceFile,
|
|
497
|
-
filename: sourceFile.fileName
|
|
499
|
+
filename: sourceFile.fileName,
|
|
500
|
+
baseDir: config.baseDir
|
|
498
501
|
});
|
|
499
502
|
const runtimeCallsFromLastTransform = [];
|
|
500
503
|
const visitor = (node) => {
|
|
@@ -505,7 +508,8 @@ const createTransformer = ({ compilerOptions, config, artifact }) => {
|
|
|
505
508
|
metadata,
|
|
506
509
|
getArtifact: (canonicalId) => artifact.elements[canonicalId],
|
|
507
510
|
factory: context.factory,
|
|
508
|
-
isCJS
|
|
511
|
+
isCJS,
|
|
512
|
+
baseDir: config.baseDir
|
|
509
513
|
});
|
|
510
514
|
if (result.isErr()) {
|
|
511
515
|
console.error(`[@soda-gql/tsc] ${formatPluginError(result.error)}`);
|
|
@@ -569,4 +573,4 @@ const createTransformer = ({ compilerOptions, config, artifact }) => {
|
|
|
569
573
|
|
|
570
574
|
//#endregion
|
|
571
575
|
export { createAfterStubTransformer as n, createTransformer as t };
|
|
572
|
-
//# sourceMappingURL=transformer-
|
|
576
|
+
//# sourceMappingURL=transformer-CQGLchIQ.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformer-CQGLchIQ.mjs","names":["newStatements","sourceFile","ts","bindings: ExportBindingMap","prebuildProps: Record<string, ts.Expression>","ts","runtimeCallsFromLastTransform: ts.Expression[]"],"sources":["../src/ast/imports.ts","../src/ast/metadata.ts","../src/ast/analysis.ts","../src/ast/ast.ts","../src/ast/runtime.ts","../src/ast/transformer.ts","../src/transformer.ts"],"sourcesContent":["import type { GraphqlSystemIdentifyHelper } from \"@soda-gql/builder\";\nimport ts from \"typescript\";\n\nconst RUNTIME_MODULE = \"@soda-gql/runtime\";\n\n/**\n * Ensure that the gqlRuntime require exists in the source file for CJS output.\n * Injects: const __soda_gql_runtime = require(\"@soda-gql/runtime\");\n * Returns an updated source file with the require added if needed.\n */\nexport const ensureGqlRuntimeRequire = ({\n sourceFile,\n factory,\n}: {\n sourceFile: ts.SourceFile;\n factory: ts.NodeFactory;\n}): ts.SourceFile => {\n // Check if the require already exists\n const existing = sourceFile.statements.find(\n (statement): statement is ts.VariableStatement =>\n ts.isVariableStatement(statement) &&\n statement.declarationList.declarations.some((decl) => {\n if (!ts.isIdentifier(decl.name) || decl.name.text !== \"__soda_gql_runtime\") {\n return false;\n }\n if (!decl.initializer || !ts.isCallExpression(decl.initializer)) {\n return false;\n }\n const callExpr = decl.initializer;\n if (!ts.isIdentifier(callExpr.expression) || callExpr.expression.text !== \"require\") {\n return false;\n }\n const arg = callExpr.arguments[0];\n return arg && ts.isStringLiteral(arg) && arg.text === RUNTIME_MODULE;\n }),\n );\n\n if (existing) {\n return sourceFile;\n }\n\n // Create: const __soda_gql_runtime = require(\"@soda-gql/runtime\");\n const requireCall = factory.createCallExpression(factory.createIdentifier(\"require\"), undefined, [\n factory.createStringLiteral(RUNTIME_MODULE),\n ]);\n\n const variableDeclaration = factory.createVariableDeclaration(\n factory.createIdentifier(\"__soda_gql_runtime\"),\n undefined,\n undefined,\n requireCall,\n );\n\n const variableStatement = factory.createVariableStatement(\n undefined,\n factory.createVariableDeclarationList([variableDeclaration], ts.NodeFlags.Const),\n );\n\n // Insert at the beginning of the file\n const newStatements = [variableStatement, ...sourceFile.statements];\n return factory.updateSourceFile(sourceFile, newStatements);\n};\n\n/**\n * Ensure that the gqlRuntime import exists in the source file.\n * gqlRuntime is always imported from @soda-gql/runtime.\n * Returns an updated source file with the import added or merged.\n */\nexport const ensureGqlRuntimeImport = ({\n sourceFile,\n factory,\n}: {\n sourceFile: ts.SourceFile;\n factory: ts.NodeFactory;\n}): ts.SourceFile => {\n const existing = sourceFile.statements.find(\n (statement): statement is ts.ImportDeclaration =>\n ts.isImportDeclaration(statement) &&\n ts.isStringLiteral(statement.moduleSpecifier) &&\n statement.moduleSpecifier.text === RUNTIME_MODULE,\n );\n\n if (existing?.importClause?.namedBindings && ts.isNamedImports(existing.importClause.namedBindings)) {\n const hasSpecifier = existing.importClause.namedBindings.elements.some(\n (element) => ts.isIdentifier(element.name) && element.name.text === \"gqlRuntime\",\n );\n\n if (hasSpecifier) {\n return sourceFile;\n }\n\n // Add gqlRuntime to existing import\n const newElements = [\n ...existing.importClause.namedBindings.elements,\n factory.createImportSpecifier(false, undefined, factory.createIdentifier(\"gqlRuntime\")),\n ];\n\n const newNamedBindings = factory.createNamedImports(newElements);\n const newImportClause = factory.createImportClause(false, undefined, newNamedBindings);\n const newImportDeclaration = factory.createImportDeclaration(\n undefined,\n newImportClause,\n factory.createStringLiteral(RUNTIME_MODULE),\n undefined,\n );\n\n const newStatements = sourceFile.statements.map((stmt) => (stmt === existing ? newImportDeclaration : stmt));\n return factory.updateSourceFile(sourceFile, newStatements);\n }\n\n // Create new import declaration\n const newImportDeclaration = factory.createImportDeclaration(\n undefined,\n factory.createImportClause(\n false,\n undefined,\n factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier(\"gqlRuntime\"))]),\n ),\n factory.createStringLiteral(RUNTIME_MODULE),\n undefined,\n );\n\n const newStatements = [newImportDeclaration, ...sourceFile.statements];\n return factory.updateSourceFile(sourceFile, newStatements);\n};\n\n/**\n * Remove the graphql-system import (runtimeModule) and gql-related exports from the source file.\n * After transformation, gqlRuntime is imported from @soda-gql/runtime instead,\n * so the original graphql-system import should be completely removed.\n *\n * This handles both ESM imports and CommonJS require() statements (including interop helpers).\n */\nexport const removeGraphqlSystemImports = ({\n sourceFile,\n factory,\n graphqlSystemIdentifyHelper,\n}: {\n sourceFile: ts.SourceFile;\n factory: ts.NodeFactory;\n graphqlSystemIdentifyHelper: GraphqlSystemIdentifyHelper;\n}): ts.SourceFile => {\n // After transformation, all gql usage should be replaced with gqlRuntime\n // So we can safely remove the graphql-system import and all gql-related exports\n const updatedStatements = Array.from(sourceFile.statements).filter((statement) => {\n // Remove ESM import declarations for the runtimeModule\n // - import { gql } from \"@/graphql-system\";\n // - import * as gql from \"@/graphql-system\";\n // - import gql from \"@/graphql-system\";\n // - import { gql as gqlRuntime } from \"@/graphql-system\";\n // - import * as gqlRuntime from \"@/graphql-system\";\n // - import gqlRuntime from \"@/graphql-system\";\n if (ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier)) {\n return !graphqlSystemIdentifyHelper.isGraphqlSystemImportSpecifier({\n filePath: sourceFile.fileName,\n specifier: statement.moduleSpecifier.text,\n });\n }\n\n // Remove CommonJS require() statements for the runtimeModule\n // TypeScript emits these when downleveling ESM to CJS:\n // - const graphql_system_1 = require(\"../../graphql-system\");\n // - const { gql } = require(\"@/graphql-system\");\n // - const foo = __importDefault(require(\"@/graphql-system\"));\n // - const foo = __importStar(require(\"@/graphql-system\"));\n if (ts.isVariableStatement(statement)) {\n return !statement.declarationList.declarations.every((decl) => {\n const specifier = extractRequireTargetSpecifier(decl.initializer);\n if (!specifier) {\n return false;\n }\n\n return graphqlSystemIdentifyHelper.isGraphqlSystemImportSpecifier({\n filePath: sourceFile.fileName,\n specifier: specifier,\n });\n });\n }\n\n return true;\n });\n\n if (updatedStatements.length === sourceFile.statements.length) {\n return sourceFile;\n }\n\n return factory.updateSourceFile(sourceFile, updatedStatements);\n};\n\n/**\n * Create an \"after\" transformer that stubs out require() calls for the runtimeModule.\n * This runs after TypeScript's own transformers (including CommonJS down-leveling),\n * so we can replace `const X = require(\"@/graphql-system\")` with a lightweight stub.\n *\n * This prevents the heavy graphql-system module from being loaded at runtime.\n */\nexport const createAfterStubTransformer = ({\n sourceFile,\n graphqlSystemIdentifyHelper,\n}: {\n sourceFile: ts.SourceFile;\n graphqlSystemIdentifyHelper: GraphqlSystemIdentifyHelper;\n}): ts.TransformerFactory<ts.SourceFile> => {\n return (context) => {\n const factory = context.factory;\n\n const visitor = (node: ts.Node): ts.Node => {\n // Replace variable statements that require the runtimeModule with a stub\n if (ts.isVariableStatement(node)) {\n let transformed = false;\n\n const newDeclarations = node.declarationList.declarations.map((decl) => {\n const specifier = extractRequireTargetSpecifier(decl.initializer);\n if (!specifier) {\n return decl;\n }\n\n const isGraphqlSystemImport = graphqlSystemIdentifyHelper.isGraphqlSystemImportSpecifier({\n filePath: sourceFile.fileName,\n specifier,\n });\n if (!isGraphqlSystemImport) {\n return decl;\n }\n\n // Create stub: const X = /*#__PURE__*/Object.create(null);\n const stub = factory.createCallExpression(\n factory.createPropertyAccessExpression(factory.createIdentifier(\"Object\"), \"create\"),\n undefined,\n [factory.createNull()],\n );\n\n // Add /*#__PURE__*/ comment for tree-shaking\n ts.addSyntheticLeadingComment(stub, ts.SyntaxKind.MultiLineCommentTrivia, \"#__PURE__\", false);\n\n transformed = true;\n\n return factory.updateVariableDeclaration(decl, decl.name, decl.exclamationToken, decl.type, stub);\n });\n\n if (transformed) {\n return factory.updateVariableStatement(\n node,\n node.modifiers,\n factory.updateVariableDeclarationList(node.declarationList, newDeclarations),\n );\n }\n }\n\n return ts.visitEachChild(node, visitor, context);\n };\n\n return (sourceFile) => ts.visitNode(sourceFile, visitor) as ts.SourceFile;\n };\n};\n\n/**\n * Check if an expression is a require() call for the runtimeModule.\n * Handles multiple patterns:\n * - require(\"@/graphql-system\")\n * - __importDefault(require(\"@/graphql-system\"))\n * - __importStar(require(\"@/graphql-system\"))\n */\nconst extractRequireTargetSpecifier = (expr: ts.Expression | undefined): string | undefined => {\n if (!expr) {\n return undefined;\n }\n\n // Direct require(\"@/graphql-system\")\n if (ts.isCallExpression(expr)) {\n if (ts.isIdentifier(expr.expression) && expr.expression.text === \"require\") {\n const arg = expr.arguments[0];\n if (arg && ts.isStringLiteral(arg)) {\n return arg.text;\n }\n }\n\n // __importDefault(require(\"@/graphql-system\")) or __importStar(require(\"@/graphql-system\"))\n if (ts.isIdentifier(expr.expression)) {\n const helperName = expr.expression.text;\n if (helperName === \"__importDefault\" || helperName === \"__importStar\") {\n const arg = expr.arguments[0];\n if (arg && ts.isCallExpression(arg)) {\n if (ts.isIdentifier(arg.expression) && arg.expression.text === \"require\") {\n const requireArg = arg.arguments[0];\n if (requireArg && ts.isStringLiteral(requireArg)) {\n return requireArg.text;\n }\n }\n }\n }\n }\n }\n\n return undefined;\n};\n","import type { GqlDefinitionMetadata } from \"@soda-gql/builder/plugin-support\";\nimport type { CanonicalPathTracker } from \"@soda-gql/common\";\nimport { createCanonicalTracker } from \"@soda-gql/common\";\nimport * as ts from \"typescript\";\n\nexport type GqlDefinitionMetadataMap = WeakMap<ts.CallExpression, GqlDefinitionMetadata>;\n\ntype CanonicalTrackerFactory = typeof createCanonicalTracker;\n\ntype CollectArgs = {\n readonly sourceFile: ts.SourceFile;\n readonly filename: string;\n readonly createTracker?: CanonicalTrackerFactory;\n /**\n * Base directory for relative path computation.\n * When provided, canonical IDs use paths relative to this directory.\n */\n readonly baseDir?: string;\n};\n\ntype ScopeHandle = ReturnType<CanonicalPathTracker[\"enterScope\"]>;\ntype ExportBindingMap = Map<string, string>;\n\nexport const collectGqlDefinitionMetadata = ({\n sourceFile,\n filename,\n createTracker,\n baseDir,\n}: CollectArgs): GqlDefinitionMetadataMap => {\n const exportBindings = collectExportBindings(sourceFile);\n const trackerFactory = createTracker ?? createCanonicalTracker;\n const tracker = trackerFactory({\n filePath: filename,\n baseDir,\n getExportName: (localName) => exportBindings.get(localName),\n });\n\n const getAnonymousName = createAnonymousNameFactory();\n const scopeHandles = new WeakMap<ts.Node, ScopeHandle>();\n const metadata = new WeakMap<ts.CallExpression, GqlDefinitionMetadata>();\n\n const visit = (node: ts.Node): void => {\n // Handle GraphQL definition calls\n if (ts.isCallExpression(node) && isGqlDefinitionCall(node, ts)) {\n const depthBeforeRegister = tracker.currentDepth();\n const { astPath } = tracker.registerDefinition();\n const isTopLevel = depthBeforeRegister <= 1;\n const exportInfo = isTopLevel ? resolveTopLevelExport(node, exportBindings, ts) : null;\n\n metadata.set(node, {\n astPath,\n isTopLevel,\n isExported: exportInfo?.isExported ?? false,\n exportBinding: exportInfo?.exportBinding,\n });\n\n // Skip visiting children of gql calls\n return;\n }\n\n // Enter scope if this node creates one\n const handle = maybeEnterScope(node, tracker, getAnonymousName, ts);\n if (handle) {\n scopeHandles.set(node, handle);\n }\n\n // Visit children\n ts.forEachChild(node, visit);\n\n // Exit scope if we entered one\n const scopeHandle = scopeHandles.get(node);\n if (scopeHandle) {\n tracker.exitScope(scopeHandle);\n scopeHandles.delete(node);\n }\n };\n\n visit(sourceFile);\n\n return metadata;\n};\n\nconst collectExportBindings = (sourceFile: ts.SourceFile): ExportBindingMap => {\n const bindings: ExportBindingMap = new Map();\n\n for (const statement of sourceFile.statements) {\n // ESM exports: export const foo = ...\n if (ts.isExportDeclaration(statement) && statement.exportClause && ts.isNamedExports(statement.exportClause)) {\n for (const element of statement.exportClause.elements) {\n const name = element.name.text;\n bindings.set(name, name);\n }\n continue;\n }\n\n // Export variable declaration: export const foo = ...\n if (ts.isVariableStatement(statement) && statement.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)) {\n for (const declaration of statement.declarationList.declarations) {\n if (ts.isIdentifier(declaration.name)) {\n bindings.set(declaration.name.text, declaration.name.text);\n }\n }\n continue;\n }\n\n // Export function/class: export function foo() {} or export class Foo {}\n if (\n (ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement)) &&\n statement.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword) &&\n statement.name\n ) {\n bindings.set(statement.name.text, statement.name.text);\n continue;\n }\n\n // CommonJS exports: exports.foo = ... or module.exports.foo = ...\n if (ts.isExpressionStatement(statement) && ts.isBinaryExpression(statement.expression)) {\n const exportName = getCommonJsExportName(statement.expression.left);\n if (exportName) {\n bindings.set(exportName, exportName);\n }\n }\n }\n\n return bindings;\n};\n\nconst getCommonJsExportName = (node: ts.Node): string | null => {\n if (!ts.isPropertyAccessExpression(node)) {\n return null;\n }\n\n // Check if it's exports.foo or module.exports.foo\n const isExports = ts.isIdentifier(node.expression) && node.expression.text === \"exports\";\n const isModuleExports =\n ts.isPropertyAccessExpression(node.expression) &&\n ts.isIdentifier(node.expression.expression) &&\n node.expression.expression.text === \"module\" &&\n ts.isIdentifier(node.expression.name) &&\n node.expression.name.text === \"exports\";\n\n if (!isExports && !isModuleExports) {\n return null;\n }\n\n // Extract property name\n if (ts.isIdentifier(node.name)) {\n return node.name.text;\n }\n\n return null;\n};\n\nconst createAnonymousNameFactory = (): ((kind: string) => string) => {\n const counters = new Map<string, number>();\n return (kind) => {\n const count = counters.get(kind) ?? 0;\n counters.set(kind, count + 1);\n return `${kind}#${count}`;\n };\n};\n\nconst isGqlDefinitionCall = (node: ts.Node, typescript: typeof ts): node is ts.CallExpression => {\n if (!typescript.isCallExpression(node)) {\n return false;\n }\n if (!typescript.isPropertyAccessExpression(node.expression)) {\n return false;\n }\n if (!isGqlReference(node.expression.expression, typescript)) {\n return false;\n }\n if (node.arguments.length === 0) {\n return false;\n }\n const firstArg = node.arguments[0];\n if (firstArg === undefined) {\n return false;\n }\n return typescript.isArrowFunction(firstArg);\n};\n\nconst isGqlReference = (expr: ts.Expression, typescript: typeof ts): boolean => {\n if (typescript.isIdentifier(expr) && expr.text === \"gql\") {\n return true;\n }\n if (!typescript.isPropertyAccessExpression(expr)) {\n return false;\n }\n if (typescript.isIdentifier(expr.name) && expr.name.text === \"gql\") {\n return true;\n }\n return isGqlReference(expr.expression, typescript);\n};\n\nconst resolveTopLevelExport = (\n callNode: ts.CallExpression,\n exportBindings: ExportBindingMap,\n typescript: typeof ts,\n): { readonly isExported: true; readonly exportBinding: string } | null => {\n // ESM: const foo = gql.default(...); export { foo };\n const parent = callNode.parent;\n if (!parent) {\n return null;\n }\n\n if (typescript.isVariableDeclaration(parent)) {\n const { name } = parent;\n if (typescript.isIdentifier(name)) {\n const exportBinding = exportBindings.get(name.text);\n if (exportBinding) {\n return { isExported: true, exportBinding };\n }\n }\n }\n\n // CommonJS: exports.foo = gql.default(...);\n if (typescript.isBinaryExpression(parent)) {\n const exportName = getCommonJsExportName(parent.left);\n if (exportName && exportBindings.has(exportName)) {\n return { isExported: true, exportBinding: exportName };\n }\n }\n\n return null;\n};\n\nconst maybeEnterScope = (\n node: ts.Node,\n tracker: CanonicalPathTracker,\n getAnonymousName: (kind: string) => string,\n typescript: typeof ts,\n): ScopeHandle | null => {\n // CommonJS exports: exports.foo = ... or module.exports.foo = ...\n if (typescript.isBinaryExpression(node)) {\n const exportName = getCommonJsExportName(node.left);\n if (exportName) {\n return tracker.enterScope({ segment: exportName, kind: \"variable\", stableKey: `var:${exportName}` });\n }\n }\n\n if (typescript.isVariableDeclaration(node) && typescript.isIdentifier(node.name)) {\n const name = node.name.text;\n return tracker.enterScope({ segment: name, kind: \"variable\", stableKey: `var:${name}` });\n }\n\n if (typescript.isArrowFunction(node)) {\n const name = getAnonymousName(\"arrow\");\n return tracker.enterScope({ segment: name, kind: \"function\", stableKey: \"arrow\" });\n }\n\n if (typescript.isFunctionDeclaration(node) || typescript.isFunctionExpression(node)) {\n const explicitName = node.name?.text;\n const name = explicitName ?? getAnonymousName(\"function\");\n return tracker.enterScope({ segment: name, kind: \"function\", stableKey: `func:${name}` });\n }\n\n if (typescript.isClassDeclaration(node)) {\n const explicitName = node.name?.text;\n const name = explicitName ?? getAnonymousName(\"class\");\n return tracker.enterScope({ segment: name, kind: \"class\", stableKey: `class:${name}` });\n }\n\n if (typescript.isMethodDeclaration(node) && typescript.isIdentifier(node.name)) {\n const name = node.name.text;\n return tracker.enterScope({ segment: name, kind: \"method\", stableKey: `member:${name}` });\n }\n\n if (typescript.isPropertyDeclaration(node) && typescript.isIdentifier(node.name)) {\n const name = node.name.text;\n return tracker.enterScope({ segment: name, kind: \"property\", stableKey: `member:${name}` });\n }\n\n if (typescript.isPropertyAssignment(node)) {\n const key = node.name;\n const name = typescript.isIdentifier(key) ? key.text : typescript.isStringLiteral(key) ? key.text : null;\n if (name) {\n return tracker.enterScope({ segment: name, kind: \"property\", stableKey: `prop:${name}` });\n }\n }\n\n return null;\n};\n","import type { BuilderArtifactElement } from \"@soda-gql/builder\";\nimport type {\n GqlCallFragment,\n GqlCallOperation,\n PluginAnalysisArtifactMissingError,\n PluginAnalysisMetadataMissingError,\n PluginAnalysisUnsupportedArtifactTypeError,\n PluginError,\n} from \"@soda-gql/builder/plugin-support\";\nimport { resolveCanonicalId } from \"@soda-gql/builder/plugin-support\";\nimport type { CanonicalId } from \"@soda-gql/common\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport type * as ts from \"typescript\";\nimport type { GqlDefinitionMetadataMap } from \"./metadata\";\n\nexport type ArtifactLookup = (canonicalId: CanonicalId) => BuilderArtifactElement | undefined;\n\n// TypeScript-specific GqlCall types\nexport type TsGqlCallFragment = GqlCallFragment & { readonly callNode: ts.CallExpression };\nexport type TsGqlCallOperation = GqlCallOperation & { readonly callNode: ts.CallExpression };\n\nexport type TsGqlCall = TsGqlCallFragment | TsGqlCallOperation;\n\nexport type ExtractGqlCallArgs = {\n readonly callNode: ts.CallExpression;\n readonly filename: string;\n readonly metadata: GqlDefinitionMetadataMap;\n readonly getArtifact: ArtifactLookup;\n /**\n * Base directory for relative path computation.\n * When provided, canonical IDs use paths relative to this directory.\n */\n readonly baseDir?: string;\n};\n\nexport const extractGqlCall = ({\n callNode,\n filename,\n metadata,\n getArtifact,\n baseDir,\n}: ExtractGqlCallArgs): Result<TsGqlCall, PluginError> => {\n const meta = metadata.get(callNode);\n if (!meta) {\n return err(createMetadataMissingError({ filename }));\n }\n\n const canonicalId = resolveCanonicalId(filename, meta.astPath, { baseDir });\n const artifact = getArtifact(canonicalId);\n\n if (!artifact) {\n return err(createArtifactMissingError({ filename, canonicalId }));\n }\n\n if (artifact.type === \"fragment\") {\n return ok({ callNode, canonicalId, type: \"fragment\", artifact });\n }\n\n if (artifact.type === \"operation\") {\n return ok({ callNode, canonicalId, type: \"operation\", artifact });\n }\n\n return err(\n createUnsupportedArtifactTypeError({\n filename,\n canonicalId,\n artifactType: (artifact as { type: string }).type,\n }),\n );\n};\n\ntype MetadataErrorInput = { readonly filename: string };\ntype ArtifactMissingErrorInput = { readonly filename: string; readonly canonicalId: CanonicalId };\ntype UnsupportedArtifactTypeInput = {\n readonly filename: string;\n readonly canonicalId: CanonicalId;\n readonly artifactType: string;\n};\n\nconst createMetadataMissingError = ({ filename }: MetadataErrorInput): PluginAnalysisMetadataMissingError => ({\n type: \"PluginError\",\n stage: \"analysis\",\n code: \"SODA_GQL_METADATA_NOT_FOUND\",\n message: `No GraphQL metadata found for ${filename}`,\n cause: { filename },\n filename,\n});\n\nconst createArtifactMissingError = ({\n filename,\n canonicalId,\n}: ArtifactMissingErrorInput): PluginAnalysisArtifactMissingError => ({\n type: \"PluginError\",\n stage: \"analysis\",\n code: \"SODA_GQL_ANALYSIS_ARTIFACT_NOT_FOUND\",\n message: `No builder artifact found for canonical ID ${canonicalId}`,\n cause: { filename, canonicalId },\n filename,\n canonicalId,\n});\n\nconst createUnsupportedArtifactTypeError = ({\n filename,\n canonicalId,\n artifactType,\n}: UnsupportedArtifactTypeInput): PluginAnalysisUnsupportedArtifactTypeError => ({\n type: \"PluginError\",\n stage: \"analysis\",\n code: \"SODA_GQL_UNSUPPORTED_ARTIFACT_TYPE\",\n message: `Unsupported builder artifact type \"${artifactType}\" for canonical ID ${canonicalId}`,\n cause: { filename, canonicalId, artifactType },\n filename,\n canonicalId,\n artifactType,\n});\n","import type { PluginError, PluginTransformUnsupportedValueTypeError } from \"@soda-gql/builder/plugin-support\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport * as ts from \"typescript\";\n\nconst createUnsupportedValueTypeError = (valueType: string): PluginTransformUnsupportedValueTypeError => ({\n type: \"PluginError\",\n stage: \"transform\",\n code: \"SODA_GQL_TRANSFORM_UNSUPPORTED_VALUE_TYPE\",\n message: `Unsupported value type: ${valueType}`,\n cause: { valueType },\n valueType,\n});\n\n/**\n * Build a literal expression from a primitive value.\n * Mirrors Babel's buildLiteralFromValue.\n */\nexport const buildLiteralFromValue = (factory: ts.NodeFactory, value: unknown): Result<ts.Expression, PluginError> => {\n if (value === null) {\n return ok(factory.createNull());\n }\n if (typeof value === \"string\") {\n return ok(factory.createStringLiteral(value));\n }\n if (typeof value === \"number\") {\n return ok(factory.createNumericLiteral(value));\n }\n if (typeof value === \"boolean\") {\n return ok(value ? factory.createTrue() : factory.createFalse());\n }\n if (Array.isArray(value)) {\n const elements: ts.Expression[] = [];\n for (const item of value) {\n const result = buildLiteralFromValue(factory, item);\n if (result.isErr()) {\n return result;\n }\n elements.push(result.value);\n }\n return ok(factory.createArrayLiteralExpression(elements));\n }\n if (typeof value === \"object\") {\n const properties: ts.PropertyAssignment[] = [];\n for (const [key, val] of Object.entries(value)) {\n const result = buildLiteralFromValue(factory, val);\n if (result.isErr()) {\n return result;\n }\n properties.push(factory.createPropertyAssignment(factory.createIdentifier(key), result.value));\n }\n return ok(factory.createObjectLiteralExpression(properties));\n }\n return err(createUnsupportedValueTypeError(typeof value));\n};\n\n/**\n * Clone a TypeScript node deeply.\n * TypeScript nodes are immutable, so we need to use visitEachChild for deep cloning.\n */\nexport const clone = <T extends ts.Node>(node: T): T => {\n const cloneVisitor = (n: ts.Node): ts.Node => ts.visitEachChild(n, cloneVisitor, undefined);\n return cloneVisitor(node) as T;\n};\n\n/**\n * Build an object literal expression from a record of properties.\n */\nexport const buildObjectExpression = <K extends string>(\n factory: ts.NodeFactory,\n properties: Record<K, ts.Expression>,\n): ts.ObjectLiteralExpression => {\n const propertyAssignments = Object.entries<ts.Expression>(properties).map(([key, value]) =>\n factory.createPropertyAssignment(factory.createIdentifier(key), value),\n );\n return factory.createObjectLiteralExpression(propertyAssignments);\n};\n\n/**\n * Build a JSON.parse expression from an object value.\n * This is used to emit large objects as JSON strings to reduce the calculation cost of both the compiler and the runtime.\n */\nexport const buildJsonParseExpression = <T extends object>(factory: ts.NodeFactory, value: T): ts.Expression =>\n factory.createCallExpression(\n factory.createPropertyAccessExpression(factory.createIdentifier(\"JSON\"), factory.createIdentifier(\"parse\")),\n undefined,\n [factory.createStringLiteral(JSON.stringify(value))],\n );\n","import type { PluginError } from \"@soda-gql/builder/plugin-support\";\nimport type { RuntimeOperationInput } from \"@soda-gql/core/runtime\";\nimport { ok, type Result } from \"neverthrow\";\nimport type * as ts from \"typescript\";\nimport type { TsGqlCallFragment, TsGqlCallOperation } from \"./analysis\";\nimport { buildJsonParseExpression, buildObjectExpression } from \"./ast\";\n\nconst createRuntimeAccessor = ({ isCJS, factory }: { isCJS: boolean; factory: ts.NodeFactory }) =>\n isCJS\n ? factory.createPropertyAccessExpression(\n factory.createIdentifier(\"__soda_gql_runtime\"),\n factory.createIdentifier(\"gqlRuntime\"),\n )\n : factory.createIdentifier(\"gqlRuntime\");\n\nexport const buildFragmentRuntimeCall = ({\n gqlCall,\n factory,\n isCJS,\n}: {\n gqlCall: TsGqlCallFragment;\n factory: ts.NodeFactory;\n isCJS: boolean;\n filename: string;\n}): Result<ts.Expression, PluginError> => {\n const prebuildProps: Record<string, ts.Expression> = {\n typename: factory.createStringLiteral(gqlCall.artifact.prebuild.typename),\n };\n if (gqlCall.artifact.prebuild.key !== undefined) {\n prebuildProps.key = factory.createStringLiteral(gqlCall.artifact.prebuild.key);\n }\n\n return ok(\n factory.createCallExpression(\n factory.createPropertyAccessExpression(createRuntimeAccessor({ isCJS, factory }), factory.createIdentifier(\"fragment\")),\n undefined,\n [\n buildObjectExpression(factory, {\n prebuild: buildObjectExpression(factory, prebuildProps),\n }),\n ],\n ),\n );\n};\n\nexport const buildOperationRuntimeComponents = ({\n gqlCall,\n factory,\n isCJS,\n}: {\n gqlCall: TsGqlCallOperation;\n factory: ts.NodeFactory;\n isCJS: boolean;\n}): Result<{ referenceCall: ts.Expression; runtimeCall: ts.Expression }, PluginError> => {\n const runtimeCall = factory.createCallExpression(\n factory.createPropertyAccessExpression(createRuntimeAccessor({ isCJS, factory }), factory.createIdentifier(\"operation\")),\n undefined,\n [\n buildObjectExpression(factory, {\n prebuild: buildJsonParseExpression<RuntimeOperationInput[\"prebuild\"]>(factory, gqlCall.artifact.prebuild),\n runtime: buildObjectExpression(factory, {}),\n }),\n ],\n );\n\n const referenceCall = factory.createCallExpression(\n factory.createPropertyAccessExpression(createRuntimeAccessor({ isCJS, factory }), factory.createIdentifier(\"getOperation\")),\n undefined,\n [factory.createStringLiteral(gqlCall.artifact.prebuild.operationName)],\n );\n\n return ok({\n referenceCall,\n runtimeCall,\n });\n};\n","import type { PluginError } from \"@soda-gql/builder/plugin-support\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport type * as ts from \"typescript\";\nimport type { ArtifactLookup, TsGqlCall } from \"./analysis\";\nimport { extractGqlCall } from \"./analysis\";\nimport type { GqlDefinitionMetadataMap } from \"./metadata\";\nimport { buildFragmentRuntimeCall, buildOperationRuntimeComponents } from \"./runtime\";\n\ntype TransformCallExpressionArgs = {\n readonly callNode: ts.CallExpression;\n readonly filename: string;\n readonly metadata: GqlDefinitionMetadataMap;\n readonly getArtifact: ArtifactLookup;\n readonly factory: ts.NodeFactory;\n readonly isCJS: boolean;\n /**\n * Base directory for relative path computation.\n * When provided, canonical IDs use paths relative to this directory.\n */\n readonly baseDir?: string;\n};\n\ntype TransformCallExpressionResult =\n | { readonly transformed: false }\n | { readonly transformed: true; readonly replacement: ts.Expression; readonly runtimeCall?: ts.Expression };\n\nexport const transformCallExpression = ({\n callNode,\n filename,\n metadata,\n getArtifact,\n factory,\n isCJS,\n baseDir,\n}: TransformCallExpressionArgs): Result<TransformCallExpressionResult, PluginError> => {\n // Skip if this call doesn't have GQL metadata\n if (!metadata.has(callNode)) {\n return ok({ transformed: false });\n }\n\n const gqlCallResult = extractGqlCall({\n callNode,\n filename,\n metadata,\n getArtifact,\n baseDir,\n });\n\n if (gqlCallResult.isErr()) {\n return err(gqlCallResult.error);\n }\n\n const gqlCall = gqlCallResult.value;\n\n return replaceWithRuntimeCall({ gqlCall, factory, isCJS, filename });\n};\n\nconst replaceWithRuntimeCall = ({\n gqlCall,\n factory,\n isCJS,\n filename,\n}: {\n gqlCall: TsGqlCall;\n factory: ts.NodeFactory;\n isCJS: boolean;\n filename: string;\n}): Result<TransformCallExpressionResult, PluginError> => {\n if (gqlCall.type === \"fragment\") {\n const result = buildFragmentRuntimeCall({ gqlCall, factory, isCJS, filename });\n if (result.isErr()) {\n return err(result.error);\n }\n return ok({ transformed: true, replacement: result.value as ts.Expression });\n }\n\n if (gqlCall.type === \"operation\") {\n const result = buildOperationRuntimeComponents({ gqlCall, factory, isCJS });\n if (result.isErr()) {\n return err(result.error);\n }\n const { referenceCall, runtimeCall } = result.value;\n return ok({ transformed: true, replacement: referenceCall, runtimeCall });\n }\n\n return ok({ transformed: false });\n};\n","/**\n * TypeScript implementation of the TransformAdapter interface.\n */\n\nimport type { BuilderArtifact } from \"@soda-gql/builder\";\nimport { createGraphqlSystemIdentifyHelper } from \"@soda-gql/builder\";\nimport { formatPluginError } from \"@soda-gql/builder/plugin-support\";\nimport type { CanonicalId } from \"@soda-gql/common\";\nimport type { ResolvedSodaGqlConfig } from \"@soda-gql/config\";\nimport * as ts from \"typescript\";\nimport { ensureGqlRuntimeImport, ensureGqlRuntimeRequire, removeGraphqlSystemImports } from \"./ast/imports\";\nimport { collectGqlDefinitionMetadata } from \"./ast/metadata\";\nimport { transformCallExpression } from \"./ast/transformer\";\n\nexport { createAfterStubTransformer } from \"./ast/imports\";\n\n/**\n * TypeScript-specific environment required for the adapter.\n */\nexport type TypeScriptEnv = {\n readonly sourceFile: ts.SourceFile;\n readonly context: ts.TransformationContext;\n};\n\nconst findLastImportIndex = ({ sourceFile }: { sourceFile: ts.SourceFile }): number => {\n let lastIndex = -1;\n const statements = sourceFile.statements;\n\n for (let i = 0; i < statements.length; i++) {\n const statement = statements[i];\n if (statement && ts.isImportDeclaration(statement)) {\n lastIndex = i;\n }\n }\n\n return lastIndex;\n};\n\nexport const createTransformer = ({\n compilerOptions,\n config,\n artifact,\n}: {\n readonly compilerOptions: ts.CompilerOptions;\n readonly config: ResolvedSodaGqlConfig;\n readonly artifact: BuilderArtifact;\n}) => {\n const isCJS = compilerOptions.module === ts.ModuleKind.CommonJS || compilerOptions.target === ts.ScriptTarget.ES5;\n\n // Create graphql system identify helper using builder's implementation\n const graphqlSystemIdentifyHelper = createGraphqlSystemIdentifyHelper(config);\n\n const makeSourceFileEmpty = ({ factory, sourceFile }: { factory: ts.NodeFactory; sourceFile: ts.SourceFile }) => {\n return factory.updateSourceFile(sourceFile, [\n factory.createExportDeclaration(undefined, false, factory.createNamedExports([]), undefined),\n ]);\n };\n\n const transformGqlCalls = ({ sourceFile, context }: { sourceFile: ts.SourceFile; context: ts.TransformationContext }) => {\n let transformed = false;\n\n const metadata = collectGqlDefinitionMetadata({\n sourceFile,\n filename: sourceFile.fileName,\n baseDir: config.baseDir,\n });\n\n const runtimeCallsFromLastTransform: ts.Expression[] = [];\n const visitor = (node: ts.Node): ts.Node => {\n if (ts.isCallExpression(node)) {\n const result = transformCallExpression({\n callNode: node,\n filename: sourceFile.fileName,\n metadata,\n getArtifact: (canonicalId: CanonicalId) => artifact.elements[canonicalId],\n factory: context.factory,\n isCJS,\n baseDir: config.baseDir,\n });\n\n if (result.isErr()) {\n // Log error and continue - don't fail the entire build for a single error\n console.error(`[@soda-gql/tsc] ${formatPluginError(result.error)}`);\n return node;\n }\n\n const transformResult = result.value;\n if (transformResult.transformed) {\n transformed = true;\n\n if (transformResult.runtimeCall) {\n runtimeCallsFromLastTransform.push(transformResult.runtimeCall);\n }\n\n return transformResult.replacement;\n }\n }\n\n return ts.visitEachChild(node, visitor, context);\n };\n\n const visitedNode = ts.visitNode(sourceFile, visitor);\n if (!visitedNode || !ts.isSourceFile(visitedNode)) {\n console.error(`[@soda-gql/tsc] Failed to transform source file: ${sourceFile.fileName}`);\n return sourceFile;\n }\n\n if (!transformed) {\n return sourceFile;\n }\n\n if (runtimeCallsFromLastTransform.length === 0) {\n return visitedNode;\n }\n\n const lastImportIndex = findLastImportIndex({ sourceFile });\n\n return context.factory.updateSourceFile(visitedNode, [\n ...visitedNode.statements.slice(0, lastImportIndex + 1),\n ...runtimeCallsFromLastTransform.map((expr) => context.factory.createExpressionStatement(expr)),\n ...visitedNode.statements.slice(lastImportIndex + 1),\n ]);\n };\n\n return {\n transform: ({ sourceFile, context }: { sourceFile: ts.SourceFile; context: ts.TransformationContext }) => {\n // Stub internal modules (graphql-system and inject files)\n // These modules are only needed at build time and should be empty at runtime\n if (graphqlSystemIdentifyHelper.isInternalModuleFile({ filePath: sourceFile.fileName })) {\n const transformedSourceFile = makeSourceFileEmpty({ factory: context.factory, sourceFile: sourceFile });\n return { transformed: true, sourceFile: transformedSourceFile };\n }\n\n const original = sourceFile;\n let current = sourceFile;\n current = transformGqlCalls({ sourceFile: current, context });\n\n if (current !== sourceFile) {\n current = isCJS\n ? ensureGqlRuntimeRequire({ sourceFile: current, factory: context.factory })\n : ensureGqlRuntimeImport({ sourceFile: current, factory: context.factory });\n }\n\n current = removeGraphqlSystemImports({\n sourceFile: current,\n factory: context.factory,\n graphqlSystemIdentifyHelper,\n });\n\n return { transformed: current !== original, sourceFile: current };\n },\n };\n};\n"],"mappings":";;;;;;;;AAGA,MAAM,iBAAiB;;;;;;AAOvB,MAAa,2BAA2B,EACtC,YACA,cAImB;AAqBnB,KAnBiB,WAAW,WAAW,MACpC,cACC,GAAG,oBAAoB,UAAU,IACjC,UAAU,gBAAgB,aAAa,MAAM,SAAS;AACpD,MAAI,CAAC,GAAG,aAAa,KAAK,KAAK,IAAI,KAAK,KAAK,SAAS,qBACpD,QAAO;AAET,MAAI,CAAC,KAAK,eAAe,CAAC,GAAG,iBAAiB,KAAK,YAAY,CAC7D,QAAO;EAET,MAAM,WAAW,KAAK;AACtB,MAAI,CAAC,GAAG,aAAa,SAAS,WAAW,IAAI,SAAS,WAAW,SAAS,UACxE,QAAO;EAET,MAAM,MAAM,SAAS,UAAU;AAC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AAW,MAAM,GAAG,kBAAkB,EAAE;GACvD,GAAG,8BAA8B,KAAK,SAAS,QAAQ,QAAQ,0BAA0B,KAAK,CAAC;GAC/F,GAAG,YAAY,WAAW,MAAM,kBAAkB,EAAE;GACrD,CAAC;;AAGJ,QAAO,EACL,YAAY,EAAE,YAAY,cAAgF;AAGxG,MAAI,4BAA4B,qBAAqB,EAAE,UAAU,WAAW,UAAU,CAAC,CAErF,QAAO;GAAE,aAAa;GAAM,YADE,oBAAoB;IAAE,SAAS,QAAQ;IAAqB;IAAY,CAAC;GACxC;EAGjE,MAAM,WAAW;EACjB,IAAI,UAAU;AACd,YAAU,kBAAkB;GAAE,YAAY;GAAS;GAAS,CAAC;AAE7D,MAAI,YAAY,WACd,WAAU,QACN,wBAAwB;GAAE,YAAY;GAAS,SAAS,QAAQ;GAAS,CAAC,GAC1E,uBAAuB;GAAE,YAAY;GAAS,SAAS,QAAQ;GAAS,CAAC;AAG/E,YAAU,2BAA2B;GACnC,YAAY;GACZ,SAAS,QAAQ;GACjB;GACD,CAAC;AAEF,SAAO;GAAE,aAAa,YAAY;GAAU,YAAY;GAAS;IAEpE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@soda-gql/tsc",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.11",
|
|
4
4
|
"description": "TypeScript transformer and compiler plugin for soda-gql",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -62,14 +62,14 @@
|
|
|
62
62
|
"./package.json": "./package.json"
|
|
63
63
|
},
|
|
64
64
|
"dependencies": {
|
|
65
|
-
"@soda-gql/builder": "0.11.
|
|
66
|
-
"@soda-gql/common": "0.11.
|
|
67
|
-
"@soda-gql/config": "0.11.
|
|
68
|
-
"@soda-gql/core": "0.11.
|
|
65
|
+
"@soda-gql/builder": "0.11.11",
|
|
66
|
+
"@soda-gql/common": "0.11.11",
|
|
67
|
+
"@soda-gql/config": "0.11.11",
|
|
68
|
+
"@soda-gql/core": "0.11.11",
|
|
69
69
|
"neverthrow": "^8.1.1"
|
|
70
70
|
},
|
|
71
71
|
"devDependencies": {
|
|
72
|
-
"@soda-gql/codegen": "0.11.
|
|
72
|
+
"@soda-gql/codegen": "0.11.11",
|
|
73
73
|
"prettier": "^3.4.2"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transformer-BE1nwZtg.cjs","names":["ts","newStatements","sourceFile","createCanonicalTracker","ts","bindings: ExportBindingMap","typescript","prebuildProps: Record<string, ts.Expression>","ts","runtimeCallsFromLastTransform: ts.Expression[]"],"sources":["../src/ast/imports.ts","../src/ast/metadata.ts","../src/ast/analysis.ts","../src/ast/ast.ts","../src/ast/runtime.ts","../src/ast/transformer.ts","../src/transformer.ts"],"sourcesContent":["import type { GraphqlSystemIdentifyHelper } from \"@soda-gql/builder\";\nimport ts from \"typescript\";\n\nconst RUNTIME_MODULE = \"@soda-gql/runtime\";\n\n/**\n * Ensure that the gqlRuntime require exists in the source file for CJS output.\n * Injects: const __soda_gql_runtime = require(\"@soda-gql/runtime\");\n * Returns an updated source file with the require added if needed.\n */\nexport const ensureGqlRuntimeRequire = ({\n sourceFile,\n factory,\n}: {\n sourceFile: ts.SourceFile;\n factory: ts.NodeFactory;\n}): ts.SourceFile => {\n // Check if the require already exists\n const existing = sourceFile.statements.find(\n (statement): statement is ts.VariableStatement =>\n ts.isVariableStatement(statement) &&\n statement.declarationList.declarations.some((decl) => {\n if (!ts.isIdentifier(decl.name) || decl.name.text !== \"__soda_gql_runtime\") {\n return false;\n }\n if (!decl.initializer || !ts.isCallExpression(decl.initializer)) {\n return false;\n }\n const callExpr = decl.initializer;\n if (!ts.isIdentifier(callExpr.expression) || callExpr.expression.text !== \"require\") {\n return false;\n }\n const arg = callExpr.arguments[0];\n return arg && ts.isStringLiteral(arg) && arg.text === RUNTIME_MODULE;\n }),\n );\n\n if (existing) {\n return sourceFile;\n }\n\n // Create: const __soda_gql_runtime = require(\"@soda-gql/runtime\");\n const requireCall = factory.createCallExpression(factory.createIdentifier(\"require\"), undefined, [\n factory.createStringLiteral(RUNTIME_MODULE),\n ]);\n\n const variableDeclaration = factory.createVariableDeclaration(\n factory.createIdentifier(\"__soda_gql_runtime\"),\n undefined,\n undefined,\n requireCall,\n );\n\n const variableStatement = factory.createVariableStatement(\n undefined,\n factory.createVariableDeclarationList([variableDeclaration], ts.NodeFlags.Const),\n );\n\n // Insert at the beginning of the file\n const newStatements = [variableStatement, ...sourceFile.statements];\n return factory.updateSourceFile(sourceFile, newStatements);\n};\n\n/**\n * Ensure that the gqlRuntime import exists in the source file.\n * gqlRuntime is always imported from @soda-gql/runtime.\n * Returns an updated source file with the import added or merged.\n */\nexport const ensureGqlRuntimeImport = ({\n sourceFile,\n factory,\n}: {\n sourceFile: ts.SourceFile;\n factory: ts.NodeFactory;\n}): ts.SourceFile => {\n const existing = sourceFile.statements.find(\n (statement): statement is ts.ImportDeclaration =>\n ts.isImportDeclaration(statement) &&\n ts.isStringLiteral(statement.moduleSpecifier) &&\n statement.moduleSpecifier.text === RUNTIME_MODULE,\n );\n\n if (existing?.importClause?.namedBindings && ts.isNamedImports(existing.importClause.namedBindings)) {\n const hasSpecifier = existing.importClause.namedBindings.elements.some(\n (element) => ts.isIdentifier(element.name) && element.name.text === \"gqlRuntime\",\n );\n\n if (hasSpecifier) {\n return sourceFile;\n }\n\n // Add gqlRuntime to existing import\n const newElements = [\n ...existing.importClause.namedBindings.elements,\n factory.createImportSpecifier(false, undefined, factory.createIdentifier(\"gqlRuntime\")),\n ];\n\n const newNamedBindings = factory.createNamedImports(newElements);\n const newImportClause = factory.createImportClause(false, undefined, newNamedBindings);\n const newImportDeclaration = factory.createImportDeclaration(\n undefined,\n newImportClause,\n factory.createStringLiteral(RUNTIME_MODULE),\n undefined,\n );\n\n const newStatements = sourceFile.statements.map((stmt) => (stmt === existing ? newImportDeclaration : stmt));\n return factory.updateSourceFile(sourceFile, newStatements);\n }\n\n // Create new import declaration\n const newImportDeclaration = factory.createImportDeclaration(\n undefined,\n factory.createImportClause(\n false,\n undefined,\n factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier(\"gqlRuntime\"))]),\n ),\n factory.createStringLiteral(RUNTIME_MODULE),\n undefined,\n );\n\n const newStatements = [newImportDeclaration, ...sourceFile.statements];\n return factory.updateSourceFile(sourceFile, newStatements);\n};\n\n/**\n * Remove the graphql-system import (runtimeModule) and gql-related exports from the source file.\n * After transformation, gqlRuntime is imported from @soda-gql/runtime instead,\n * so the original graphql-system import should be completely removed.\n *\n * This handles both ESM imports and CommonJS require() statements (including interop helpers).\n */\nexport const removeGraphqlSystemImports = ({\n sourceFile,\n factory,\n graphqlSystemIdentifyHelper,\n}: {\n sourceFile: ts.SourceFile;\n factory: ts.NodeFactory;\n graphqlSystemIdentifyHelper: GraphqlSystemIdentifyHelper;\n}): ts.SourceFile => {\n // After transformation, all gql usage should be replaced with gqlRuntime\n // So we can safely remove the graphql-system import and all gql-related exports\n const updatedStatements = Array.from(sourceFile.statements).filter((statement) => {\n // Remove ESM import declarations for the runtimeModule\n // - import { gql } from \"@/graphql-system\";\n // - import * as gql from \"@/graphql-system\";\n // - import gql from \"@/graphql-system\";\n // - import { gql as gqlRuntime } from \"@/graphql-system\";\n // - import * as gqlRuntime from \"@/graphql-system\";\n // - import gqlRuntime from \"@/graphql-system\";\n if (ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier)) {\n return !graphqlSystemIdentifyHelper.isGraphqlSystemImportSpecifier({\n filePath: sourceFile.fileName,\n specifier: statement.moduleSpecifier.text,\n });\n }\n\n // Remove CommonJS require() statements for the runtimeModule\n // TypeScript emits these when downleveling ESM to CJS:\n // - const graphql_system_1 = require(\"../../graphql-system\");\n // - const { gql } = require(\"@/graphql-system\");\n // - const foo = __importDefault(require(\"@/graphql-system\"));\n // - const foo = __importStar(require(\"@/graphql-system\"));\n if (ts.isVariableStatement(statement)) {\n return !statement.declarationList.declarations.every((decl) => {\n const specifier = extractRequireTargetSpecifier(decl.initializer);\n if (!specifier) {\n return false;\n }\n\n return graphqlSystemIdentifyHelper.isGraphqlSystemImportSpecifier({\n filePath: sourceFile.fileName,\n specifier: specifier,\n });\n });\n }\n\n return true;\n });\n\n if (updatedStatements.length === sourceFile.statements.length) {\n return sourceFile;\n }\n\n return factory.updateSourceFile(sourceFile, updatedStatements);\n};\n\n/**\n * Create an \"after\" transformer that stubs out require() calls for the runtimeModule.\n * This runs after TypeScript's own transformers (including CommonJS down-leveling),\n * so we can replace `const X = require(\"@/graphql-system\")` with a lightweight stub.\n *\n * This prevents the heavy graphql-system module from being loaded at runtime.\n */\nexport const createAfterStubTransformer = ({\n sourceFile,\n graphqlSystemIdentifyHelper,\n}: {\n sourceFile: ts.SourceFile;\n graphqlSystemIdentifyHelper: GraphqlSystemIdentifyHelper;\n}): ts.TransformerFactory<ts.SourceFile> => {\n return (context) => {\n const factory = context.factory;\n\n const visitor = (node: ts.Node): ts.Node => {\n // Replace variable statements that require the runtimeModule with a stub\n if (ts.isVariableStatement(node)) {\n let transformed = false;\n\n const newDeclarations = node.declarationList.declarations.map((decl) => {\n const specifier = extractRequireTargetSpecifier(decl.initializer);\n if (!specifier) {\n return decl;\n }\n\n const isGraphqlSystemImport = graphqlSystemIdentifyHelper.isGraphqlSystemImportSpecifier({\n filePath: sourceFile.fileName,\n specifier,\n });\n if (!isGraphqlSystemImport) {\n return decl;\n }\n\n // Create stub: const X = /*#__PURE__*/Object.create(null);\n const stub = factory.createCallExpression(\n factory.createPropertyAccessExpression(factory.createIdentifier(\"Object\"), \"create\"),\n undefined,\n [factory.createNull()],\n );\n\n // Add /*#__PURE__*/ comment for tree-shaking\n ts.addSyntheticLeadingComment(stub, ts.SyntaxKind.MultiLineCommentTrivia, \"#__PURE__\", false);\n\n transformed = true;\n\n return factory.updateVariableDeclaration(decl, decl.name, decl.exclamationToken, decl.type, stub);\n });\n\n if (transformed) {\n return factory.updateVariableStatement(\n node,\n node.modifiers,\n factory.updateVariableDeclarationList(node.declarationList, newDeclarations),\n );\n }\n }\n\n return ts.visitEachChild(node, visitor, context);\n };\n\n return (sourceFile) => ts.visitNode(sourceFile, visitor) as ts.SourceFile;\n };\n};\n\n/**\n * Check if an expression is a require() call for the runtimeModule.\n * Handles multiple patterns:\n * - require(\"@/graphql-system\")\n * - __importDefault(require(\"@/graphql-system\"))\n * - __importStar(require(\"@/graphql-system\"))\n */\nconst extractRequireTargetSpecifier = (expr: ts.Expression | undefined): string | undefined => {\n if (!expr) {\n return undefined;\n }\n\n // Direct require(\"@/graphql-system\")\n if (ts.isCallExpression(expr)) {\n if (ts.isIdentifier(expr.expression) && expr.expression.text === \"require\") {\n const arg = expr.arguments[0];\n if (arg && ts.isStringLiteral(arg)) {\n return arg.text;\n }\n }\n\n // __importDefault(require(\"@/graphql-system\")) or __importStar(require(\"@/graphql-system\"))\n if (ts.isIdentifier(expr.expression)) {\n const helperName = expr.expression.text;\n if (helperName === \"__importDefault\" || helperName === \"__importStar\") {\n const arg = expr.arguments[0];\n if (arg && ts.isCallExpression(arg)) {\n if (ts.isIdentifier(arg.expression) && arg.expression.text === \"require\") {\n const requireArg = arg.arguments[0];\n if (requireArg && ts.isStringLiteral(requireArg)) {\n return requireArg.text;\n }\n }\n }\n }\n }\n }\n\n return undefined;\n};\n","import type { GqlDefinitionMetadata } from \"@soda-gql/builder/plugin-support\";\nimport type { CanonicalPathTracker } from \"@soda-gql/common\";\nimport { createCanonicalTracker } from \"@soda-gql/common\";\nimport * as ts from \"typescript\";\n\nexport type GqlDefinitionMetadataMap = WeakMap<ts.CallExpression, GqlDefinitionMetadata>;\n\ntype CanonicalTrackerFactory = typeof createCanonicalTracker;\n\ntype CollectArgs = {\n readonly sourceFile: ts.SourceFile;\n readonly filename: string;\n readonly createTracker?: CanonicalTrackerFactory;\n};\n\ntype ScopeHandle = ReturnType<CanonicalPathTracker[\"enterScope\"]>;\ntype ExportBindingMap = Map<string, string>;\n\nexport const collectGqlDefinitionMetadata = ({ sourceFile, filename, createTracker }: CollectArgs): GqlDefinitionMetadataMap => {\n const exportBindings = collectExportBindings(sourceFile);\n const trackerFactory = createTracker ?? createCanonicalTracker;\n const tracker = trackerFactory({\n filePath: filename,\n getExportName: (localName) => exportBindings.get(localName),\n });\n\n const getAnonymousName = createAnonymousNameFactory();\n const scopeHandles = new WeakMap<ts.Node, ScopeHandle>();\n const metadata = new WeakMap<ts.CallExpression, GqlDefinitionMetadata>();\n\n const visit = (node: ts.Node): void => {\n // Handle GraphQL definition calls\n if (ts.isCallExpression(node) && isGqlDefinitionCall(node, ts)) {\n const depthBeforeRegister = tracker.currentDepth();\n const { astPath } = tracker.registerDefinition();\n const isTopLevel = depthBeforeRegister <= 1;\n const exportInfo = isTopLevel ? resolveTopLevelExport(node, exportBindings, ts) : null;\n\n metadata.set(node, {\n astPath,\n isTopLevel,\n isExported: exportInfo?.isExported ?? false,\n exportBinding: exportInfo?.exportBinding,\n });\n\n // Skip visiting children of gql calls\n return;\n }\n\n // Enter scope if this node creates one\n const handle = maybeEnterScope(node, tracker, getAnonymousName, ts);\n if (handle) {\n scopeHandles.set(node, handle);\n }\n\n // Visit children\n ts.forEachChild(node, visit);\n\n // Exit scope if we entered one\n const scopeHandle = scopeHandles.get(node);\n if (scopeHandle) {\n tracker.exitScope(scopeHandle);\n scopeHandles.delete(node);\n }\n };\n\n visit(sourceFile);\n\n return metadata;\n};\n\nconst collectExportBindings = (sourceFile: ts.SourceFile): ExportBindingMap => {\n const bindings: ExportBindingMap = new Map();\n\n for (const statement of sourceFile.statements) {\n // ESM exports: export const foo = ...\n if (ts.isExportDeclaration(statement) && statement.exportClause && ts.isNamedExports(statement.exportClause)) {\n for (const element of statement.exportClause.elements) {\n const name = element.name.text;\n bindings.set(name, name);\n }\n continue;\n }\n\n // Export variable declaration: export const foo = ...\n if (ts.isVariableStatement(statement) && statement.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)) {\n for (const declaration of statement.declarationList.declarations) {\n if (ts.isIdentifier(declaration.name)) {\n bindings.set(declaration.name.text, declaration.name.text);\n }\n }\n continue;\n }\n\n // Export function/class: export function foo() {} or export class Foo {}\n if (\n (ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement)) &&\n statement.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword) &&\n statement.name\n ) {\n bindings.set(statement.name.text, statement.name.text);\n continue;\n }\n\n // CommonJS exports: exports.foo = ... or module.exports.foo = ...\n if (ts.isExpressionStatement(statement) && ts.isBinaryExpression(statement.expression)) {\n const exportName = getCommonJsExportName(statement.expression.left);\n if (exportName) {\n bindings.set(exportName, exportName);\n }\n }\n }\n\n return bindings;\n};\n\nconst getCommonJsExportName = (node: ts.Node): string | null => {\n if (!ts.isPropertyAccessExpression(node)) {\n return null;\n }\n\n // Check if it's exports.foo or module.exports.foo\n const isExports = ts.isIdentifier(node.expression) && node.expression.text === \"exports\";\n const isModuleExports =\n ts.isPropertyAccessExpression(node.expression) &&\n ts.isIdentifier(node.expression.expression) &&\n node.expression.expression.text === \"module\" &&\n ts.isIdentifier(node.expression.name) &&\n node.expression.name.text === \"exports\";\n\n if (!isExports && !isModuleExports) {\n return null;\n }\n\n // Extract property name\n if (ts.isIdentifier(node.name)) {\n return node.name.text;\n }\n\n return null;\n};\n\nconst createAnonymousNameFactory = (): ((kind: string) => string) => {\n const counters = new Map<string, number>();\n return (kind) => {\n const count = counters.get(kind) ?? 0;\n counters.set(kind, count + 1);\n return `${kind}#${count}`;\n };\n};\n\nconst isGqlDefinitionCall = (node: ts.Node, typescript: typeof ts): node is ts.CallExpression => {\n if (!typescript.isCallExpression(node)) {\n return false;\n }\n if (!typescript.isPropertyAccessExpression(node.expression)) {\n return false;\n }\n if (!isGqlReference(node.expression.expression, typescript)) {\n return false;\n }\n if (node.arguments.length === 0) {\n return false;\n }\n const firstArg = node.arguments[0];\n if (firstArg === undefined) {\n return false;\n }\n return typescript.isArrowFunction(firstArg);\n};\n\nconst isGqlReference = (expr: ts.Expression, typescript: typeof ts): boolean => {\n if (typescript.isIdentifier(expr) && expr.text === \"gql\") {\n return true;\n }\n if (!typescript.isPropertyAccessExpression(expr)) {\n return false;\n }\n if (typescript.isIdentifier(expr.name) && expr.name.text === \"gql\") {\n return true;\n }\n return isGqlReference(expr.expression, typescript);\n};\n\nconst resolveTopLevelExport = (\n callNode: ts.CallExpression,\n exportBindings: ExportBindingMap,\n typescript: typeof ts,\n): { readonly isExported: true; readonly exportBinding: string } | null => {\n // ESM: const foo = gql.default(...); export { foo };\n const parent = callNode.parent;\n if (!parent) {\n return null;\n }\n\n if (typescript.isVariableDeclaration(parent)) {\n const { name } = parent;\n if (typescript.isIdentifier(name)) {\n const exportBinding = exportBindings.get(name.text);\n if (exportBinding) {\n return { isExported: true, exportBinding };\n }\n }\n }\n\n // CommonJS: exports.foo = gql.default(...);\n if (typescript.isBinaryExpression(parent)) {\n const exportName = getCommonJsExportName(parent.left);\n if (exportName && exportBindings.has(exportName)) {\n return { isExported: true, exportBinding: exportName };\n }\n }\n\n return null;\n};\n\nconst maybeEnterScope = (\n node: ts.Node,\n tracker: CanonicalPathTracker,\n getAnonymousName: (kind: string) => string,\n typescript: typeof ts,\n): ScopeHandle | null => {\n // CommonJS exports: exports.foo = ... or module.exports.foo = ...\n if (typescript.isBinaryExpression(node)) {\n const exportName = getCommonJsExportName(node.left);\n if (exportName) {\n return tracker.enterScope({ segment: exportName, kind: \"variable\", stableKey: `var:${exportName}` });\n }\n }\n\n if (typescript.isVariableDeclaration(node) && typescript.isIdentifier(node.name)) {\n const name = node.name.text;\n return tracker.enterScope({ segment: name, kind: \"variable\", stableKey: `var:${name}` });\n }\n\n if (typescript.isArrowFunction(node)) {\n const name = getAnonymousName(\"arrow\");\n return tracker.enterScope({ segment: name, kind: \"function\", stableKey: \"arrow\" });\n }\n\n if (typescript.isFunctionDeclaration(node) || typescript.isFunctionExpression(node)) {\n const explicitName = node.name?.text;\n const name = explicitName ?? getAnonymousName(\"function\");\n return tracker.enterScope({ segment: name, kind: \"function\", stableKey: `func:${name}` });\n }\n\n if (typescript.isClassDeclaration(node)) {\n const explicitName = node.name?.text;\n const name = explicitName ?? getAnonymousName(\"class\");\n return tracker.enterScope({ segment: name, kind: \"class\", stableKey: `class:${name}` });\n }\n\n if (typescript.isMethodDeclaration(node) && typescript.isIdentifier(node.name)) {\n const name = node.name.text;\n return tracker.enterScope({ segment: name, kind: \"method\", stableKey: `member:${name}` });\n }\n\n if (typescript.isPropertyDeclaration(node) && typescript.isIdentifier(node.name)) {\n const name = node.name.text;\n return tracker.enterScope({ segment: name, kind: \"property\", stableKey: `member:${name}` });\n }\n\n if (typescript.isPropertyAssignment(node)) {\n const key = node.name;\n const name = typescript.isIdentifier(key) ? key.text : typescript.isStringLiteral(key) ? key.text : null;\n if (name) {\n return tracker.enterScope({ segment: name, kind: \"property\", stableKey: `prop:${name}` });\n }\n }\n\n return null;\n};\n","import type { BuilderArtifactElement } from \"@soda-gql/builder\";\nimport type {\n GqlCallFragment,\n GqlCallOperation,\n PluginAnalysisArtifactMissingError,\n PluginAnalysisMetadataMissingError,\n PluginAnalysisUnsupportedArtifactTypeError,\n PluginError,\n} from \"@soda-gql/builder/plugin-support\";\nimport { resolveCanonicalId } from \"@soda-gql/builder/plugin-support\";\nimport type { CanonicalId } from \"@soda-gql/common\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport type * as ts from \"typescript\";\nimport type { GqlDefinitionMetadataMap } from \"./metadata\";\n\nexport type ArtifactLookup = (canonicalId: CanonicalId) => BuilderArtifactElement | undefined;\n\n// TypeScript-specific GqlCall types\nexport type TsGqlCallFragment = GqlCallFragment & { readonly callNode: ts.CallExpression };\nexport type TsGqlCallOperation = GqlCallOperation & { readonly callNode: ts.CallExpression };\n\nexport type TsGqlCall = TsGqlCallFragment | TsGqlCallOperation;\n\nexport type ExtractGqlCallArgs = {\n readonly callNode: ts.CallExpression;\n readonly filename: string;\n readonly metadata: GqlDefinitionMetadataMap;\n readonly getArtifact: ArtifactLookup;\n};\n\nexport const extractGqlCall = ({\n callNode,\n filename,\n metadata,\n getArtifact,\n}: ExtractGqlCallArgs): Result<TsGqlCall, PluginError> => {\n const meta = metadata.get(callNode);\n if (!meta) {\n return err(createMetadataMissingError({ filename }));\n }\n\n const canonicalId = resolveCanonicalId(filename, meta.astPath);\n const artifact = getArtifact(canonicalId);\n\n if (!artifact) {\n return err(createArtifactMissingError({ filename, canonicalId }));\n }\n\n if (artifact.type === \"fragment\") {\n return ok({ callNode, canonicalId, type: \"fragment\", artifact });\n }\n\n if (artifact.type === \"operation\") {\n return ok({ callNode, canonicalId, type: \"operation\", artifact });\n }\n\n return err(\n createUnsupportedArtifactTypeError({\n filename,\n canonicalId,\n artifactType: (artifact as { type: string }).type,\n }),\n );\n};\n\ntype MetadataErrorInput = { readonly filename: string };\ntype ArtifactMissingErrorInput = { readonly filename: string; readonly canonicalId: CanonicalId };\ntype UnsupportedArtifactTypeInput = {\n readonly filename: string;\n readonly canonicalId: CanonicalId;\n readonly artifactType: string;\n};\n\nconst createMetadataMissingError = ({ filename }: MetadataErrorInput): PluginAnalysisMetadataMissingError => ({\n type: \"PluginError\",\n stage: \"analysis\",\n code: \"SODA_GQL_METADATA_NOT_FOUND\",\n message: `No GraphQL metadata found for ${filename}`,\n cause: { filename },\n filename,\n});\n\nconst createArtifactMissingError = ({\n filename,\n canonicalId,\n}: ArtifactMissingErrorInput): PluginAnalysisArtifactMissingError => ({\n type: \"PluginError\",\n stage: \"analysis\",\n code: \"SODA_GQL_ANALYSIS_ARTIFACT_NOT_FOUND\",\n message: `No builder artifact found for canonical ID ${canonicalId}`,\n cause: { filename, canonicalId },\n filename,\n canonicalId,\n});\n\nconst createUnsupportedArtifactTypeError = ({\n filename,\n canonicalId,\n artifactType,\n}: UnsupportedArtifactTypeInput): PluginAnalysisUnsupportedArtifactTypeError => ({\n type: \"PluginError\",\n stage: \"analysis\",\n code: \"SODA_GQL_UNSUPPORTED_ARTIFACT_TYPE\",\n message: `Unsupported builder artifact type \"${artifactType}\" for canonical ID ${canonicalId}`,\n cause: { filename, canonicalId, artifactType },\n filename,\n canonicalId,\n artifactType,\n});\n","import type { PluginError, PluginTransformUnsupportedValueTypeError } from \"@soda-gql/builder/plugin-support\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport * as ts from \"typescript\";\n\nconst createUnsupportedValueTypeError = (valueType: string): PluginTransformUnsupportedValueTypeError => ({\n type: \"PluginError\",\n stage: \"transform\",\n code: \"SODA_GQL_TRANSFORM_UNSUPPORTED_VALUE_TYPE\",\n message: `Unsupported value type: ${valueType}`,\n cause: { valueType },\n valueType,\n});\n\n/**\n * Build a literal expression from a primitive value.\n * Mirrors Babel's buildLiteralFromValue.\n */\nexport const buildLiteralFromValue = (factory: ts.NodeFactory, value: unknown): Result<ts.Expression, PluginError> => {\n if (value === null) {\n return ok(factory.createNull());\n }\n if (typeof value === \"string\") {\n return ok(factory.createStringLiteral(value));\n }\n if (typeof value === \"number\") {\n return ok(factory.createNumericLiteral(value));\n }\n if (typeof value === \"boolean\") {\n return ok(value ? factory.createTrue() : factory.createFalse());\n }\n if (Array.isArray(value)) {\n const elements: ts.Expression[] = [];\n for (const item of value) {\n const result = buildLiteralFromValue(factory, item);\n if (result.isErr()) {\n return result;\n }\n elements.push(result.value);\n }\n return ok(factory.createArrayLiteralExpression(elements));\n }\n if (typeof value === \"object\") {\n const properties: ts.PropertyAssignment[] = [];\n for (const [key, val] of Object.entries(value)) {\n const result = buildLiteralFromValue(factory, val);\n if (result.isErr()) {\n return result;\n }\n properties.push(factory.createPropertyAssignment(factory.createIdentifier(key), result.value));\n }\n return ok(factory.createObjectLiteralExpression(properties));\n }\n return err(createUnsupportedValueTypeError(typeof value));\n};\n\n/**\n * Clone a TypeScript node deeply.\n * TypeScript nodes are immutable, so we need to use visitEachChild for deep cloning.\n */\nexport const clone = <T extends ts.Node>(node: T): T => {\n const cloneVisitor = (n: ts.Node): ts.Node => ts.visitEachChild(n, cloneVisitor, undefined);\n return cloneVisitor(node) as T;\n};\n\n/**\n * Build an object literal expression from a record of properties.\n */\nexport const buildObjectExpression = <K extends string>(\n factory: ts.NodeFactory,\n properties: Record<K, ts.Expression>,\n): ts.ObjectLiteralExpression => {\n const propertyAssignments = Object.entries<ts.Expression>(properties).map(([key, value]) =>\n factory.createPropertyAssignment(factory.createIdentifier(key), value),\n );\n return factory.createObjectLiteralExpression(propertyAssignments);\n};\n\n/**\n * Build a JSON.parse expression from an object value.\n * This is used to emit large objects as JSON strings to reduce the calculation cost of both the compiler and the runtime.\n */\nexport const buildJsonParseExpression = <T extends object>(factory: ts.NodeFactory, value: T): ts.Expression =>\n factory.createCallExpression(\n factory.createPropertyAccessExpression(factory.createIdentifier(\"JSON\"), factory.createIdentifier(\"parse\")),\n undefined,\n [factory.createStringLiteral(JSON.stringify(value))],\n );\n","import type { PluginError } from \"@soda-gql/builder/plugin-support\";\nimport type { RuntimeOperationInput } from \"@soda-gql/core/runtime\";\nimport { ok, type Result } from \"neverthrow\";\nimport type * as ts from \"typescript\";\nimport type { TsGqlCallFragment, TsGqlCallOperation } from \"./analysis\";\nimport { buildJsonParseExpression, buildObjectExpression } from \"./ast\";\n\nconst createRuntimeAccessor = ({ isCJS, factory }: { isCJS: boolean; factory: ts.NodeFactory }) =>\n isCJS\n ? factory.createPropertyAccessExpression(\n factory.createIdentifier(\"__soda_gql_runtime\"),\n factory.createIdentifier(\"gqlRuntime\"),\n )\n : factory.createIdentifier(\"gqlRuntime\");\n\nexport const buildFragmentRuntimeCall = ({\n gqlCall,\n factory,\n isCJS,\n}: {\n gqlCall: TsGqlCallFragment;\n factory: ts.NodeFactory;\n isCJS: boolean;\n filename: string;\n}): Result<ts.Expression, PluginError> => {\n const prebuildProps: Record<string, ts.Expression> = {\n typename: factory.createStringLiteral(gqlCall.artifact.prebuild.typename),\n };\n if (gqlCall.artifact.prebuild.key !== undefined) {\n prebuildProps.key = factory.createStringLiteral(gqlCall.artifact.prebuild.key);\n }\n\n return ok(\n factory.createCallExpression(\n factory.createPropertyAccessExpression(createRuntimeAccessor({ isCJS, factory }), factory.createIdentifier(\"fragment\")),\n undefined,\n [\n buildObjectExpression(factory, {\n prebuild: buildObjectExpression(factory, prebuildProps),\n }),\n ],\n ),\n );\n};\n\nexport const buildOperationRuntimeComponents = ({\n gqlCall,\n factory,\n isCJS,\n}: {\n gqlCall: TsGqlCallOperation;\n factory: ts.NodeFactory;\n isCJS: boolean;\n}): Result<{ referenceCall: ts.Expression; runtimeCall: ts.Expression }, PluginError> => {\n const runtimeCall = factory.createCallExpression(\n factory.createPropertyAccessExpression(createRuntimeAccessor({ isCJS, factory }), factory.createIdentifier(\"operation\")),\n undefined,\n [\n buildObjectExpression(factory, {\n prebuild: buildJsonParseExpression<RuntimeOperationInput[\"prebuild\"]>(factory, gqlCall.artifact.prebuild),\n runtime: buildObjectExpression(factory, {}),\n }),\n ],\n );\n\n const referenceCall = factory.createCallExpression(\n factory.createPropertyAccessExpression(createRuntimeAccessor({ isCJS, factory }), factory.createIdentifier(\"getOperation\")),\n undefined,\n [factory.createStringLiteral(gqlCall.artifact.prebuild.operationName)],\n );\n\n return ok({\n referenceCall,\n runtimeCall,\n });\n};\n","import type { PluginError } from \"@soda-gql/builder/plugin-support\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport type * as ts from \"typescript\";\nimport type { ArtifactLookup, TsGqlCall } from \"./analysis\";\nimport { extractGqlCall } from \"./analysis\";\nimport type { GqlDefinitionMetadataMap } from \"./metadata\";\nimport { buildFragmentRuntimeCall, buildOperationRuntimeComponents } from \"./runtime\";\n\ntype TransformCallExpressionArgs = {\n readonly callNode: ts.CallExpression;\n readonly filename: string;\n readonly metadata: GqlDefinitionMetadataMap;\n readonly getArtifact: ArtifactLookup;\n readonly factory: ts.NodeFactory;\n readonly isCJS: boolean;\n};\n\ntype TransformCallExpressionResult =\n | { readonly transformed: false }\n | { readonly transformed: true; readonly replacement: ts.Expression; readonly runtimeCall?: ts.Expression };\n\nexport const transformCallExpression = ({\n callNode,\n filename,\n metadata,\n getArtifact,\n factory,\n isCJS,\n}: TransformCallExpressionArgs): Result<TransformCallExpressionResult, PluginError> => {\n // Skip if this call doesn't have GQL metadata\n if (!metadata.has(callNode)) {\n return ok({ transformed: false });\n }\n\n const gqlCallResult = extractGqlCall({\n callNode,\n filename,\n metadata,\n getArtifact,\n });\n\n if (gqlCallResult.isErr()) {\n return err(gqlCallResult.error);\n }\n\n const gqlCall = gqlCallResult.value;\n\n return replaceWithRuntimeCall({ gqlCall, factory, isCJS, filename });\n};\n\nconst replaceWithRuntimeCall = ({\n gqlCall,\n factory,\n isCJS,\n filename,\n}: {\n gqlCall: TsGqlCall;\n factory: ts.NodeFactory;\n isCJS: boolean;\n filename: string;\n}): Result<TransformCallExpressionResult, PluginError> => {\n if (gqlCall.type === \"fragment\") {\n const result = buildFragmentRuntimeCall({ gqlCall, factory, isCJS, filename });\n if (result.isErr()) {\n return err(result.error);\n }\n return ok({ transformed: true, replacement: result.value as ts.Expression });\n }\n\n if (gqlCall.type === \"operation\") {\n const result = buildOperationRuntimeComponents({ gqlCall, factory, isCJS });\n if (result.isErr()) {\n return err(result.error);\n }\n const { referenceCall, runtimeCall } = result.value;\n return ok({ transformed: true, replacement: referenceCall, runtimeCall });\n }\n\n return ok({ transformed: false });\n};\n","/**\n * TypeScript implementation of the TransformAdapter interface.\n */\n\nimport type { BuilderArtifact } from \"@soda-gql/builder\";\nimport { createGraphqlSystemIdentifyHelper } from \"@soda-gql/builder\";\nimport { formatPluginError } from \"@soda-gql/builder/plugin-support\";\nimport type { CanonicalId } from \"@soda-gql/common\";\nimport type { ResolvedSodaGqlConfig } from \"@soda-gql/config\";\nimport * as ts from \"typescript\";\nimport { ensureGqlRuntimeImport, ensureGqlRuntimeRequire, removeGraphqlSystemImports } from \"./ast/imports\";\nimport { collectGqlDefinitionMetadata } from \"./ast/metadata\";\nimport { transformCallExpression } from \"./ast/transformer\";\n\nexport { createAfterStubTransformer } from \"./ast/imports\";\n\n/**\n * TypeScript-specific environment required for the adapter.\n */\nexport type TypeScriptEnv = {\n readonly sourceFile: ts.SourceFile;\n readonly context: ts.TransformationContext;\n};\n\nconst findLastImportIndex = ({ sourceFile }: { sourceFile: ts.SourceFile }): number => {\n let lastIndex = -1;\n const statements = sourceFile.statements;\n\n for (let i = 0; i < statements.length; i++) {\n const statement = statements[i];\n if (statement && ts.isImportDeclaration(statement)) {\n lastIndex = i;\n }\n }\n\n return lastIndex;\n};\n\nexport const createTransformer = ({\n compilerOptions,\n config,\n artifact,\n}: {\n readonly compilerOptions: ts.CompilerOptions;\n readonly config: ResolvedSodaGqlConfig;\n readonly artifact: BuilderArtifact;\n}) => {\n const isCJS = compilerOptions.module === ts.ModuleKind.CommonJS || compilerOptions.target === ts.ScriptTarget.ES5;\n\n // Create graphql system identify helper using builder's implementation\n const graphqlSystemIdentifyHelper = createGraphqlSystemIdentifyHelper(config);\n\n const makeSourceFileEmpty = ({ factory, sourceFile }: { factory: ts.NodeFactory; sourceFile: ts.SourceFile }) => {\n return factory.updateSourceFile(sourceFile, [\n factory.createExportDeclaration(undefined, false, factory.createNamedExports([]), undefined),\n ]);\n };\n\n const transformGqlCalls = ({ sourceFile, context }: { sourceFile: ts.SourceFile; context: ts.TransformationContext }) => {\n let transformed = false;\n\n const metadata = collectGqlDefinitionMetadata({\n sourceFile,\n filename: sourceFile.fileName,\n });\n\n const runtimeCallsFromLastTransform: ts.Expression[] = [];\n const visitor = (node: ts.Node): ts.Node => {\n if (ts.isCallExpression(node)) {\n const result = transformCallExpression({\n callNode: node,\n filename: sourceFile.fileName,\n metadata,\n getArtifact: (canonicalId: CanonicalId) => artifact.elements[canonicalId],\n factory: context.factory,\n isCJS,\n });\n\n if (result.isErr()) {\n // Log error and continue - don't fail the entire build for a single error\n console.error(`[@soda-gql/tsc] ${formatPluginError(result.error)}`);\n return node;\n }\n\n const transformResult = result.value;\n if (transformResult.transformed) {\n transformed = true;\n\n if (transformResult.runtimeCall) {\n runtimeCallsFromLastTransform.push(transformResult.runtimeCall);\n }\n\n return transformResult.replacement;\n }\n }\n\n return ts.visitEachChild(node, visitor, context);\n };\n\n const visitedNode = ts.visitNode(sourceFile, visitor);\n if (!visitedNode || !ts.isSourceFile(visitedNode)) {\n console.error(`[@soda-gql/tsc] Failed to transform source file: ${sourceFile.fileName}`);\n return sourceFile;\n }\n\n if (!transformed) {\n return sourceFile;\n }\n\n if (runtimeCallsFromLastTransform.length === 0) {\n return visitedNode;\n }\n\n const lastImportIndex = findLastImportIndex({ sourceFile });\n\n return context.factory.updateSourceFile(visitedNode, [\n ...visitedNode.statements.slice(0, lastImportIndex + 1),\n ...runtimeCallsFromLastTransform.map((expr) => context.factory.createExpressionStatement(expr)),\n ...visitedNode.statements.slice(lastImportIndex + 1),\n ]);\n };\n\n return {\n transform: ({ sourceFile, context }: { sourceFile: ts.SourceFile; context: ts.TransformationContext }) => {\n // Stub internal modules (graphql-system and inject files)\n // These modules are only needed at build time and should be empty at runtime\n if (graphqlSystemIdentifyHelper.isInternalModuleFile({ filePath: sourceFile.fileName })) {\n const transformedSourceFile = makeSourceFileEmpty({ factory: context.factory, sourceFile: sourceFile });\n return { transformed: true, sourceFile: transformedSourceFile };\n }\n\n const original = sourceFile;\n let current = sourceFile;\n current = transformGqlCalls({ sourceFile: current, context });\n\n if (current !== sourceFile) {\n current = isCJS\n ? ensureGqlRuntimeRequire({ sourceFile: current, factory: context.factory })\n : ensureGqlRuntimeImport({ sourceFile: current, factory: context.factory });\n }\n\n current = removeGraphqlSystemImports({\n sourceFile: current,\n factory: context.factory,\n graphqlSystemIdentifyHelper,\n });\n\n return { transformed: current !== original, sourceFile: current };\n },\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA,MAAM,iBAAiB;;;;;;AAOvB,MAAa,2BAA2B,EACtC,YACA,cA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AcA,WAAG,UAAU,YAAY,QAAQ;AACrD,MAAI,CAAC,eAAe,CAACA,WAAG,aAAa,YAAY,EAAE;AACjD,WAAQ,MAAM,oDAAoD,WAAW,WAAW;AACxF,UAAO;;AAGT,MAAI,CAAC,YACH,QAAO;AAGT,MAAI,8BAA8B,WAAW,EAC3C,QAAO;EAGT,MAAM,kBAAkB,oBAAoB,EAAE,YAAY,CAAC;AAE3D,SAAO,QAAQ,QAAQ,iBAAiB,aAAa;GACnD,GAAG,YAAY,WAAW,MAAM,GAAG,kBAAkB,EAAE;GACvD,GAAG,8BAA8B,KAAK,SAAS,QAAQ,QAAQ,0BAA0B,KAAK,CAAC;GAC/F,GAAG,YAAY,WAAW,MAAM,kBAAkB,EAAE;GACrD,CAAC;;AAGJ,QAAO,EACL,YAAY,EAAE,YAAY,cAAgF;AAGxG,MAAI,4BAA4B,qBAAqB,EAAE,UAAU,WAAW,UAAU,CAAC,CAErF,QAAO;GAAE,aAAa;GAAM,YADE,oBAAoB;IAAE,SAAS,QAAQ;IAAqB;IAAY,CAAC;GACxC;EAGjE,MAAM,WAAW;EACjB,IAAI,UAAU;AACd,YAAU,kBAAkB;GAAE,YAAY;GAAS;GAAS,CAAC;AAE7D,MAAI,YAAY,WACd,WAAU,QACN,wBAAwB;GAAE,YAAY;GAAS,SAAS,QAAQ;GAAS,CAAC,GAC1E,uBAAuB;GAAE,YAAY;GAAS,SAAS,QAAQ;GAAS,CAAC;AAG/E,YAAU,2BAA2B;GACnC,YAAY;GACZ,SAAS,QAAQ;GACjB;GACD,CAAC;AAEF,SAAO;GAAE,aAAa,YAAY;GAAU,YAAY;GAAS;IAEpE"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"transformer-Dk0Nnpg_.mjs","names":["newStatements","sourceFile","ts","bindings: ExportBindingMap","prebuildProps: Record<string, ts.Expression>","ts","runtimeCallsFromLastTransform: ts.Expression[]"],"sources":["../src/ast/imports.ts","../src/ast/metadata.ts","../src/ast/analysis.ts","../src/ast/ast.ts","../src/ast/runtime.ts","../src/ast/transformer.ts","../src/transformer.ts"],"sourcesContent":["import type { GraphqlSystemIdentifyHelper } from \"@soda-gql/builder\";\nimport ts from \"typescript\";\n\nconst RUNTIME_MODULE = \"@soda-gql/runtime\";\n\n/**\n * Ensure that the gqlRuntime require exists in the source file for CJS output.\n * Injects: const __soda_gql_runtime = require(\"@soda-gql/runtime\");\n * Returns an updated source file with the require added if needed.\n */\nexport const ensureGqlRuntimeRequire = ({\n sourceFile,\n factory,\n}: {\n sourceFile: ts.SourceFile;\n factory: ts.NodeFactory;\n}): ts.SourceFile => {\n // Check if the require already exists\n const existing = sourceFile.statements.find(\n (statement): statement is ts.VariableStatement =>\n ts.isVariableStatement(statement) &&\n statement.declarationList.declarations.some((decl) => {\n if (!ts.isIdentifier(decl.name) || decl.name.text !== \"__soda_gql_runtime\") {\n return false;\n }\n if (!decl.initializer || !ts.isCallExpression(decl.initializer)) {\n return false;\n }\n const callExpr = decl.initializer;\n if (!ts.isIdentifier(callExpr.expression) || callExpr.expression.text !== \"require\") {\n return false;\n }\n const arg = callExpr.arguments[0];\n return arg && ts.isStringLiteral(arg) && arg.text === RUNTIME_MODULE;\n }),\n );\n\n if (existing) {\n return sourceFile;\n }\n\n // Create: const __soda_gql_runtime = require(\"@soda-gql/runtime\");\n const requireCall = factory.createCallExpression(factory.createIdentifier(\"require\"), undefined, [\n factory.createStringLiteral(RUNTIME_MODULE),\n ]);\n\n const variableDeclaration = factory.createVariableDeclaration(\n factory.createIdentifier(\"__soda_gql_runtime\"),\n undefined,\n undefined,\n requireCall,\n );\n\n const variableStatement = factory.createVariableStatement(\n undefined,\n factory.createVariableDeclarationList([variableDeclaration], ts.NodeFlags.Const),\n );\n\n // Insert at the beginning of the file\n const newStatements = [variableStatement, ...sourceFile.statements];\n return factory.updateSourceFile(sourceFile, newStatements);\n};\n\n/**\n * Ensure that the gqlRuntime import exists in the source file.\n * gqlRuntime is always imported from @soda-gql/runtime.\n * Returns an updated source file with the import added or merged.\n */\nexport const ensureGqlRuntimeImport = ({\n sourceFile,\n factory,\n}: {\n sourceFile: ts.SourceFile;\n factory: ts.NodeFactory;\n}): ts.SourceFile => {\n const existing = sourceFile.statements.find(\n (statement): statement is ts.ImportDeclaration =>\n ts.isImportDeclaration(statement) &&\n ts.isStringLiteral(statement.moduleSpecifier) &&\n statement.moduleSpecifier.text === RUNTIME_MODULE,\n );\n\n if (existing?.importClause?.namedBindings && ts.isNamedImports(existing.importClause.namedBindings)) {\n const hasSpecifier = existing.importClause.namedBindings.elements.some(\n (element) => ts.isIdentifier(element.name) && element.name.text === \"gqlRuntime\",\n );\n\n if (hasSpecifier) {\n return sourceFile;\n }\n\n // Add gqlRuntime to existing import\n const newElements = [\n ...existing.importClause.namedBindings.elements,\n factory.createImportSpecifier(false, undefined, factory.createIdentifier(\"gqlRuntime\")),\n ];\n\n const newNamedBindings = factory.createNamedImports(newElements);\n const newImportClause = factory.createImportClause(false, undefined, newNamedBindings);\n const newImportDeclaration = factory.createImportDeclaration(\n undefined,\n newImportClause,\n factory.createStringLiteral(RUNTIME_MODULE),\n undefined,\n );\n\n const newStatements = sourceFile.statements.map((stmt) => (stmt === existing ? newImportDeclaration : stmt));\n return factory.updateSourceFile(sourceFile, newStatements);\n }\n\n // Create new import declaration\n const newImportDeclaration = factory.createImportDeclaration(\n undefined,\n factory.createImportClause(\n false,\n undefined,\n factory.createNamedImports([factory.createImportSpecifier(false, undefined, factory.createIdentifier(\"gqlRuntime\"))]),\n ),\n factory.createStringLiteral(RUNTIME_MODULE),\n undefined,\n );\n\n const newStatements = [newImportDeclaration, ...sourceFile.statements];\n return factory.updateSourceFile(sourceFile, newStatements);\n};\n\n/**\n * Remove the graphql-system import (runtimeModule) and gql-related exports from the source file.\n * After transformation, gqlRuntime is imported from @soda-gql/runtime instead,\n * so the original graphql-system import should be completely removed.\n *\n * This handles both ESM imports and CommonJS require() statements (including interop helpers).\n */\nexport const removeGraphqlSystemImports = ({\n sourceFile,\n factory,\n graphqlSystemIdentifyHelper,\n}: {\n sourceFile: ts.SourceFile;\n factory: ts.NodeFactory;\n graphqlSystemIdentifyHelper: GraphqlSystemIdentifyHelper;\n}): ts.SourceFile => {\n // After transformation, all gql usage should be replaced with gqlRuntime\n // So we can safely remove the graphql-system import and all gql-related exports\n const updatedStatements = Array.from(sourceFile.statements).filter((statement) => {\n // Remove ESM import declarations for the runtimeModule\n // - import { gql } from \"@/graphql-system\";\n // - import * as gql from \"@/graphql-system\";\n // - import gql from \"@/graphql-system\";\n // - import { gql as gqlRuntime } from \"@/graphql-system\";\n // - import * as gqlRuntime from \"@/graphql-system\";\n // - import gqlRuntime from \"@/graphql-system\";\n if (ts.isImportDeclaration(statement) && ts.isStringLiteral(statement.moduleSpecifier)) {\n return !graphqlSystemIdentifyHelper.isGraphqlSystemImportSpecifier({\n filePath: sourceFile.fileName,\n specifier: statement.moduleSpecifier.text,\n });\n }\n\n // Remove CommonJS require() statements for the runtimeModule\n // TypeScript emits these when downleveling ESM to CJS:\n // - const graphql_system_1 = require(\"../../graphql-system\");\n // - const { gql } = require(\"@/graphql-system\");\n // - const foo = __importDefault(require(\"@/graphql-system\"));\n // - const foo = __importStar(require(\"@/graphql-system\"));\n if (ts.isVariableStatement(statement)) {\n return !statement.declarationList.declarations.every((decl) => {\n const specifier = extractRequireTargetSpecifier(decl.initializer);\n if (!specifier) {\n return false;\n }\n\n return graphqlSystemIdentifyHelper.isGraphqlSystemImportSpecifier({\n filePath: sourceFile.fileName,\n specifier: specifier,\n });\n });\n }\n\n return true;\n });\n\n if (updatedStatements.length === sourceFile.statements.length) {\n return sourceFile;\n }\n\n return factory.updateSourceFile(sourceFile, updatedStatements);\n};\n\n/**\n * Create an \"after\" transformer that stubs out require() calls for the runtimeModule.\n * This runs after TypeScript's own transformers (including CommonJS down-leveling),\n * so we can replace `const X = require(\"@/graphql-system\")` with a lightweight stub.\n *\n * This prevents the heavy graphql-system module from being loaded at runtime.\n */\nexport const createAfterStubTransformer = ({\n sourceFile,\n graphqlSystemIdentifyHelper,\n}: {\n sourceFile: ts.SourceFile;\n graphqlSystemIdentifyHelper: GraphqlSystemIdentifyHelper;\n}): ts.TransformerFactory<ts.SourceFile> => {\n return (context) => {\n const factory = context.factory;\n\n const visitor = (node: ts.Node): ts.Node => {\n // Replace variable statements that require the runtimeModule with a stub\n if (ts.isVariableStatement(node)) {\n let transformed = false;\n\n const newDeclarations = node.declarationList.declarations.map((decl) => {\n const specifier = extractRequireTargetSpecifier(decl.initializer);\n if (!specifier) {\n return decl;\n }\n\n const isGraphqlSystemImport = graphqlSystemIdentifyHelper.isGraphqlSystemImportSpecifier({\n filePath: sourceFile.fileName,\n specifier,\n });\n if (!isGraphqlSystemImport) {\n return decl;\n }\n\n // Create stub: const X = /*#__PURE__*/Object.create(null);\n const stub = factory.createCallExpression(\n factory.createPropertyAccessExpression(factory.createIdentifier(\"Object\"), \"create\"),\n undefined,\n [factory.createNull()],\n );\n\n // Add /*#__PURE__*/ comment for tree-shaking\n ts.addSyntheticLeadingComment(stub, ts.SyntaxKind.MultiLineCommentTrivia, \"#__PURE__\", false);\n\n transformed = true;\n\n return factory.updateVariableDeclaration(decl, decl.name, decl.exclamationToken, decl.type, stub);\n });\n\n if (transformed) {\n return factory.updateVariableStatement(\n node,\n node.modifiers,\n factory.updateVariableDeclarationList(node.declarationList, newDeclarations),\n );\n }\n }\n\n return ts.visitEachChild(node, visitor, context);\n };\n\n return (sourceFile) => ts.visitNode(sourceFile, visitor) as ts.SourceFile;\n };\n};\n\n/**\n * Check if an expression is a require() call for the runtimeModule.\n * Handles multiple patterns:\n * - require(\"@/graphql-system\")\n * - __importDefault(require(\"@/graphql-system\"))\n * - __importStar(require(\"@/graphql-system\"))\n */\nconst extractRequireTargetSpecifier = (expr: ts.Expression | undefined): string | undefined => {\n if (!expr) {\n return undefined;\n }\n\n // Direct require(\"@/graphql-system\")\n if (ts.isCallExpression(expr)) {\n if (ts.isIdentifier(expr.expression) && expr.expression.text === \"require\") {\n const arg = expr.arguments[0];\n if (arg && ts.isStringLiteral(arg)) {\n return arg.text;\n }\n }\n\n // __importDefault(require(\"@/graphql-system\")) or __importStar(require(\"@/graphql-system\"))\n if (ts.isIdentifier(expr.expression)) {\n const helperName = expr.expression.text;\n if (helperName === \"__importDefault\" || helperName === \"__importStar\") {\n const arg = expr.arguments[0];\n if (arg && ts.isCallExpression(arg)) {\n if (ts.isIdentifier(arg.expression) && arg.expression.text === \"require\") {\n const requireArg = arg.arguments[0];\n if (requireArg && ts.isStringLiteral(requireArg)) {\n return requireArg.text;\n }\n }\n }\n }\n }\n }\n\n return undefined;\n};\n","import type { GqlDefinitionMetadata } from \"@soda-gql/builder/plugin-support\";\nimport type { CanonicalPathTracker } from \"@soda-gql/common\";\nimport { createCanonicalTracker } from \"@soda-gql/common\";\nimport * as ts from \"typescript\";\n\nexport type GqlDefinitionMetadataMap = WeakMap<ts.CallExpression, GqlDefinitionMetadata>;\n\ntype CanonicalTrackerFactory = typeof createCanonicalTracker;\n\ntype CollectArgs = {\n readonly sourceFile: ts.SourceFile;\n readonly filename: string;\n readonly createTracker?: CanonicalTrackerFactory;\n};\n\ntype ScopeHandle = ReturnType<CanonicalPathTracker[\"enterScope\"]>;\ntype ExportBindingMap = Map<string, string>;\n\nexport const collectGqlDefinitionMetadata = ({ sourceFile, filename, createTracker }: CollectArgs): GqlDefinitionMetadataMap => {\n const exportBindings = collectExportBindings(sourceFile);\n const trackerFactory = createTracker ?? createCanonicalTracker;\n const tracker = trackerFactory({\n filePath: filename,\n getExportName: (localName) => exportBindings.get(localName),\n });\n\n const getAnonymousName = createAnonymousNameFactory();\n const scopeHandles = new WeakMap<ts.Node, ScopeHandle>();\n const metadata = new WeakMap<ts.CallExpression, GqlDefinitionMetadata>();\n\n const visit = (node: ts.Node): void => {\n // Handle GraphQL definition calls\n if (ts.isCallExpression(node) && isGqlDefinitionCall(node, ts)) {\n const depthBeforeRegister = tracker.currentDepth();\n const { astPath } = tracker.registerDefinition();\n const isTopLevel = depthBeforeRegister <= 1;\n const exportInfo = isTopLevel ? resolveTopLevelExport(node, exportBindings, ts) : null;\n\n metadata.set(node, {\n astPath,\n isTopLevel,\n isExported: exportInfo?.isExported ?? false,\n exportBinding: exportInfo?.exportBinding,\n });\n\n // Skip visiting children of gql calls\n return;\n }\n\n // Enter scope if this node creates one\n const handle = maybeEnterScope(node, tracker, getAnonymousName, ts);\n if (handle) {\n scopeHandles.set(node, handle);\n }\n\n // Visit children\n ts.forEachChild(node, visit);\n\n // Exit scope if we entered one\n const scopeHandle = scopeHandles.get(node);\n if (scopeHandle) {\n tracker.exitScope(scopeHandle);\n scopeHandles.delete(node);\n }\n };\n\n visit(sourceFile);\n\n return metadata;\n};\n\nconst collectExportBindings = (sourceFile: ts.SourceFile): ExportBindingMap => {\n const bindings: ExportBindingMap = new Map();\n\n for (const statement of sourceFile.statements) {\n // ESM exports: export const foo = ...\n if (ts.isExportDeclaration(statement) && statement.exportClause && ts.isNamedExports(statement.exportClause)) {\n for (const element of statement.exportClause.elements) {\n const name = element.name.text;\n bindings.set(name, name);\n }\n continue;\n }\n\n // Export variable declaration: export const foo = ...\n if (ts.isVariableStatement(statement) && statement.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword)) {\n for (const declaration of statement.declarationList.declarations) {\n if (ts.isIdentifier(declaration.name)) {\n bindings.set(declaration.name.text, declaration.name.text);\n }\n }\n continue;\n }\n\n // Export function/class: export function foo() {} or export class Foo {}\n if (\n (ts.isFunctionDeclaration(statement) || ts.isClassDeclaration(statement)) &&\n statement.modifiers?.some((m) => m.kind === ts.SyntaxKind.ExportKeyword) &&\n statement.name\n ) {\n bindings.set(statement.name.text, statement.name.text);\n continue;\n }\n\n // CommonJS exports: exports.foo = ... or module.exports.foo = ...\n if (ts.isExpressionStatement(statement) && ts.isBinaryExpression(statement.expression)) {\n const exportName = getCommonJsExportName(statement.expression.left);\n if (exportName) {\n bindings.set(exportName, exportName);\n }\n }\n }\n\n return bindings;\n};\n\nconst getCommonJsExportName = (node: ts.Node): string | null => {\n if (!ts.isPropertyAccessExpression(node)) {\n return null;\n }\n\n // Check if it's exports.foo or module.exports.foo\n const isExports = ts.isIdentifier(node.expression) && node.expression.text === \"exports\";\n const isModuleExports =\n ts.isPropertyAccessExpression(node.expression) &&\n ts.isIdentifier(node.expression.expression) &&\n node.expression.expression.text === \"module\" &&\n ts.isIdentifier(node.expression.name) &&\n node.expression.name.text === \"exports\";\n\n if (!isExports && !isModuleExports) {\n return null;\n }\n\n // Extract property name\n if (ts.isIdentifier(node.name)) {\n return node.name.text;\n }\n\n return null;\n};\n\nconst createAnonymousNameFactory = (): ((kind: string) => string) => {\n const counters = new Map<string, number>();\n return (kind) => {\n const count = counters.get(kind) ?? 0;\n counters.set(kind, count + 1);\n return `${kind}#${count}`;\n };\n};\n\nconst isGqlDefinitionCall = (node: ts.Node, typescript: typeof ts): node is ts.CallExpression => {\n if (!typescript.isCallExpression(node)) {\n return false;\n }\n if (!typescript.isPropertyAccessExpression(node.expression)) {\n return false;\n }\n if (!isGqlReference(node.expression.expression, typescript)) {\n return false;\n }\n if (node.arguments.length === 0) {\n return false;\n }\n const firstArg = node.arguments[0];\n if (firstArg === undefined) {\n return false;\n }\n return typescript.isArrowFunction(firstArg);\n};\n\nconst isGqlReference = (expr: ts.Expression, typescript: typeof ts): boolean => {\n if (typescript.isIdentifier(expr) && expr.text === \"gql\") {\n return true;\n }\n if (!typescript.isPropertyAccessExpression(expr)) {\n return false;\n }\n if (typescript.isIdentifier(expr.name) && expr.name.text === \"gql\") {\n return true;\n }\n return isGqlReference(expr.expression, typescript);\n};\n\nconst resolveTopLevelExport = (\n callNode: ts.CallExpression,\n exportBindings: ExportBindingMap,\n typescript: typeof ts,\n): { readonly isExported: true; readonly exportBinding: string } | null => {\n // ESM: const foo = gql.default(...); export { foo };\n const parent = callNode.parent;\n if (!parent) {\n return null;\n }\n\n if (typescript.isVariableDeclaration(parent)) {\n const { name } = parent;\n if (typescript.isIdentifier(name)) {\n const exportBinding = exportBindings.get(name.text);\n if (exportBinding) {\n return { isExported: true, exportBinding };\n }\n }\n }\n\n // CommonJS: exports.foo = gql.default(...);\n if (typescript.isBinaryExpression(parent)) {\n const exportName = getCommonJsExportName(parent.left);\n if (exportName && exportBindings.has(exportName)) {\n return { isExported: true, exportBinding: exportName };\n }\n }\n\n return null;\n};\n\nconst maybeEnterScope = (\n node: ts.Node,\n tracker: CanonicalPathTracker,\n getAnonymousName: (kind: string) => string,\n typescript: typeof ts,\n): ScopeHandle | null => {\n // CommonJS exports: exports.foo = ... or module.exports.foo = ...\n if (typescript.isBinaryExpression(node)) {\n const exportName = getCommonJsExportName(node.left);\n if (exportName) {\n return tracker.enterScope({ segment: exportName, kind: \"variable\", stableKey: `var:${exportName}` });\n }\n }\n\n if (typescript.isVariableDeclaration(node) && typescript.isIdentifier(node.name)) {\n const name = node.name.text;\n return tracker.enterScope({ segment: name, kind: \"variable\", stableKey: `var:${name}` });\n }\n\n if (typescript.isArrowFunction(node)) {\n const name = getAnonymousName(\"arrow\");\n return tracker.enterScope({ segment: name, kind: \"function\", stableKey: \"arrow\" });\n }\n\n if (typescript.isFunctionDeclaration(node) || typescript.isFunctionExpression(node)) {\n const explicitName = node.name?.text;\n const name = explicitName ?? getAnonymousName(\"function\");\n return tracker.enterScope({ segment: name, kind: \"function\", stableKey: `func:${name}` });\n }\n\n if (typescript.isClassDeclaration(node)) {\n const explicitName = node.name?.text;\n const name = explicitName ?? getAnonymousName(\"class\");\n return tracker.enterScope({ segment: name, kind: \"class\", stableKey: `class:${name}` });\n }\n\n if (typescript.isMethodDeclaration(node) && typescript.isIdentifier(node.name)) {\n const name = node.name.text;\n return tracker.enterScope({ segment: name, kind: \"method\", stableKey: `member:${name}` });\n }\n\n if (typescript.isPropertyDeclaration(node) && typescript.isIdentifier(node.name)) {\n const name = node.name.text;\n return tracker.enterScope({ segment: name, kind: \"property\", stableKey: `member:${name}` });\n }\n\n if (typescript.isPropertyAssignment(node)) {\n const key = node.name;\n const name = typescript.isIdentifier(key) ? key.text : typescript.isStringLiteral(key) ? key.text : null;\n if (name) {\n return tracker.enterScope({ segment: name, kind: \"property\", stableKey: `prop:${name}` });\n }\n }\n\n return null;\n};\n","import type { BuilderArtifactElement } from \"@soda-gql/builder\";\nimport type {\n GqlCallFragment,\n GqlCallOperation,\n PluginAnalysisArtifactMissingError,\n PluginAnalysisMetadataMissingError,\n PluginAnalysisUnsupportedArtifactTypeError,\n PluginError,\n} from \"@soda-gql/builder/plugin-support\";\nimport { resolveCanonicalId } from \"@soda-gql/builder/plugin-support\";\nimport type { CanonicalId } from \"@soda-gql/common\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport type * as ts from \"typescript\";\nimport type { GqlDefinitionMetadataMap } from \"./metadata\";\n\nexport type ArtifactLookup = (canonicalId: CanonicalId) => BuilderArtifactElement | undefined;\n\n// TypeScript-specific GqlCall types\nexport type TsGqlCallFragment = GqlCallFragment & { readonly callNode: ts.CallExpression };\nexport type TsGqlCallOperation = GqlCallOperation & { readonly callNode: ts.CallExpression };\n\nexport type TsGqlCall = TsGqlCallFragment | TsGqlCallOperation;\n\nexport type ExtractGqlCallArgs = {\n readonly callNode: ts.CallExpression;\n readonly filename: string;\n readonly metadata: GqlDefinitionMetadataMap;\n readonly getArtifact: ArtifactLookup;\n};\n\nexport const extractGqlCall = ({\n callNode,\n filename,\n metadata,\n getArtifact,\n}: ExtractGqlCallArgs): Result<TsGqlCall, PluginError> => {\n const meta = metadata.get(callNode);\n if (!meta) {\n return err(createMetadataMissingError({ filename }));\n }\n\n const canonicalId = resolveCanonicalId(filename, meta.astPath);\n const artifact = getArtifact(canonicalId);\n\n if (!artifact) {\n return err(createArtifactMissingError({ filename, canonicalId }));\n }\n\n if (artifact.type === \"fragment\") {\n return ok({ callNode, canonicalId, type: \"fragment\", artifact });\n }\n\n if (artifact.type === \"operation\") {\n return ok({ callNode, canonicalId, type: \"operation\", artifact });\n }\n\n return err(\n createUnsupportedArtifactTypeError({\n filename,\n canonicalId,\n artifactType: (artifact as { type: string }).type,\n }),\n );\n};\n\ntype MetadataErrorInput = { readonly filename: string };\ntype ArtifactMissingErrorInput = { readonly filename: string; readonly canonicalId: CanonicalId };\ntype UnsupportedArtifactTypeInput = {\n readonly filename: string;\n readonly canonicalId: CanonicalId;\n readonly artifactType: string;\n};\n\nconst createMetadataMissingError = ({ filename }: MetadataErrorInput): PluginAnalysisMetadataMissingError => ({\n type: \"PluginError\",\n stage: \"analysis\",\n code: \"SODA_GQL_METADATA_NOT_FOUND\",\n message: `No GraphQL metadata found for ${filename}`,\n cause: { filename },\n filename,\n});\n\nconst createArtifactMissingError = ({\n filename,\n canonicalId,\n}: ArtifactMissingErrorInput): PluginAnalysisArtifactMissingError => ({\n type: \"PluginError\",\n stage: \"analysis\",\n code: \"SODA_GQL_ANALYSIS_ARTIFACT_NOT_FOUND\",\n message: `No builder artifact found for canonical ID ${canonicalId}`,\n cause: { filename, canonicalId },\n filename,\n canonicalId,\n});\n\nconst createUnsupportedArtifactTypeError = ({\n filename,\n canonicalId,\n artifactType,\n}: UnsupportedArtifactTypeInput): PluginAnalysisUnsupportedArtifactTypeError => ({\n type: \"PluginError\",\n stage: \"analysis\",\n code: \"SODA_GQL_UNSUPPORTED_ARTIFACT_TYPE\",\n message: `Unsupported builder artifact type \"${artifactType}\" for canonical ID ${canonicalId}`,\n cause: { filename, canonicalId, artifactType },\n filename,\n canonicalId,\n artifactType,\n});\n","import type { PluginError, PluginTransformUnsupportedValueTypeError } from \"@soda-gql/builder/plugin-support\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport * as ts from \"typescript\";\n\nconst createUnsupportedValueTypeError = (valueType: string): PluginTransformUnsupportedValueTypeError => ({\n type: \"PluginError\",\n stage: \"transform\",\n code: \"SODA_GQL_TRANSFORM_UNSUPPORTED_VALUE_TYPE\",\n message: `Unsupported value type: ${valueType}`,\n cause: { valueType },\n valueType,\n});\n\n/**\n * Build a literal expression from a primitive value.\n * Mirrors Babel's buildLiteralFromValue.\n */\nexport const buildLiteralFromValue = (factory: ts.NodeFactory, value: unknown): Result<ts.Expression, PluginError> => {\n if (value === null) {\n return ok(factory.createNull());\n }\n if (typeof value === \"string\") {\n return ok(factory.createStringLiteral(value));\n }\n if (typeof value === \"number\") {\n return ok(factory.createNumericLiteral(value));\n }\n if (typeof value === \"boolean\") {\n return ok(value ? factory.createTrue() : factory.createFalse());\n }\n if (Array.isArray(value)) {\n const elements: ts.Expression[] = [];\n for (const item of value) {\n const result = buildLiteralFromValue(factory, item);\n if (result.isErr()) {\n return result;\n }\n elements.push(result.value);\n }\n return ok(factory.createArrayLiteralExpression(elements));\n }\n if (typeof value === \"object\") {\n const properties: ts.PropertyAssignment[] = [];\n for (const [key, val] of Object.entries(value)) {\n const result = buildLiteralFromValue(factory, val);\n if (result.isErr()) {\n return result;\n }\n properties.push(factory.createPropertyAssignment(factory.createIdentifier(key), result.value));\n }\n return ok(factory.createObjectLiteralExpression(properties));\n }\n return err(createUnsupportedValueTypeError(typeof value));\n};\n\n/**\n * Clone a TypeScript node deeply.\n * TypeScript nodes are immutable, so we need to use visitEachChild for deep cloning.\n */\nexport const clone = <T extends ts.Node>(node: T): T => {\n const cloneVisitor = (n: ts.Node): ts.Node => ts.visitEachChild(n, cloneVisitor, undefined);\n return cloneVisitor(node) as T;\n};\n\n/**\n * Build an object literal expression from a record of properties.\n */\nexport const buildObjectExpression = <K extends string>(\n factory: ts.NodeFactory,\n properties: Record<K, ts.Expression>,\n): ts.ObjectLiteralExpression => {\n const propertyAssignments = Object.entries<ts.Expression>(properties).map(([key, value]) =>\n factory.createPropertyAssignment(factory.createIdentifier(key), value),\n );\n return factory.createObjectLiteralExpression(propertyAssignments);\n};\n\n/**\n * Build a JSON.parse expression from an object value.\n * This is used to emit large objects as JSON strings to reduce the calculation cost of both the compiler and the runtime.\n */\nexport const buildJsonParseExpression = <T extends object>(factory: ts.NodeFactory, value: T): ts.Expression =>\n factory.createCallExpression(\n factory.createPropertyAccessExpression(factory.createIdentifier(\"JSON\"), factory.createIdentifier(\"parse\")),\n undefined,\n [factory.createStringLiteral(JSON.stringify(value))],\n );\n","import type { PluginError } from \"@soda-gql/builder/plugin-support\";\nimport type { RuntimeOperationInput } from \"@soda-gql/core/runtime\";\nimport { ok, type Result } from \"neverthrow\";\nimport type * as ts from \"typescript\";\nimport type { TsGqlCallFragment, TsGqlCallOperation } from \"./analysis\";\nimport { buildJsonParseExpression, buildObjectExpression } from \"./ast\";\n\nconst createRuntimeAccessor = ({ isCJS, factory }: { isCJS: boolean; factory: ts.NodeFactory }) =>\n isCJS\n ? factory.createPropertyAccessExpression(\n factory.createIdentifier(\"__soda_gql_runtime\"),\n factory.createIdentifier(\"gqlRuntime\"),\n )\n : factory.createIdentifier(\"gqlRuntime\");\n\nexport const buildFragmentRuntimeCall = ({\n gqlCall,\n factory,\n isCJS,\n}: {\n gqlCall: TsGqlCallFragment;\n factory: ts.NodeFactory;\n isCJS: boolean;\n filename: string;\n}): Result<ts.Expression, PluginError> => {\n const prebuildProps: Record<string, ts.Expression> = {\n typename: factory.createStringLiteral(gqlCall.artifact.prebuild.typename),\n };\n if (gqlCall.artifact.prebuild.key !== undefined) {\n prebuildProps.key = factory.createStringLiteral(gqlCall.artifact.prebuild.key);\n }\n\n return ok(\n factory.createCallExpression(\n factory.createPropertyAccessExpression(createRuntimeAccessor({ isCJS, factory }), factory.createIdentifier(\"fragment\")),\n undefined,\n [\n buildObjectExpression(factory, {\n prebuild: buildObjectExpression(factory, prebuildProps),\n }),\n ],\n ),\n );\n};\n\nexport const buildOperationRuntimeComponents = ({\n gqlCall,\n factory,\n isCJS,\n}: {\n gqlCall: TsGqlCallOperation;\n factory: ts.NodeFactory;\n isCJS: boolean;\n}): Result<{ referenceCall: ts.Expression; runtimeCall: ts.Expression }, PluginError> => {\n const runtimeCall = factory.createCallExpression(\n factory.createPropertyAccessExpression(createRuntimeAccessor({ isCJS, factory }), factory.createIdentifier(\"operation\")),\n undefined,\n [\n buildObjectExpression(factory, {\n prebuild: buildJsonParseExpression<RuntimeOperationInput[\"prebuild\"]>(factory, gqlCall.artifact.prebuild),\n runtime: buildObjectExpression(factory, {}),\n }),\n ],\n );\n\n const referenceCall = factory.createCallExpression(\n factory.createPropertyAccessExpression(createRuntimeAccessor({ isCJS, factory }), factory.createIdentifier(\"getOperation\")),\n undefined,\n [factory.createStringLiteral(gqlCall.artifact.prebuild.operationName)],\n );\n\n return ok({\n referenceCall,\n runtimeCall,\n });\n};\n","import type { PluginError } from \"@soda-gql/builder/plugin-support\";\nimport { err, ok, type Result } from \"neverthrow\";\nimport type * as ts from \"typescript\";\nimport type { ArtifactLookup, TsGqlCall } from \"./analysis\";\nimport { extractGqlCall } from \"./analysis\";\nimport type { GqlDefinitionMetadataMap } from \"./metadata\";\nimport { buildFragmentRuntimeCall, buildOperationRuntimeComponents } from \"./runtime\";\n\ntype TransformCallExpressionArgs = {\n readonly callNode: ts.CallExpression;\n readonly filename: string;\n readonly metadata: GqlDefinitionMetadataMap;\n readonly getArtifact: ArtifactLookup;\n readonly factory: ts.NodeFactory;\n readonly isCJS: boolean;\n};\n\ntype TransformCallExpressionResult =\n | { readonly transformed: false }\n | { readonly transformed: true; readonly replacement: ts.Expression; readonly runtimeCall?: ts.Expression };\n\nexport const transformCallExpression = ({\n callNode,\n filename,\n metadata,\n getArtifact,\n factory,\n isCJS,\n}: TransformCallExpressionArgs): Result<TransformCallExpressionResult, PluginError> => {\n // Skip if this call doesn't have GQL metadata\n if (!metadata.has(callNode)) {\n return ok({ transformed: false });\n }\n\n const gqlCallResult = extractGqlCall({\n callNode,\n filename,\n metadata,\n getArtifact,\n });\n\n if (gqlCallResult.isErr()) {\n return err(gqlCallResult.error);\n }\n\n const gqlCall = gqlCallResult.value;\n\n return replaceWithRuntimeCall({ gqlCall, factory, isCJS, filename });\n};\n\nconst replaceWithRuntimeCall = ({\n gqlCall,\n factory,\n isCJS,\n filename,\n}: {\n gqlCall: TsGqlCall;\n factory: ts.NodeFactory;\n isCJS: boolean;\n filename: string;\n}): Result<TransformCallExpressionResult, PluginError> => {\n if (gqlCall.type === \"fragment\") {\n const result = buildFragmentRuntimeCall({ gqlCall, factory, isCJS, filename });\n if (result.isErr()) {\n return err(result.error);\n }\n return ok({ transformed: true, replacement: result.value as ts.Expression });\n }\n\n if (gqlCall.type === \"operation\") {\n const result = buildOperationRuntimeComponents({ gqlCall, factory, isCJS });\n if (result.isErr()) {\n return err(result.error);\n }\n const { referenceCall, runtimeCall } = result.value;\n return ok({ transformed: true, replacement: referenceCall, runtimeCall });\n }\n\n return ok({ transformed: false });\n};\n","/**\n * TypeScript implementation of the TransformAdapter interface.\n */\n\nimport type { BuilderArtifact } from \"@soda-gql/builder\";\nimport { createGraphqlSystemIdentifyHelper } from \"@soda-gql/builder\";\nimport { formatPluginError } from \"@soda-gql/builder/plugin-support\";\nimport type { CanonicalId } from \"@soda-gql/common\";\nimport type { ResolvedSodaGqlConfig } from \"@soda-gql/config\";\nimport * as ts from \"typescript\";\nimport { ensureGqlRuntimeImport, ensureGqlRuntimeRequire, removeGraphqlSystemImports } from \"./ast/imports\";\nimport { collectGqlDefinitionMetadata } from \"./ast/metadata\";\nimport { transformCallExpression } from \"./ast/transformer\";\n\nexport { createAfterStubTransformer } from \"./ast/imports\";\n\n/**\n * TypeScript-specific environment required for the adapter.\n */\nexport type TypeScriptEnv = {\n readonly sourceFile: ts.SourceFile;\n readonly context: ts.TransformationContext;\n};\n\nconst findLastImportIndex = ({ sourceFile }: { sourceFile: ts.SourceFile }): number => {\n let lastIndex = -1;\n const statements = sourceFile.statements;\n\n for (let i = 0; i < statements.length; i++) {\n const statement = statements[i];\n if (statement && ts.isImportDeclaration(statement)) {\n lastIndex = i;\n }\n }\n\n return lastIndex;\n};\n\nexport const createTransformer = ({\n compilerOptions,\n config,\n artifact,\n}: {\n readonly compilerOptions: ts.CompilerOptions;\n readonly config: ResolvedSodaGqlConfig;\n readonly artifact: BuilderArtifact;\n}) => {\n const isCJS = compilerOptions.module === ts.ModuleKind.CommonJS || compilerOptions.target === ts.ScriptTarget.ES5;\n\n // Create graphql system identify helper using builder's implementation\n const graphqlSystemIdentifyHelper = createGraphqlSystemIdentifyHelper(config);\n\n const makeSourceFileEmpty = ({ factory, sourceFile }: { factory: ts.NodeFactory; sourceFile: ts.SourceFile }) => {\n return factory.updateSourceFile(sourceFile, [\n factory.createExportDeclaration(undefined, false, factory.createNamedExports([]), undefined),\n ]);\n };\n\n const transformGqlCalls = ({ sourceFile, context }: { sourceFile: ts.SourceFile; context: ts.TransformationContext }) => {\n let transformed = false;\n\n const metadata = collectGqlDefinitionMetadata({\n sourceFile,\n filename: sourceFile.fileName,\n });\n\n const runtimeCallsFromLastTransform: ts.Expression[] = [];\n const visitor = (node: ts.Node): ts.Node => {\n if (ts.isCallExpression(node)) {\n const result = transformCallExpression({\n callNode: node,\n filename: sourceFile.fileName,\n metadata,\n getArtifact: (canonicalId: CanonicalId) => artifact.elements[canonicalId],\n factory: context.factory,\n isCJS,\n });\n\n if (result.isErr()) {\n // Log error and continue - don't fail the entire build for a single error\n console.error(`[@soda-gql/tsc] ${formatPluginError(result.error)}`);\n return node;\n }\n\n const transformResult = result.value;\n if (transformResult.transformed) {\n transformed = true;\n\n if (transformResult.runtimeCall) {\n runtimeCallsFromLastTransform.push(transformResult.runtimeCall);\n }\n\n return transformResult.replacement;\n }\n }\n\n return ts.visitEachChild(node, visitor, context);\n };\n\n const visitedNode = ts.visitNode(sourceFile, visitor);\n if (!visitedNode || !ts.isSourceFile(visitedNode)) {\n console.error(`[@soda-gql/tsc] Failed to transform source file: ${sourceFile.fileName}`);\n return sourceFile;\n }\n\n if (!transformed) {\n return sourceFile;\n }\n\n if (runtimeCallsFromLastTransform.length === 0) {\n return visitedNode;\n }\n\n const lastImportIndex = findLastImportIndex({ sourceFile });\n\n return context.factory.updateSourceFile(visitedNode, [\n ...visitedNode.statements.slice(0, lastImportIndex + 1),\n ...runtimeCallsFromLastTransform.map((expr) => context.factory.createExpressionStatement(expr)),\n ...visitedNode.statements.slice(lastImportIndex + 1),\n ]);\n };\n\n return {\n transform: ({ sourceFile, context }: { sourceFile: ts.SourceFile; context: ts.TransformationContext }) => {\n // Stub internal modules (graphql-system and inject files)\n // These modules are only needed at build time and should be empty at runtime\n if (graphqlSystemIdentifyHelper.isInternalModuleFile({ filePath: sourceFile.fileName })) {\n const transformedSourceFile = makeSourceFileEmpty({ factory: context.factory, sourceFile: sourceFile });\n return { transformed: true, sourceFile: transformedSourceFile };\n }\n\n const original = sourceFile;\n let current = sourceFile;\n current = transformGqlCalls({ sourceFile: current, context });\n\n if (current !== sourceFile) {\n current = isCJS\n ? ensureGqlRuntimeRequire({ sourceFile: current, factory: context.factory })\n : ensureGqlRuntimeImport({ sourceFile: current, factory: context.factory });\n }\n\n current = removeGraphqlSystemImports({\n sourceFile: current,\n factory: context.factory,\n graphqlSystemIdentifyHelper,\n });\n\n return { transformed: current !== original, sourceFile: current };\n },\n };\n};\n"],"mappings":";;;;;;;;AAGA,MAAM,iBAAiB;;;;;;AAOvB,MAAa,2BAA2B,EACtC,YACA,cAImB;AAqBnB,KAnBiB,WAAW,WAAW,MACpC,cACC,GAAG,oBAAoB,UAAU,IACjC,UAAU,gBAAgB,aAAa,MAAM,SAAS;AACpD,MAAI,CAAC,GAAG,aAAa,KAAK,KAAK,IAAI,KAAK,KAAK,SAAS,qBACpD,QAAO;AAET,MAAI,CAAC,KAAK,eAAe,CAAC,GAAG,iBAAiB,KAAK,YAAY,CAC7D,QAAO;EAET,MAAM,WAAW,KAAK;AACtB,MAAI,CAAC,GAAG,aAAa,SAAS,WAAW,IAAI,SAAS,WAAW,SAAS,UACxE,QAAO;EAET,MAAM,MAAM,SAAS,UAAU;AAC/B,SAAO,OAAO,GAAG,gBAAgB,IAAI,IAAI,IAAI,SAAS;GACtD,CACL,CAGC,QAAO;CAIT,MAAM,cAAc,QAAQ,qBAAqB,QAAQ,iBAAi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