Skip to content

Commit

Permalink
use changes to generate the proto descriptors
Browse files Browse the repository at this point in the history
  • Loading branch information
lukealvoeiro committed Feb 23, 2024
1 parent 350d9f6 commit eaef719
Show file tree
Hide file tree
Showing 2 changed files with 537 additions and 520 deletions.
144 changes: 69 additions & 75 deletions protos/google/protobuf/compiler/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import { FileDescriptorProto, GeneratedCodeInfo } from "../descriptor";

/** The version number of protocol compiler. */
export interface Version {
major: number;
minor: number;
patch: number;
major?: number | undefined;
minor?: number | undefined;
patch?:
| number
| undefined;
/**
* A suffix for alpha, beta or rc release, e.g., "alpha-1", "rc2". It should
* be empty for mainline stable releases.
*/
suffix: string;
suffix?: string | undefined;
_unknownFields?: { [key: number]: Uint8Array[] } | undefined;
}

Expand All @@ -25,7 +27,9 @@ export interface CodeGeneratorRequest {
*/
fileToGenerate: string[];
/** The generator parameter passed on the command-line. */
parameter: string;
parameter?:
| string
| undefined;
/**
* FileDescriptorProtos for all files in files_to_generate and everything
* they import. The files will appear in topological order, so each file
Expand All @@ -44,7 +48,7 @@ export interface CodeGeneratorRequest {
*/
protoFile: FileDescriptorProto[];
/** The version number of protocol compiler. */
compilerVersion: Version | undefined;
compilerVersion?: Version | undefined;
_unknownFields?: { [key: number]: Uint8Array[] } | undefined;
}

Expand All @@ -60,12 +64,14 @@ export interface CodeGeneratorResponse {
* unparseable -- should be reported by writing a message to stderr and
* exiting with a non-zero status code.
*/
error: string;
error?:
| string
| undefined;
/**
* A bitmask of supported features that the code generator supports.
* This is a bitwise "or" of values from the Feature enum.
*/
supportedFeatures: number;
supportedFeatures?: number | undefined;
file: CodeGeneratorResponse_File[];
_unknownFields?: { [key: number]: Uint8Array[] } | undefined;
}
Expand Down Expand Up @@ -119,7 +125,9 @@ export interface CodeGeneratorResponse_File {
* this writing protoc does not optimize for this -- it will read the entire
* CodeGeneratorResponse before writing files to disk.
*/
name: string;
name?:
| string
| undefined;
/**
* If non-empty, indicates that the named file should already exist, and the
* content here is to be inserted into that file at a defined insertion
Expand Down Expand Up @@ -159,34 +167,38 @@ export interface CodeGeneratorResponse_File {
*
* If |insertion_point| is present, |name| must also be present.
*/
insertionPoint: string;
insertionPoint?:
| string
| undefined;
/** The file contents. */
content: string;
content?:
| string
| undefined;
/**
* Information describing the file content being inserted. If an insertion
* point is used, this information will be appropriately offset and inserted
* into the code generation metadata for the generated files.
*/
generatedCodeInfo: GeneratedCodeInfo | undefined;
generatedCodeInfo?: GeneratedCodeInfo | undefined;
_unknownFields?: { [key: number]: Uint8Array[] } | undefined;
}

function createBaseVersion(): Version {
return { major: 0, minor: 0, patch: 0, suffix: "" };
return {};
}

export const Version = {
encode(message: Version, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.major !== 0) {
if (message.major !== undefined && message.major !== 0) {
writer.uint32(8).int32(message.major);
}
if (message.minor !== 0) {
if (message.minor !== undefined && message.minor !== 0) {
writer.uint32(16).int32(message.minor);
}
if (message.patch !== 0) {
if (message.patch !== undefined && message.patch !== 0) {
writer.uint32(24).int32(message.patch);
}
if (message.suffix !== "") {
if (message.suffix !== undefined && message.suffix !== "") {
writer.uint32(34).string(message.suffix);
}
if (message._unknownFields !== undefined) {
Expand Down Expand Up @@ -265,25 +277,25 @@ export const Version = {

fromJSON(object: any): Version {
return {
major: isSet(object.major) ? Number(object.major) : 0,
minor: isSet(object.minor) ? Number(object.minor) : 0,
patch: isSet(object.patch) ? Number(object.patch) : 0,
suffix: isSet(object.suffix) ? String(object.suffix) : "",
major: isSet(object.major) ? globalThis.Number(object.major) : undefined,
minor: isSet(object.minor) ? globalThis.Number(object.minor) : undefined,
patch: isSet(object.patch) ? globalThis.Number(object.patch) : undefined,
suffix: isSet(object.suffix) ? globalThis.String(object.suffix) : undefined,
};
},

toJSON(message: Version): unknown {
const obj: any = {};
if (message.major !== 0) {
if (message.major !== undefined && message.major !== 0) {
obj.major = Math.round(message.major);
}
if (message.minor !== 0) {
if (message.minor !== undefined && message.minor !== 0) {
obj.minor = Math.round(message.minor);
}
if (message.patch !== 0) {
if (message.patch !== undefined && message.patch !== 0) {
obj.patch = Math.round(message.patch);
}
if (message.suffix !== "") {
if (message.suffix !== undefined && message.suffix !== "") {
obj.suffix = message.suffix;
}
return obj;
Expand All @@ -292,7 +304,6 @@ export const Version = {
create(base?: DeepPartial<Version>): Version {
return Version.fromPartial(base ?? {});
},

fromPartial(object: DeepPartial<Version>): Version {
const message = Object.create(createBaseVersion()) as Version;
message.major = object.major ?? 0;
Expand All @@ -304,15 +315,15 @@ export const Version = {
};

function createBaseCodeGeneratorRequest(): CodeGeneratorRequest {
return { fileToGenerate: [], parameter: "", protoFile: [], compilerVersion: undefined };
return { fileToGenerate: [], protoFile: [] };
}

export const CodeGeneratorRequest = {
encode(message: CodeGeneratorRequest, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
for (const v of message.fileToGenerate) {
writer.uint32(10).string(v!);
}
if (message.parameter !== "") {
if (message.parameter !== undefined && message.parameter !== "") {
writer.uint32(18).string(message.parameter);
}
for (const v of message.protoFile) {
Expand Down Expand Up @@ -397,9 +408,11 @@ export const CodeGeneratorRequest = {

fromJSON(object: any): CodeGeneratorRequest {
return {
fileToGenerate: Array.isArray(object?.fileToGenerate) ? object.fileToGenerate.map((e: any) => String(e)) : [],
parameter: isSet(object.parameter) ? String(object.parameter) : "",
protoFile: Array.isArray(object?.protoFile)
fileToGenerate: globalThis.Array.isArray(object?.fileToGenerate)
? object.fileToGenerate.map((e: any) => globalThis.String(e))
: [],
parameter: isSet(object.parameter) ? globalThis.String(object.parameter) : undefined,
protoFile: globalThis.Array.isArray(object?.protoFile)
? object.protoFile.map((e: any) => FileDescriptorProto.fromJSON(e))
: [],
compilerVersion: isSet(object.compilerVersion) ? Version.fromJSON(object.compilerVersion) : undefined,
Expand All @@ -411,7 +424,7 @@ export const CodeGeneratorRequest = {
if (message.fileToGenerate?.length) {
obj.fileToGenerate = message.fileToGenerate;
}
if (message.parameter !== "") {
if (message.parameter !== undefined && message.parameter !== "") {
obj.parameter = message.parameter;
}
if (message.protoFile?.length) {
Expand All @@ -426,7 +439,6 @@ export const CodeGeneratorRequest = {
create(base?: DeepPartial<CodeGeneratorRequest>): CodeGeneratorRequest {
return CodeGeneratorRequest.fromPartial(base ?? {});
},

fromPartial(object: DeepPartial<CodeGeneratorRequest>): CodeGeneratorRequest {
const message = Object.create(createBaseCodeGeneratorRequest()) as CodeGeneratorRequest;
message.fileToGenerate = object.fileToGenerate?.map((e) => e) || [];
Expand All @@ -440,15 +452,15 @@ export const CodeGeneratorRequest = {
};

function createBaseCodeGeneratorResponse(): CodeGeneratorResponse {
return { error: "", supportedFeatures: 0, file: [] };
return { file: [] };
}

export const CodeGeneratorResponse = {
encode(message: CodeGeneratorResponse, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.error !== "") {
if (message.error !== undefined && message.error !== "") {
writer.uint32(10).string(message.error);
}
if (message.supportedFeatures !== 0) {
if (message.supportedFeatures !== undefined && message.supportedFeatures !== 0) {
writer.uint32(16).uint64(message.supportedFeatures);
}
for (const v of message.file) {
Expand Down Expand Up @@ -523,18 +535,20 @@ export const CodeGeneratorResponse = {

fromJSON(object: any): CodeGeneratorResponse {
return {
error: isSet(object.error) ? String(object.error) : "",
supportedFeatures: isSet(object.supportedFeatures) ? Number(object.supportedFeatures) : 0,
file: Array.isArray(object?.file) ? object.file.map((e: any) => CodeGeneratorResponse_File.fromJSON(e)) : [],
error: isSet(object.error) ? globalThis.String(object.error) : undefined,
supportedFeatures: isSet(object.supportedFeatures) ? globalThis.Number(object.supportedFeatures) : undefined,
file: globalThis.Array.isArray(object?.file)
? object.file.map((e: any) => CodeGeneratorResponse_File.fromJSON(e))
: [],
};
},

toJSON(message: CodeGeneratorResponse): unknown {
const obj: any = {};
if (message.error !== "") {
if (message.error !== undefined && message.error !== "") {
obj.error = message.error;
}
if (message.supportedFeatures !== 0) {
if (message.supportedFeatures !== undefined && message.supportedFeatures !== 0) {
obj.supportedFeatures = Math.round(message.supportedFeatures);
}
if (message.file?.length) {
Expand All @@ -546,7 +560,6 @@ export const CodeGeneratorResponse = {
create(base?: DeepPartial<CodeGeneratorResponse>): CodeGeneratorResponse {
return CodeGeneratorResponse.fromPartial(base ?? {});
},

fromPartial(object: DeepPartial<CodeGeneratorResponse>): CodeGeneratorResponse {
const message = Object.create(createBaseCodeGeneratorResponse()) as CodeGeneratorResponse;
message.error = object.error ?? "";
Expand All @@ -557,18 +570,18 @@ export const CodeGeneratorResponse = {
};

function createBaseCodeGeneratorResponse_File(): CodeGeneratorResponse_File {
return { name: "", insertionPoint: "", content: "", generatedCodeInfo: undefined };
return {};
}

export const CodeGeneratorResponse_File = {
encode(message: CodeGeneratorResponse_File, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer {
if (message.name !== "") {
if (message.name !== undefined && message.name !== "") {
writer.uint32(10).string(message.name);
}
if (message.insertionPoint !== "") {
if (message.insertionPoint !== undefined && message.insertionPoint !== "") {
writer.uint32(18).string(message.insertionPoint);
}
if (message.content !== "") {
if (message.content !== undefined && message.content !== "") {
writer.uint32(122).string(message.content);
}
if (message.generatedCodeInfo !== undefined) {
Expand Down Expand Up @@ -650,9 +663,9 @@ export const CodeGeneratorResponse_File = {

fromJSON(object: any): CodeGeneratorResponse_File {
return {
name: isSet(object.name) ? String(object.name) : "",
insertionPoint: isSet(object.insertionPoint) ? String(object.insertionPoint) : "",
content: isSet(object.content) ? String(object.content) : "",
name: isSet(object.name) ? globalThis.String(object.name) : undefined,
insertionPoint: isSet(object.insertionPoint) ? globalThis.String(object.insertionPoint) : undefined,
content: isSet(object.content) ? globalThis.String(object.content) : undefined,
generatedCodeInfo: isSet(object.generatedCodeInfo)
? GeneratedCodeInfo.fromJSON(object.generatedCodeInfo)
: undefined,
Expand All @@ -661,13 +674,13 @@ export const CodeGeneratorResponse_File = {

toJSON(message: CodeGeneratorResponse_File): unknown {
const obj: any = {};
if (message.name !== "") {
if (message.name !== undefined && message.name !== "") {
obj.name = message.name;
}
if (message.insertionPoint !== "") {
if (message.insertionPoint !== undefined && message.insertionPoint !== "") {
obj.insertionPoint = message.insertionPoint;
}
if (message.content !== "") {
if (message.content !== undefined && message.content !== "") {
obj.content = message.content;
}
if (message.generatedCodeInfo !== undefined) {
Expand All @@ -679,7 +692,6 @@ export const CodeGeneratorResponse_File = {
create(base?: DeepPartial<CodeGeneratorResponse_File>): CodeGeneratorResponse_File {
return CodeGeneratorResponse_File.fromPartial(base ?? {});
},

fromPartial(object: DeepPartial<CodeGeneratorResponse_File>): CodeGeneratorResponse_File {
const message = Object.create(createBaseCodeGeneratorResponse_File()) as CodeGeneratorResponse_File;
message.name = object.name ?? "";
Expand All @@ -692,35 +704,17 @@ export const CodeGeneratorResponse_File = {
},
};

declare const self: any | undefined;
declare const window: any | undefined;
declare const global: any | undefined;
const tsProtoGlobalThis: any = (() => {
if (typeof globalThis !== "undefined") {
return globalThis;
}
if (typeof self !== "undefined") {
return self;
}
if (typeof window !== "undefined") {
return window;
}
if (typeof global !== "undefined") {
return global;
}
throw "Unable to locate global object";
})();

type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;

type DeepPartial<T> = T extends Builtin ? T
: T extends Array<infer U> ? Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>>
: T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>>
: T extends {} ? { [K in keyof T]?: DeepPartial<T[K]> }
: Partial<T>;

function longToNumber(long: Long): number {
if (long.gt(Number.MAX_SAFE_INTEGER)) {
throw new tsProtoGlobalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
if (long.gt(globalThis.Number.MAX_SAFE_INTEGER)) {
throw new globalThis.Error("Value is larger than Number.MAX_SAFE_INTEGER");
}
return long.toNumber();
}
Expand Down
Loading

0 comments on commit eaef719

Please sign in to comment.