From 833518c3eab4808e72441daed088a76ebb0a3090 Mon Sep 17 00:00:00 2001 From: "Timothy J. Aveni" Date: Thu, 3 Sep 2026 09:44:56 -0700 Subject: [PATCH] Keep protobuf value types distinct from object refs --- dist/codegen-ts-runtime.js | 6 +++--- dist/schema-compiler.d.ts.map | 2 +- dist/schema-compiler.js | 4 +--- src/codegen-ts-runtime.ts | 6 +++--- src/schema-compiler.ts | 4 +--- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/dist/codegen-ts-runtime.js b/dist/codegen-ts-runtime.js index 0e90402..5a0c0eb 100755 --- a/dist/codegen-ts-runtime.js +++ b/dist/codegen-ts-runtime.js @@ -22,12 +22,12 @@ const symbolId = (value) => `${value.namespace}:${value.name}:${value.version}:$ const normalizedProtoType = (value) => value.replace(/^\./, ""); const declarationName = (value) => value.name; const tsTypeForTypeRef = (type, root) => { - if (type.symbol) { - return `ObjectRef<${stringLiteral(symbolId(type.symbol))}>`; - } if (type.enumValues && type.enumValues.length > 0) { return type.enumValues.map(stringLiteral).join(" | "); } + if (type.symbol) { + return `ObjectRef<${stringLiteral(symbolId(type.symbol))}>`; + } const protoType = normalizedProtoType(type.protoType); switch (protoType) { case "string": diff --git a/dist/schema-compiler.d.ts.map b/dist/schema-compiler.d.ts.map index db9b9b8..aa1fdd9 100644 --- a/dist/schema-compiler.d.ts.map +++ b/dist/schema-compiler.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"schema-compiler.d.ts","sourceRoot":"","sources":["../src/schema-compiler.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,KAAK,EAeV,mBAAmB,EAIpB,MAAM,gBAAgB,CAAC;AA02BxB,eAAO,MAAM,oBAAoB,GAC/B,YAAY,MAAM,KACjB,OAAO,CAAC;IAAE,kBAAkB,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAA;CAAE,CAqC7D,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,YAAY,MAAM,KACjB,OAAO,CAAC,mBAAmB,CAsC7B,CAAC"} \ No newline at end of file +{"version":3,"file":"schema-compiler.d.ts","sourceRoot":"","sources":["../src/schema-compiler.ts"],"names":[],"mappings":"AAEA,OAAO,QAAQ,MAAM,YAAY,CAAC;AAClC,OAAO,KAAK,EAeV,mBAAmB,EAIpB,MAAM,gBAAgB,CAAC;AAw2BxB,eAAO,MAAM,oBAAoB,GAC/B,YAAY,MAAM,KACjB,OAAO,CAAC;IAAE,kBAAkB,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,CAAA;CAAE,CAqC7D,CAAC;AAEF,eAAO,MAAM,mBAAmB,GAC9B,YAAY,MAAM,KACjB,OAAO,CAAC,mBAAmB,CAsC7B,CAAC"} \ No newline at end of file diff --git a/dist/schema-compiler.js b/dist/schema-compiler.js index 6ffb931..54f4f5b 100644 --- a/dist/schema-compiler.js +++ b/dist/schema-compiler.js @@ -267,8 +267,7 @@ const protoSymbolFromReflection = (reflection, fallbackVersion) => { version: fallbackVersion, }; }; -const typeRefForField = (field, schemaVersion) => { - const symbol = protoSymbolFromReflection(field.resolvedType, schemaVersion); +const typeRefForField = (field, _schemaVersion) => { const enumValues = field.resolvedType instanceof protobuf.Enum ? Object.entries(field.resolvedType.values) .filter(([_name, value]) => value !== 0) @@ -276,7 +275,6 @@ const typeRefForField = (field, schemaVersion) => { : undefined; return { protoType: field.type, - ...(symbol ? { symbol } : {}), ...(enumValues ? { enumValues } : {}), }; }; diff --git a/src/codegen-ts-runtime.ts b/src/codegen-ts-runtime.ts index 96f525f..bacc582 100644 --- a/src/codegen-ts-runtime.ts +++ b/src/codegen-ts-runtime.ts @@ -58,12 +58,12 @@ const tsTypeForTypeRef = ( type: TypeRef, root?: protobuf.Root, ): string => { - if (type.symbol) { - return `ObjectRef<${stringLiteral(symbolId(type.symbol))}>`; - } if (type.enumValues && type.enumValues.length > 0) { return type.enumValues.map(stringLiteral).join(" | "); } + if (type.symbol) { + return `ObjectRef<${stringLiteral(symbolId(type.symbol))}>`; + } const protoType = normalizedProtoType(type.protoType); switch (protoType) { case "string": diff --git a/src/schema-compiler.ts b/src/schema-compiler.ts index 8eb1038..ee10ce7 100644 --- a/src/schema-compiler.ts +++ b/src/schema-compiler.ts @@ -366,9 +366,8 @@ const protoSymbolFromReflection = ( const typeRefForField = ( field: protobuf.Field, - schemaVersion: string, + _schemaVersion: string, ): TypeRef => { - const symbol = protoSymbolFromReflection(field.resolvedType, schemaVersion); const enumValues = field.resolvedType instanceof protobuf.Enum ? Object.entries(field.resolvedType.values) @@ -377,7 +376,6 @@ const typeRefForField = ( : undefined; return { protoType: field.type, - ...(symbol ? { symbol } : {}), ...(enumValues ? { enumValues } : {}), }; };