Keep protobuf value types distinct from object refs
This commit is contained in:
Vendored
+3
-3
@@ -22,12 +22,12 @@ const symbolId = (value) => `${value.namespace}:${value.name}:${value.version}:$
|
|||||||
const normalizedProtoType = (value) => value.replace(/^\./, "");
|
const normalizedProtoType = (value) => value.replace(/^\./, "");
|
||||||
const declarationName = (value) => value.name;
|
const declarationName = (value) => value.name;
|
||||||
const tsTypeForTypeRef = (type, root) => {
|
const tsTypeForTypeRef = (type, root) => {
|
||||||
if (type.symbol) {
|
|
||||||
return `ObjectRef<${stringLiteral(symbolId(type.symbol))}>`;
|
|
||||||
}
|
|
||||||
if (type.enumValues && type.enumValues.length > 0) {
|
if (type.enumValues && type.enumValues.length > 0) {
|
||||||
return type.enumValues.map(stringLiteral).join(" | ");
|
return type.enumValues.map(stringLiteral).join(" | ");
|
||||||
}
|
}
|
||||||
|
if (type.symbol) {
|
||||||
|
return `ObjectRef<${stringLiteral(symbolId(type.symbol))}>`;
|
||||||
|
}
|
||||||
const protoType = normalizedProtoType(type.protoType);
|
const protoType = normalizedProtoType(type.protoType);
|
||||||
switch (protoType) {
|
switch (protoType) {
|
||||||
case "string":
|
case "string":
|
||||||
|
|||||||
Vendored
+1
-1
@@ -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"}
|
{"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"}
|
||||||
Vendored
+1
-3
@@ -267,8 +267,7 @@ const protoSymbolFromReflection = (reflection, fallbackVersion) => {
|
|||||||
version: fallbackVersion,
|
version: fallbackVersion,
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
const typeRefForField = (field, schemaVersion) => {
|
const typeRefForField = (field, _schemaVersion) => {
|
||||||
const symbol = protoSymbolFromReflection(field.resolvedType, schemaVersion);
|
|
||||||
const enumValues = field.resolvedType instanceof protobuf.Enum
|
const enumValues = field.resolvedType instanceof protobuf.Enum
|
||||||
? Object.entries(field.resolvedType.values)
|
? Object.entries(field.resolvedType.values)
|
||||||
.filter(([_name, value]) => value !== 0)
|
.filter(([_name, value]) => value !== 0)
|
||||||
@@ -276,7 +275,6 @@ const typeRefForField = (field, schemaVersion) => {
|
|||||||
: undefined;
|
: undefined;
|
||||||
return {
|
return {
|
||||||
protoType: field.type,
|
protoType: field.type,
|
||||||
...(symbol ? { symbol } : {}),
|
|
||||||
...(enumValues ? { enumValues } : {}),
|
...(enumValues ? { enumValues } : {}),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -58,12 +58,12 @@ const tsTypeForTypeRef = (
|
|||||||
type: TypeRef,
|
type: TypeRef,
|
||||||
root?: protobuf.Root,
|
root?: protobuf.Root,
|
||||||
): string => {
|
): string => {
|
||||||
if (type.symbol) {
|
|
||||||
return `ObjectRef<${stringLiteral(symbolId(type.symbol))}>`;
|
|
||||||
}
|
|
||||||
if (type.enumValues && type.enumValues.length > 0) {
|
if (type.enumValues && type.enumValues.length > 0) {
|
||||||
return type.enumValues.map(stringLiteral).join(" | ");
|
return type.enumValues.map(stringLiteral).join(" | ");
|
||||||
}
|
}
|
||||||
|
if (type.symbol) {
|
||||||
|
return `ObjectRef<${stringLiteral(symbolId(type.symbol))}>`;
|
||||||
|
}
|
||||||
const protoType = normalizedProtoType(type.protoType);
|
const protoType = normalizedProtoType(type.protoType);
|
||||||
switch (protoType) {
|
switch (protoType) {
|
||||||
case "string":
|
case "string":
|
||||||
|
|||||||
@@ -366,9 +366,8 @@ const protoSymbolFromReflection = (
|
|||||||
|
|
||||||
const typeRefForField = (
|
const typeRefForField = (
|
||||||
field: protobuf.Field,
|
field: protobuf.Field,
|
||||||
schemaVersion: string,
|
_schemaVersion: string,
|
||||||
): TypeRef => {
|
): TypeRef => {
|
||||||
const symbol = protoSymbolFromReflection(field.resolvedType, schemaVersion);
|
|
||||||
const enumValues =
|
const enumValues =
|
||||||
field.resolvedType instanceof protobuf.Enum
|
field.resolvedType instanceof protobuf.Enum
|
||||||
? Object.entries(field.resolvedType.values)
|
? Object.entries(field.resolvedType.values)
|
||||||
@@ -377,7 +376,6 @@ const typeRefForField = (
|
|||||||
: undefined;
|
: undefined;
|
||||||
return {
|
return {
|
||||||
protoType: field.type,
|
protoType: field.type,
|
||||||
...(symbol ? { symbol } : {}),
|
|
||||||
...(enumValues ? { enumValues } : {}),
|
...(enumValues ? { enumValues } : {}),
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user