Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
lukasIO committed Dec 30, 2024
1 parent 24c1bc3 commit 1464b23
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 34 deletions.
6 changes: 3 additions & 3 deletions packages/protobuf/src/codegen-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@ interface CodegenInfo {
| DescOneof
| DescField
| DescService
| DescMethod
| DescMethod,
) => string;
readonly symbols: Record<RuntimeSymbolName, RuntimeSymbolInfo>;
readonly getUnwrappedFieldType: (
field: DescField | DescExtension
field: DescField | DescExtension,
) => ScalarType | undefined;
readonly wktSourceFiles: readonly string[];
/**
Expand All @@ -60,7 +60,7 @@ interface CodegenInfo {
readonly scalarDefaultValue: (type: ScalarType, longType: LongType) => any; // eslint-disable-line @typescript-eslint/no-explicit-any
readonly scalarZeroValue: <T extends ScalarType, L extends LongType>(
type: T,
longType: L
longType: L,
) => ScalarValue<T, L>;
/**
* @deprecated please use reifyWkt from @bufbuild/protoplugin/ecmascript instead
Expand Down
4 changes: 2 additions & 2 deletions packages/protobuf/src/message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export class Message<T extends Message<T> = AnyMessage> {
return this.getType().runtime.util.equals(
this.getType(),
this as unknown as T,
other
other,
);
}

Expand Down Expand Up @@ -96,7 +96,7 @@ export class Message<T extends Message<T> = AnyMessage> {
throw new Error(
`cannot decode ${this.getType().typeName} from JSON: ${
e instanceof Error ? e.message : String(e)
}`
}`,
);
}
return this.fromJson(json, options);
Expand Down
28 changes: 14 additions & 14 deletions packages/protoc-gen-es/src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import { localName } from "@bufbuild/protoplugin/ecmascript";

export function getFieldTypeInfo(
field: DescField | DescExtension,
strict: boolean
strict: boolean,
): {
typing: Printable;
optional: boolean;
Expand Down Expand Up @@ -89,7 +89,7 @@ export function getFieldTypeInfo(
case "scalar":
valueType = scalarTypeScriptType(
field.mapValue.scalar,
LongType.BIGINT
LongType.BIGINT,
);
break;
case "message":
Expand Down Expand Up @@ -130,7 +130,7 @@ export function getFieldDefaultValueExpression(
enumAs:
| "enum_value_as_is"
| "enum_value_as_integer"
| "enum_value_as_cast_integer" = "enum_value_as_is"
| "enum_value_as_cast_integer" = "enum_value_as_is",
): Printable | undefined {
if (field.repeated) {
return undefined;
Expand All @@ -145,11 +145,11 @@ export function getFieldDefaultValueExpression(
switch (field.fieldKind) {
case "enum": {
const enumValue = field.enum.values.find(
(value) => value.number === defaultValue
(value) => value.number === defaultValue,
);
if (enumValue === undefined) {
throw new Error(
`invalid enum default value: ${String(defaultValue)} for ${enumValue}`
`invalid enum default value: ${String(defaultValue)} for ${enumValue}`,
);
}
return literalEnumValue(enumValue, enumAs);
Expand All @@ -174,7 +174,7 @@ export function getFieldZeroValueExpression(
enumAs:
| "enum_value_as_is"
| "enum_value_as_integer"
| "enum_value_as_cast_integer" = "enum_value_as_is"
| "enum_value_as_cast_integer" = "enum_value_as_is",
): Printable | undefined {
if (field.repeated) {
return "[]";
Expand All @@ -196,7 +196,7 @@ export function getFieldZeroValueExpression(
case "scalar": {
const defaultValue = codegenInfo.scalarZeroValue(
field.scalar,
field.longType
field.longType,
);
return literalScalarValue(defaultValue, field);
}
Expand All @@ -205,7 +205,7 @@ export function getFieldZeroValueExpression(

function literalScalarValue(
value: ScalarValue,
field: (DescField | DescExtension) & { fieldKind: "scalar" }
field: (DescField | DescExtension) & { fieldKind: "scalar" },
): Printable {
switch (field.scalar) {
case ScalarType.DOUBLE:
Expand All @@ -217,28 +217,28 @@ function literalScalarValue(
case ScalarType.SINT32:
if (typeof value != "number") {
throw new Error(
`Unexpected value for ${ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`
`Unexpected value for ${ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`,
);
}
return value;
case ScalarType.BOOL:
if (typeof value != "boolean") {
throw new Error(
`Unexpected value for ${ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`
`Unexpected value for ${ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`,
);
}
return value;
case ScalarType.STRING:
if (typeof value != "string") {
throw new Error(
`Unexpected value for ${ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`
`Unexpected value for ${ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`,
);
}
return { kind: "es_string", value };
case ScalarType.BYTES:
if (!(value instanceof Uint8Array)) {
throw new Error(
`Unexpected value for ${ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`
`Unexpected value for ${ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`,
);
}
return value;
Expand All @@ -249,7 +249,7 @@ function literalScalarValue(
case ScalarType.FIXED64:
if (typeof value != "bigint" && typeof value != "string") {
throw new Error(
`Unexpected value for ${ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`
`Unexpected value for ${ScalarType[field.scalar]} ${field.toString()}: ${String(value)}`,
);
}
return {
Expand All @@ -266,7 +266,7 @@ function literalEnumValue(
enumAs:
| "enum_value_as_is"
| "enum_value_as_integer"
| "enum_value_as_cast_integer"
| "enum_value_as_cast_integer",
): Printable {
switch (enumAs) {
case "enum_value_as_is":
Expand Down
6 changes: 3 additions & 3 deletions packages/protoplugin/src/ecmascript/parameter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export interface ParsedParameter {

export function parseParameter(
parameter: string | undefined,
parseExtraOption: ((key: string, value: string) => void) | undefined
parseExtraOption: ((key: string, value: string) => void) | undefined,
): ParsedParameter {
let targets: Target[] = ["js", "dts"];
let tsNocheck = true;
Expand Down Expand Up @@ -96,7 +96,7 @@ export function parseParameter(
if (parts.length !== 2) {
throw new PluginOptionError(
raw,
"must be in the form of <pattern>:<target>"
"must be in the form of <pattern>:<target>",
);
}
const [pattern, target] = parts;
Expand Down Expand Up @@ -184,7 +184,7 @@ export function parseParameter(
}

function splitParameter(
parameter: string | undefined
parameter: string | undefined,
): { key: string; value: string; raw: string }[] {
if (parameter == undefined) {
return [];
Expand Down
4 changes: 2 additions & 2 deletions packages/protoplugin/src/ecmascript/runtime-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ export function createRuntimeImports(bootstrapWkt: boolean): RuntimeImports {

function infoToSymbol(
name: keyof typeof codegenInfo.symbols,
bootstrapWkt: boolean
bootstrapWkt: boolean,
): ImportSymbol {
const info = codegenInfo.symbols[name];
const symbol = createImportSymbol(
name,
bootstrapWkt ? info.privateImportPath : info.publicImportPath
bootstrapWkt ? info.privateImportPath : info.publicImportPath,
);
return info.typeOnly ? symbol.toTypeOnly() : symbol;
}
22 changes: 12 additions & 10 deletions packages/protoplugin/src/ecmascript/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,21 +95,21 @@ export function createSchema(
parameter: ParsedParameter,
pluginName: string,
pluginVersion: string,
featureSetDefaults: FeatureSetDefaults | undefined
featureSetDefaults: FeatureSetDefaults | undefined,
): SchemaController {
const descriptorSet = createDescriptorSet(request.protoFile, {
featureSetDefaults,
});
const filesToGenerate = findFilesToGenerate(descriptorSet, request);
const runtime = createRuntimeImports(parameter.bootstrapWkt);
const createTypeImport = (
desc: DescMessage | DescEnum | DescExtension
desc: DescMessage | DescEnum | DescExtension,
): ImportSymbol => {
const name = codegenInfo.localName(desc);
const from = makeImportPath(
desc.file,
parameter.bootstrapWkt,
filesToGenerate
filesToGenerate,
);
return createImportSymbol(name, from);
};
Expand All @@ -119,7 +119,7 @@ export function createSchema(
pluginName,
pluginVersion,
parameter.sanitizedParameter,
parameter.tsNocheck
parameter.tsNocheck,
);
let target: Target | undefined;
const generatedFiles: GeneratedFileController[] = [];
Expand All @@ -133,7 +133,7 @@ export function createSchema(
generateFile(name) {
if (target === undefined) {
throw new Error(
"prepareGenerate() must be called before generateFile()"
"prepareGenerate() must be called before generateFile()",
);
}
const genFile = createGeneratedFile(
Expand All @@ -144,11 +144,11 @@ export function createSchema(
rewriteImportPath(
importPath,
parameter.rewriteImports,
parameter.importExtension
parameter.importExtension,
),
createTypeImport,
runtime,
createPreamble
createPreamble,
);
generatedFiles.push(genFile);
return genFile;
Expand All @@ -166,15 +166,17 @@ export function createSchema(

function findFilesToGenerate(
descriptorSet: DescriptorSet,
request: CodeGeneratorRequest
request: CodeGeneratorRequest,
) {
const missing = request.fileToGenerate.filter((fileToGenerate) =>
descriptorSet.files.every((file) => fileToGenerate !== file.name + ".proto")
descriptorSet.files.every(
(file) => fileToGenerate !== file.name + ".proto",
),
);
if (missing.length) {
throw `files_to_generate missing in the request: ${missing.join(", ")}`;
}
return descriptorSet.files.filter((file) =>
request.fileToGenerate.includes(file.name + ".proto")
request.fileToGenerate.includes(file.name + ".proto"),
);
}

0 comments on commit 1464b23

Please sign in to comment.