Skip to content

Commit

Permalink
fix: Temporarily put anys back to release.
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenh committed Mar 26, 2023
1 parent 6b4ba39 commit c6f189e
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 22 deletions.
7 changes: 4 additions & 3 deletions src/generate-generic-service-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,14 @@ function generateMethodOptions(ctx: Context, options: MethodOptions | undefined)
chunks.push(code`idempotencyLevel: 'NO_SIDE_EFFECTS',`);
}

if (options._unknownFields !== undefined) {
if ("_unknownFields" in options) {
const msgUnknownFields: any = (options as any)["_unknownFields"];
const unknownFieldsChunks: Code[] = [];

unknownFieldsChunks.push(code`{`);

for (const key in options._unknownFields) {
const values = options._unknownFields[key];
for (const key of Object.keys(msgUnknownFields)) {
const values = msgUnknownFields[key] as Uint8Array[];
const valuesChunks: Code[] = [];

for (const value of values) {
Expand Down
61 changes: 42 additions & 19 deletions src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,12 @@ export function generateSchema(ctx: Context, fileDesc: FileDescriptorProto, sour

let fileOptions: Code | undefined;
if (fileDesc.options) {
fileOptions = encodedOptionsToOptions(ctx, ".google.protobuf.FileOptions", fileDesc.options._unknownFields);
delete fileDesc.options._unknownFields;
fileOptions = encodedOptionsToOptions(
ctx,
".google.protobuf.FileOptions",
(fileDesc.options as any)["_unknownFields"]
);
delete (fileDesc.options as any)["_unknownFields"];
}

const messagesOptions: Code[] = [];
Expand All @@ -121,9 +125,9 @@ export function generateSchema(ctx: Context, fileDesc: FileDescriptorProto, sour
const methodOptions = encodedOptionsToOptions(
ctx,
".google.protobuf.MethodOptions",
method.options._unknownFields
(method.options as any)["_unknownFields"]
);
delete method.options._unknownFields;
delete (method.options as any)["_unknownFields"];
if (methodOptions) {
methodsOptions.push(code`'${method.name}': ${methodOptions}`);
}
Expand All @@ -132,8 +136,12 @@ export function generateSchema(ctx: Context, fileDesc: FileDescriptorProto, sour

let serviceOptions: Code | undefined;
if (service.options) {
serviceOptions = encodedOptionsToOptions(ctx, ".google.protobuf.ServiceOptions", service.options._unknownFields);
delete service.options._unknownFields;
serviceOptions = encodedOptionsToOptions(
ctx,
".google.protobuf.ServiceOptions",
(service.options as any)["_unknownFields"]
);
delete (service.options as any)["_unknownFields"];
}

if (methodsOptions.length > 0 || serviceOptions) {
Expand All @@ -154,9 +162,9 @@ export function generateSchema(ctx: Context, fileDesc: FileDescriptorProto, sour
const valueOptions = encodedOptionsToOptions(
ctx,
".google.protobuf.EnumValueOptions",
value.options._unknownFields
(value.options as any)["_unknownFields"]
);
delete value.options._unknownFields;
delete (value.options as any)["_unknownFields"];
if (valueOptions) {
valuesOptions.push(code`'${value.name}': ${valueOptions}`);
}
Expand All @@ -165,8 +173,12 @@ export function generateSchema(ctx: Context, fileDesc: FileDescriptorProto, sour

let enumOptions: Code | undefined;
if (Enum.options) {
enumOptions = encodedOptionsToOptions(ctx, ".google.protobuf.EnumOptions", Enum.options._unknownFields);
delete Enum.options._unknownFields;
enumOptions = encodedOptionsToOptions(
ctx,
".google.protobuf.EnumOptions",
(Enum.options as any)["_unknownFields"]
);
delete (Enum.options as any)["_unknownFields"];
}

if (valuesOptions.length > 0 || enumOptions) {
Expand Down Expand Up @@ -227,14 +239,13 @@ function getExtensionValue(ctx: Context, extension: FieldDescriptorProto, data:
function encodedOptionsToOptions(
ctx: Context,
extendee: string,
encodedOptions?: { [key: number]: Uint8Array[] }
encodedOptions: { [key: number]: Uint8Array[] }
): Code | undefined {
if (!encodedOptions) {
return undefined;
}
const resultOptions: Code[] = [];
for (const key in encodedOptions) {
const value = encodedOptions[key];
for (const [key, value] of Object.entries(encodedOptions)) {
const extension = extensionCache[extendee][parseInt(key, 10) >>> 3];
resultOptions.push(getExtensionValue(ctx, extension, value));
}
Expand All @@ -248,8 +259,12 @@ function resolveMessageOptions(ctx: Context, message: DescriptorProto): Code | u
const fieldsOptions: Code[] = [];
message.field.forEach((field) => {
if (field.options) {
const fieldOptions = encodedOptionsToOptions(ctx, ".google.protobuf.FieldOptions", field.options._unknownFields);
delete field.options._unknownFields;
const fieldOptions = encodedOptionsToOptions(
ctx,
".google.protobuf.FieldOptions",
(field.options as any)["_unknownFields"]
);
delete (field.options as any)["_unknownFields"];
if (fieldOptions) {
fieldsOptions.push(code`'${field.name}': ${fieldOptions}`);
}
Expand All @@ -259,8 +274,12 @@ function resolveMessageOptions(ctx: Context, message: DescriptorProto): Code | u
const oneOfsOptions: Code[] = [];
message.oneofDecl.forEach((oneOf) => {
if (oneOf.options) {
const oneOfOptions = encodedOptionsToOptions(ctx, ".google.protobuf.OneofOptions", oneOf.options._unknownFields);
delete oneOf.options._unknownFields;
const oneOfOptions = encodedOptionsToOptions(
ctx,
".google.protobuf.OneofOptions",
(oneOf.options as any)["_unknownFields"]
);
delete (oneOf.options as any)["_unknownFields"];
if (oneOfOptions) {
oneOfsOptions.push(code`'${oneOf.name}': ${oneOfOptions}`);
}
Expand All @@ -279,8 +298,12 @@ function resolveMessageOptions(ctx: Context, message: DescriptorProto): Code | u

let messageOptions: Code | undefined;
if (message.options) {
messageOptions = encodedOptionsToOptions(ctx, ".google.protobuf.MessageOptions", message.options._unknownFields);
delete message.options._unknownFields;
messageOptions = encodedOptionsToOptions(
ctx,
".google.protobuf.MessageOptions",
(message.options as any)["_unknownFields"]
);
delete (message.options as any)["_unknownFields"];
}

if (fieldsOptions.length > 0 || oneOfsOptions.length > 0 || nestedOptions.length > 0 || messageOptions) {
Expand Down

0 comments on commit c6f189e

Please sign in to comment.