Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add interface for static message methods #1104

Merged
merged 1 commit into from
Sep 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions integration/affixes/affixes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function createBasePrefixAwesomeMessageSuffix(): PrefixAwesomeMessageSuffix {
return {};
}

export const PrefixAwesomeMessageSuffix = {
export const PrefixAwesomeMessageSuffix: MessageFns<PrefixAwesomeMessageSuffix> = {
encode(_: PrefixAwesomeMessageSuffix, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
return writer;
},
Expand Down Expand Up @@ -98,7 +98,7 @@ function createBasePrefixAwesomeMessage_InnerSuffix(): PrefixAwesomeMessage_Inne
return {};
}

export const PrefixAwesomeMessage_InnerSuffix = {
export const PrefixAwesomeMessage_InnerSuffix: MessageFns<PrefixAwesomeMessage_InnerSuffix> = {
encode(_: PrefixAwesomeMessage_InnerSuffix, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
return writer;
},
Expand Down Expand Up @@ -169,3 +169,12 @@ export type DeepPartial<T> = T extends Builtin ? T
type KeysOfUnion<T> = T extends T ? keyof T : never;
export type Exact<P, I extends P> = P extends Builtin ? P
: P & { [K in keyof P]: Exact<P[K], I[K]> } & { [K in Exclude<keyof I, KeysOfUnion<P>>]: never };

export interface MessageFns<T> {
encode(message: T, writer?: BinaryWriter): BinaryWriter;
decode(input: BinaryReader | Uint8Array, length?: number): T;
fromJSON(object: any): T;
toJSON(message: T): unknown;
create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
}
11 changes: 10 additions & 1 deletion integration/angular/simple-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function createBaseSimpleMessage(): SimpleMessage {
return { numberField: 0 };
}

export const SimpleMessage = {
export const SimpleMessage: MessageFns<SimpleMessage> = {
encode(message: SimpleMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.numberField !== 0) {
writer.uint32(8).int32(message.numberField);
Expand Down Expand Up @@ -82,3 +82,12 @@ export type Exact<P, I extends P> = P extends Builtin ? P
function isSet(value: any): boolean {
return value !== null && value !== undefined;
}

export interface MessageFns<T> {
encode(message: T, writer?: BinaryWriter): BinaryWriter;
decode(input: BinaryReader | Uint8Array, length?: number): T;
fromJSON(object: any): T;
toJSON(message: T): unknown;
create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
}
15 changes: 14 additions & 1 deletion integration/async-iterable-services-abort-signal/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function createBaseEchoMsg(): EchoMsg {
return { body: "" };
}

export const EchoMsg = {
export const EchoMsg: MessageFns<EchoMsg> = {
encode(message: EchoMsg, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.body !== "") {
writer.uint32(10).string(message.body);
Expand Down Expand Up @@ -191,3 +191,16 @@ export type Exact<P, I extends P> = P extends Builtin ? P
function isSet(value: any): boolean {
return value !== null && value !== undefined;
}

export interface MessageFns<T> {
encode(message: T, writer?: BinaryWriter): BinaryWriter;
decode(input: BinaryReader | Uint8Array, length?: number): T;
encodeTransform(source: AsyncIterable<T | T[]> | Iterable<T | T[]>): AsyncIterable<Uint8Array>;
decodeTransform(
source: AsyncIterable<Uint8Array | Uint8Array[]> | Iterable<Uint8Array | Uint8Array[]>,
): AsyncIterable<T>;
fromJSON(object: any): T;
toJSON(message: T): unknown;
create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
}
15 changes: 14 additions & 1 deletion integration/async-iterable-services/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function createBaseEchoMsg(): EchoMsg {
return { body: "" };
}

export const EchoMsg = {
export const EchoMsg: MessageFns<EchoMsg> = {
encode(message: EchoMsg, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.body !== "") {
writer.uint32(10).string(message.body);
Expand Down Expand Up @@ -175,3 +175,16 @@ export type Exact<P, I extends P> = P extends Builtin ? P
function isSet(value: any): boolean {
return value !== null && value !== undefined;
}

export interface MessageFns<T> {
encode(message: T, writer?: BinaryWriter): BinaryWriter;
decode(input: BinaryReader | Uint8Array, length?: number): T;
encodeTransform(source: AsyncIterable<T | T[]> | Iterable<T | T[]>): AsyncIterable<Uint8Array>;
decodeTransform(
source: AsyncIterable<Uint8Array | Uint8Array[]> | Iterable<Uint8Array | Uint8Array[]>,
): AsyncIterable<T>;
fromJSON(object: any): T;
toJSON(message: T): unknown;
create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
}
11 changes: 10 additions & 1 deletion integration/avoid-import-conflicts-folder-name/ui.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ function createBaseSimple(): Simple {
return { simple2Name: "", simple2Age: 0 };
}

export const Simple = {
export const Simple: MessageFns<Simple> = {
encode(message: Simple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.simple2Name !== "") {
writer.uint32(10).string(message.simple2Name);
Expand Down Expand Up @@ -139,3 +139,12 @@ export type Exact<P, I extends P> = P extends Builtin ? P
function isSet(value: any): boolean {
return value !== null && value !== undefined;
}

export interface MessageFns<T> {
encode(message: T, writer?: BinaryWriter): BinaryWriter;
decode(input: BinaryReader | Uint8Array, length?: number): T;
fromJSON(object: any): T;
toJSON(message: T): unknown;
create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
}
13 changes: 11 additions & 2 deletions integration/avoid-import-conflicts-folder-name/ui/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function createBaseSimple(): Simple {
return { name: "", otherSimple: undefined };
}

export const Simple = {
export const Simple: MessageFns<Simple> = {
encode(message: Simple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.name !== "") {
writer.uint32(10).string(message.name);
Expand Down Expand Up @@ -141,7 +141,7 @@ function createBaseSimpleEnums(): SimpleEnums {
return { localEnum: 0, importEnum: 0 };
}

export const SimpleEnums = {
export const SimpleEnums: MessageFns<SimpleEnums> = {
encode(message: SimpleEnums, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.localEnum !== 0) {
writer.uint32(8).int32(message.localEnum);
Expand Down Expand Up @@ -226,3 +226,12 @@ export type Exact<P, I extends P> = P extends Builtin ? P
function isSet(value: any): boolean {
return value !== null && value !== undefined;
}

export interface MessageFns<T> {
encode(message: T, writer?: BinaryWriter): BinaryWriter;
decode(input: BinaryReader | Uint8Array, length?: number): T;
fromJSON(object: any): T;
toJSON(message: T): unknown;
create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
}
19 changes: 14 additions & 5 deletions integration/avoid-import-conflicts/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ function createBaseSimple(): Simple {
return { name: "", otherSimple: undefined };
}

export const Simple = {
export const Simple: MessageFns<Simple> = {
encode(message: Simple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.name !== "") {
writer.uint32(10).string(message.name);
Expand Down Expand Up @@ -157,7 +157,7 @@ function createBaseDifferentSimple(): DifferentSimple {
return { name: "", otherOptionalSimple2: undefined };
}

export const DifferentSimple = {
export const DifferentSimple: MessageFns<DifferentSimple> = {
encode(message: DifferentSimple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.name !== "") {
writer.uint32(10).string(message.name);
Expand Down Expand Up @@ -235,7 +235,7 @@ function createBaseSimpleEnums(): SimpleEnums {
return { localEnum: 0, importEnum: 0 };
}

export const SimpleEnums = {
export const SimpleEnums: MessageFns<SimpleEnums> = {
encode(message: SimpleEnums, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.localEnum !== 0) {
writer.uint32(8).int32(message.localEnum);
Expand Down Expand Up @@ -309,7 +309,7 @@ function createBaseFooServiceCreateRequest(): FooServiceCreateRequest {
return { kind: 0 };
}

export const FooServiceCreateRequest = {
export const FooServiceCreateRequest: MessageFns<FooServiceCreateRequest> = {
encode(message: FooServiceCreateRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.kind !== 0) {
writer.uint32(8).int32(message.kind);
Expand Down Expand Up @@ -366,7 +366,7 @@ function createBaseFooServiceCreateResponse(): FooServiceCreateResponse {
return { kind: 0 };
}

export const FooServiceCreateResponse = {
export const FooServiceCreateResponse: MessageFns<FooServiceCreateResponse> = {
encode(message: FooServiceCreateResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.kind !== 0) {
writer.uint32(8).int32(message.kind);
Expand Down Expand Up @@ -458,3 +458,12 @@ export type Exact<P, I extends P> = P extends Builtin ? P
function isSet(value: any): boolean {
return value !== null && value !== undefined;
}

export interface MessageFns<T> {
encode(message: T, writer?: BinaryWriter): BinaryWriter;
decode(input: BinaryReader | Uint8Array, length?: number): T;
fromJSON(object: any): T;
toJSON(message: T): unknown;
create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
}
11 changes: 10 additions & 1 deletion integration/avoid-import-conflicts/simple2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function createBaseSimple(): Simple {
return { name: "", age: 0 };
}

export const Simple = {
export const Simple: MessageFns<Simple> = {
encode(message: Simple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.name !== "") {
writer.uint32(10).string(message.name);
Expand Down Expand Up @@ -178,3 +178,12 @@ export type Exact<P, I extends P> = P extends Builtin ? P
function isSet(value: any): boolean {
return value !== null && value !== undefined;
}

export interface MessageFns<T> {
encode(message: T, writer?: BinaryWriter): BinaryWriter;
decode(input: BinaryReader | Uint8Array, length?: number): T;
fromJSON(object: any): T;
toJSON(message: T): unknown;
create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
}
11 changes: 10 additions & 1 deletion integration/barrel-imports/bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function createBaseBar(): Bar {
return { name: "", age: 0 };
}

export const Bar = {
export const Bar: MessageFns<Bar> = {
encode(message: Bar, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.name !== "") {
writer.uint32(10).string(message.name);
Expand Down Expand Up @@ -98,3 +98,12 @@ type Exact<P, I extends P> = P extends Builtin ? P
function isSet(value: any): boolean {
return value !== null && value !== undefined;
}

interface MessageFns<T> {
encode(message: T, writer?: BinaryWriter): BinaryWriter;
decode(input: BinaryReader | Uint8Array, length?: number): T;
fromJSON(object: any): T;
toJSON(message: T): unknown;
create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
}
11 changes: 10 additions & 1 deletion integration/barrel-imports/foo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ function createBaseFoo(): Foo {
return { name: "", bar: undefined };
}

export const Foo = {
export const Foo: MessageFns<Foo> = {
encode(message: Foo, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.name !== "") {
writer.uint32(10).string(message.name);
Expand Down Expand Up @@ -99,3 +99,12 @@ type Exact<P, I extends P> = P extends Builtin ? P
function isSet(value: any): boolean {
return value !== null && value !== undefined;
}

interface MessageFns<T> {
encode(message: T, writer?: BinaryWriter): BinaryWriter;
decode(input: BinaryReader | Uint8Array, length?: number): T;
fromJSON(object: any): T;
toJSON(message: T): unknown;
create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
}
29 changes: 19 additions & 10 deletions integration/batching-with-context-esModuleInterop/batching.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function createBaseBatchQueryRequest(): BatchQueryRequest {
return { ids: [] };
}

export const BatchQueryRequest = {
export const BatchQueryRequest: MessageFns<BatchQueryRequest> = {
encode(message: BatchQueryRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
for (const v of message.ids) {
writer.uint32(10).string(v!);
Expand Down Expand Up @@ -110,7 +110,7 @@ function createBaseBatchQueryResponse(): BatchQueryResponse {
return { entities: [] };
}

export const BatchQueryResponse = {
export const BatchQueryResponse: MessageFns<BatchQueryResponse> = {
encode(message: BatchQueryResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
for (const v of message.entities) {
Entity.encode(v!, writer.uint32(10).fork()).join();
Expand Down Expand Up @@ -169,7 +169,7 @@ function createBaseBatchMapQueryRequest(): BatchMapQueryRequest {
return { ids: [] };
}

export const BatchMapQueryRequest = {
export const BatchMapQueryRequest: MessageFns<BatchMapQueryRequest> = {
encode(message: BatchMapQueryRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
for (const v of message.ids) {
writer.uint32(10).string(v!);
Expand Down Expand Up @@ -226,7 +226,7 @@ function createBaseBatchMapQueryResponse(): BatchMapQueryResponse {
return { entities: {} };
}

export const BatchMapQueryResponse = {
export const BatchMapQueryResponse: MessageFns<BatchMapQueryResponse> = {
encode(message: BatchMapQueryResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
Object.entries(message.entities).forEach(([key, value]) => {
BatchMapQueryResponse_EntitiesEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).join();
Expand Down Expand Up @@ -304,7 +304,7 @@ function createBaseBatchMapQueryResponse_EntitiesEntry(): BatchMapQueryResponse_
return { key: "", value: undefined };
}

export const BatchMapQueryResponse_EntitiesEntry = {
export const BatchMapQueryResponse_EntitiesEntry: MessageFns<BatchMapQueryResponse_EntitiesEntry> = {
encode(message: BatchMapQueryResponse_EntitiesEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.key !== "") {
writer.uint32(10).string(message.key);
Expand Down Expand Up @@ -384,7 +384,7 @@ function createBaseGetOnlyMethodRequest(): GetOnlyMethodRequest {
return { id: "" };
}

export const GetOnlyMethodRequest = {
export const GetOnlyMethodRequest: MessageFns<GetOnlyMethodRequest> = {
encode(message: GetOnlyMethodRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.id !== "") {
writer.uint32(10).string(message.id);
Expand Down Expand Up @@ -441,7 +441,7 @@ function createBaseGetOnlyMethodResponse(): GetOnlyMethodResponse {
return { entity: undefined };
}

export const GetOnlyMethodResponse = {
export const GetOnlyMethodResponse: MessageFns<GetOnlyMethodResponse> = {
encode(message: GetOnlyMethodResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.entity !== undefined) {
Entity.encode(message.entity, writer.uint32(10).fork()).join();
Expand Down Expand Up @@ -500,7 +500,7 @@ function createBaseWriteMethodRequest(): WriteMethodRequest {
return { id: "" };
}

export const WriteMethodRequest = {
export const WriteMethodRequest: MessageFns<WriteMethodRequest> = {
encode(message: WriteMethodRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.id !== "") {
writer.uint32(10).string(message.id);
Expand Down Expand Up @@ -557,7 +557,7 @@ function createBaseWriteMethodResponse(): WriteMethodResponse {
return {};
}

export const WriteMethodResponse = {
export const WriteMethodResponse: MessageFns<WriteMethodResponse> = {
encode(_: WriteMethodResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
return writer;
},
Expand Down Expand Up @@ -600,7 +600,7 @@ function createBaseEntity(): Entity {
return { id: "", name: "" };
}

export const Entity = {
export const Entity: MessageFns<Entity> = {
encode(message: Entity, writer: BinaryWriter = new BinaryWriter()): BinaryWriter {
if (message.id !== "") {
writer.uint32(10).string(message.id);
Expand Down Expand Up @@ -784,3 +784,12 @@ function isSet(value: any): boolean {
function fail(message?: string): never {
throw new globalThis.Error(message ?? "Failed");
}

export interface MessageFns<T> {
encode(message: T, writer?: BinaryWriter): BinaryWriter;
decode(input: BinaryReader | Uint8Array, length?: number): T;
fromJSON(object: any): T;
toJSON(message: T): unknown;
create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
}
Loading
Loading