diff --git a/integration/affixes/affixes.ts b/integration/affixes/affixes.ts index ce1968ca2..593b4853b 100644 --- a/integration/affixes/affixes.ts +++ b/integration/affixes/affixes.ts @@ -55,7 +55,7 @@ function createBasePrefixAwesomeMessageSuffix(): PrefixAwesomeMessageSuffix { return {}; } -export const PrefixAwesomeMessageSuffix = { +export const PrefixAwesomeMessageSuffix: MessageFns = { encode(_: PrefixAwesomeMessageSuffix, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -98,7 +98,7 @@ function createBasePrefixAwesomeMessage_InnerSuffix(): PrefixAwesomeMessage_Inne return {}; } -export const PrefixAwesomeMessage_InnerSuffix = { +export const PrefixAwesomeMessage_InnerSuffix: MessageFns = { encode(_: PrefixAwesomeMessage_InnerSuffix, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -169,3 +169,12 @@ export type DeepPartial = T extends Builtin ? T type KeysOfUnion = T extends T ? keyof T : never; export type Exact = P extends Builtin ? P : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/angular/simple-message.ts b/integration/angular/simple-message.ts index 162096a40..a598ffbf8 100644 --- a/integration/angular/simple-message.ts +++ b/integration/angular/simple-message.ts @@ -14,7 +14,7 @@ function createBaseSimpleMessage(): SimpleMessage { return { numberField: 0 }; } -export const SimpleMessage = { +export const SimpleMessage: MessageFns = { encode(message: SimpleMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.numberField !== 0) { writer.uint32(8).int32(message.numberField); @@ -82,3 +82,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/async-iterable-services-abort-signal/simple.ts b/integration/async-iterable-services-abort-signal/simple.ts index 0ea35e68e..98590967e 100644 --- a/integration/async-iterable-services-abort-signal/simple.ts +++ b/integration/async-iterable-services-abort-signal/simple.ts @@ -15,7 +15,7 @@ function createBaseEchoMsg(): EchoMsg { return { body: "" }; } -export const EchoMsg = { +export const EchoMsg: MessageFns = { encode(message: EchoMsg, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.body !== "") { writer.uint32(10).string(message.body); @@ -191,3 +191,16 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + encodeTransform(source: AsyncIterable | Iterable): AsyncIterable; + decodeTransform( + source: AsyncIterable | Iterable, + ): AsyncIterable; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/async-iterable-services/simple.ts b/integration/async-iterable-services/simple.ts index 6a1f03b9c..fa72aa227 100644 --- a/integration/async-iterable-services/simple.ts +++ b/integration/async-iterable-services/simple.ts @@ -15,7 +15,7 @@ function createBaseEchoMsg(): EchoMsg { return { body: "" }; } -export const EchoMsg = { +export const EchoMsg: MessageFns = { encode(message: EchoMsg, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.body !== "") { writer.uint32(10).string(message.body); @@ -175,3 +175,16 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + encodeTransform(source: AsyncIterable | Iterable): AsyncIterable; + decodeTransform( + source: AsyncIterable | Iterable, + ): AsyncIterable; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/avoid-import-conflicts-folder-name/ui.ts b/integration/avoid-import-conflicts-folder-name/ui.ts index 707b77d33..d32f8726e 100644 --- a/integration/avoid-import-conflicts-folder-name/ui.ts +++ b/integration/avoid-import-conflicts-folder-name/ui.ts @@ -54,7 +54,7 @@ function createBaseSimple(): Simple { return { simple2Name: "", simple2Age: 0 }; } -export const Simple = { +export const Simple: MessageFns = { encode(message: Simple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.simple2Name !== "") { writer.uint32(10).string(message.simple2Name); @@ -139,3 +139,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/avoid-import-conflicts-folder-name/ui/simple.ts b/integration/avoid-import-conflicts-folder-name/ui/simple.ts index b1f34013b..a0cd205cb 100644 --- a/integration/avoid-import-conflicts-folder-name/ui/simple.ts +++ b/integration/avoid-import-conflicts-folder-name/ui/simple.ts @@ -65,7 +65,7 @@ function createBaseSimple(): Simple { return { name: "", otherSimple: undefined }; } -export const Simple = { +export const Simple: MessageFns = { encode(message: Simple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -141,7 +141,7 @@ function createBaseSimpleEnums(): SimpleEnums { return { localEnum: 0, importEnum: 0 }; } -export const SimpleEnums = { +export const SimpleEnums: MessageFns = { encode(message: SimpleEnums, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.localEnum !== 0) { writer.uint32(8).int32(message.localEnum); @@ -226,3 +226,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/avoid-import-conflicts/simple.ts b/integration/avoid-import-conflicts/simple.ts index f2cd9a94d..647e7293d 100644 --- a/integration/avoid-import-conflicts/simple.ts +++ b/integration/avoid-import-conflicts/simple.ts @@ -81,7 +81,7 @@ function createBaseSimple(): Simple { return { name: "", otherSimple: undefined }; } -export const Simple = { +export const Simple: MessageFns = { encode(message: Simple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -157,7 +157,7 @@ function createBaseDifferentSimple(): DifferentSimple { return { name: "", otherOptionalSimple2: undefined }; } -export const DifferentSimple = { +export const DifferentSimple: MessageFns = { encode(message: DifferentSimple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -235,7 +235,7 @@ function createBaseSimpleEnums(): SimpleEnums { return { localEnum: 0, importEnum: 0 }; } -export const SimpleEnums = { +export const SimpleEnums: MessageFns = { encode(message: SimpleEnums, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.localEnum !== 0) { writer.uint32(8).int32(message.localEnum); @@ -309,7 +309,7 @@ function createBaseFooServiceCreateRequest(): FooServiceCreateRequest { return { kind: 0 }; } -export const FooServiceCreateRequest = { +export const FooServiceCreateRequest: MessageFns = { encode(message: FooServiceCreateRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.kind !== 0) { writer.uint32(8).int32(message.kind); @@ -366,7 +366,7 @@ function createBaseFooServiceCreateResponse(): FooServiceCreateResponse { return { kind: 0 }; } -export const FooServiceCreateResponse = { +export const FooServiceCreateResponse: MessageFns = { encode(message: FooServiceCreateResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.kind !== 0) { writer.uint32(8).int32(message.kind); @@ -458,3 +458,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/avoid-import-conflicts/simple2.ts b/integration/avoid-import-conflicts/simple2.ts index 4d7a9d603..5947c12b0 100644 --- a/integration/avoid-import-conflicts/simple2.ts +++ b/integration/avoid-import-conflicts/simple2.ts @@ -93,7 +93,7 @@ function createBaseSimple(): Simple { return { name: "", age: 0 }; } -export const Simple = { +export const Simple: MessageFns = { encode(message: Simple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -178,3 +178,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/barrel-imports/bar.ts b/integration/barrel-imports/bar.ts index fb830f710..1c636fd0c 100644 --- a/integration/barrel-imports/bar.ts +++ b/integration/barrel-imports/bar.ts @@ -13,7 +13,7 @@ function createBaseBar(): Bar { return { name: "", age: 0 }; } -export const Bar = { +export const Bar: MessageFns = { encode(message: Bar, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -98,3 +98,12 @@ type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/barrel-imports/foo.ts b/integration/barrel-imports/foo.ts index b7c8ca258..55885c219 100644 --- a/integration/barrel-imports/foo.ts +++ b/integration/barrel-imports/foo.ts @@ -14,7 +14,7 @@ function createBaseFoo(): Foo { return { name: "", bar: undefined }; } -export const Foo = { +export const Foo: MessageFns = { encode(message: Foo, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -99,3 +99,12 @@ type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/batching-with-context-esModuleInterop/batching.ts b/integration/batching-with-context-esModuleInterop/batching.ts index 21181a9ae..2bae08689 100644 --- a/integration/batching-with-context-esModuleInterop/batching.ts +++ b/integration/batching-with-context-esModuleInterop/batching.ts @@ -53,7 +53,7 @@ function createBaseBatchQueryRequest(): BatchQueryRequest { return { ids: [] }; } -export const BatchQueryRequest = { +export const BatchQueryRequest: MessageFns = { encode(message: BatchQueryRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.ids) { writer.uint32(10).string(v!); @@ -110,7 +110,7 @@ function createBaseBatchQueryResponse(): BatchQueryResponse { return { entities: [] }; } -export const BatchQueryResponse = { +export const BatchQueryResponse: MessageFns = { encode(message: BatchQueryResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.entities) { Entity.encode(v!, writer.uint32(10).fork()).join(); @@ -169,7 +169,7 @@ function createBaseBatchMapQueryRequest(): BatchMapQueryRequest { return { ids: [] }; } -export const BatchMapQueryRequest = { +export const BatchMapQueryRequest: MessageFns = { encode(message: BatchMapQueryRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.ids) { writer.uint32(10).string(v!); @@ -226,7 +226,7 @@ function createBaseBatchMapQueryResponse(): BatchMapQueryResponse { return { entities: {} }; } -export const BatchMapQueryResponse = { +export const BatchMapQueryResponse: MessageFns = { 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(); @@ -304,7 +304,7 @@ function createBaseBatchMapQueryResponse_EntitiesEntry(): BatchMapQueryResponse_ return { key: "", value: undefined }; } -export const BatchMapQueryResponse_EntitiesEntry = { +export const BatchMapQueryResponse_EntitiesEntry: MessageFns = { encode(message: BatchMapQueryResponse_EntitiesEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -384,7 +384,7 @@ function createBaseGetOnlyMethodRequest(): GetOnlyMethodRequest { return { id: "" }; } -export const GetOnlyMethodRequest = { +export const GetOnlyMethodRequest: MessageFns = { encode(message: GetOnlyMethodRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== "") { writer.uint32(10).string(message.id); @@ -441,7 +441,7 @@ function createBaseGetOnlyMethodResponse(): GetOnlyMethodResponse { return { entity: undefined }; } -export const GetOnlyMethodResponse = { +export const GetOnlyMethodResponse: MessageFns = { encode(message: GetOnlyMethodResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.entity !== undefined) { Entity.encode(message.entity, writer.uint32(10).fork()).join(); @@ -500,7 +500,7 @@ function createBaseWriteMethodRequest(): WriteMethodRequest { return { id: "" }; } -export const WriteMethodRequest = { +export const WriteMethodRequest: MessageFns = { encode(message: WriteMethodRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== "") { writer.uint32(10).string(message.id); @@ -557,7 +557,7 @@ function createBaseWriteMethodResponse(): WriteMethodResponse { return {}; } -export const WriteMethodResponse = { +export const WriteMethodResponse: MessageFns = { encode(_: WriteMethodResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -600,7 +600,7 @@ function createBaseEntity(): Entity { return { id: "", name: "" }; } -export const Entity = { +export const Entity: MessageFns = { encode(message: Entity, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== "") { writer.uint32(10).string(message.id); @@ -784,3 +784,12 @@ function isSet(value: any): boolean { function fail(message?: string): never { throw new globalThis.Error(message ?? "Failed"); } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/batching-with-context/batching.ts b/integration/batching-with-context/batching.ts index fed5be70e..f7544dd19 100644 --- a/integration/batching-with-context/batching.ts +++ b/integration/batching-with-context/batching.ts @@ -53,7 +53,7 @@ function createBaseBatchQueryRequest(): BatchQueryRequest { return { ids: [] }; } -export const BatchQueryRequest = { +export const BatchQueryRequest: MessageFns = { encode(message: BatchQueryRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.ids) { writer.uint32(10).string(v!); @@ -110,7 +110,7 @@ function createBaseBatchQueryResponse(): BatchQueryResponse { return { entities: [] }; } -export const BatchQueryResponse = { +export const BatchQueryResponse: MessageFns = { encode(message: BatchQueryResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.entities) { Entity.encode(v!, writer.uint32(10).fork()).join(); @@ -169,7 +169,7 @@ function createBaseBatchMapQueryRequest(): BatchMapQueryRequest { return { ids: [] }; } -export const BatchMapQueryRequest = { +export const BatchMapQueryRequest: MessageFns = { encode(message: BatchMapQueryRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.ids) { writer.uint32(10).string(v!); @@ -226,7 +226,7 @@ function createBaseBatchMapQueryResponse(): BatchMapQueryResponse { return { entities: {} }; } -export const BatchMapQueryResponse = { +export const BatchMapQueryResponse: MessageFns = { 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(); @@ -304,7 +304,7 @@ function createBaseBatchMapQueryResponse_EntitiesEntry(): BatchMapQueryResponse_ return { key: "", value: undefined }; } -export const BatchMapQueryResponse_EntitiesEntry = { +export const BatchMapQueryResponse_EntitiesEntry: MessageFns = { encode(message: BatchMapQueryResponse_EntitiesEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -384,7 +384,7 @@ function createBaseGetOnlyMethodRequest(): GetOnlyMethodRequest { return { id: "" }; } -export const GetOnlyMethodRequest = { +export const GetOnlyMethodRequest: MessageFns = { encode(message: GetOnlyMethodRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== "") { writer.uint32(10).string(message.id); @@ -441,7 +441,7 @@ function createBaseGetOnlyMethodResponse(): GetOnlyMethodResponse { return { entity: undefined }; } -export const GetOnlyMethodResponse = { +export const GetOnlyMethodResponse: MessageFns = { encode(message: GetOnlyMethodResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.entity !== undefined) { Entity.encode(message.entity, writer.uint32(10).fork()).join(); @@ -500,7 +500,7 @@ function createBaseWriteMethodRequest(): WriteMethodRequest { return { id: "" }; } -export const WriteMethodRequest = { +export const WriteMethodRequest: MessageFns = { encode(message: WriteMethodRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== "") { writer.uint32(10).string(message.id); @@ -557,7 +557,7 @@ function createBaseWriteMethodResponse(): WriteMethodResponse { return {}; } -export const WriteMethodResponse = { +export const WriteMethodResponse: MessageFns = { encode(_: WriteMethodResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -600,7 +600,7 @@ function createBaseEntity(): Entity { return { id: "", name: "" }; } -export const Entity = { +export const Entity: MessageFns = { encode(message: Entity, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== "") { writer.uint32(10).string(message.id); @@ -784,3 +784,12 @@ function isSet(value: any): boolean { function fail(message?: string): never { throw new globalThis.Error(message ?? "Failed"); } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/batching/batching.ts b/integration/batching/batching.ts index 0f590e60e..6ed5754b6 100644 --- a/integration/batching/batching.ts +++ b/integration/batching/batching.ts @@ -51,7 +51,7 @@ function createBaseBatchQueryRequest(): BatchQueryRequest { return { ids: [] }; } -export const BatchQueryRequest = { +export const BatchQueryRequest: MessageFns = { encode(message: BatchQueryRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.ids) { writer.uint32(10).string(v!); @@ -108,7 +108,7 @@ function createBaseBatchQueryResponse(): BatchQueryResponse { return { entities: [] }; } -export const BatchQueryResponse = { +export const BatchQueryResponse: MessageFns = { encode(message: BatchQueryResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.entities) { Entity.encode(v!, writer.uint32(10).fork()).join(); @@ -167,7 +167,7 @@ function createBaseBatchMapQueryRequest(): BatchMapQueryRequest { return { ids: [] }; } -export const BatchMapQueryRequest = { +export const BatchMapQueryRequest: MessageFns = { encode(message: BatchMapQueryRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.ids) { writer.uint32(10).string(v!); @@ -224,7 +224,7 @@ function createBaseBatchMapQueryResponse(): BatchMapQueryResponse { return { entities: {} }; } -export const BatchMapQueryResponse = { +export const BatchMapQueryResponse: MessageFns = { 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(); @@ -302,7 +302,7 @@ function createBaseBatchMapQueryResponse_EntitiesEntry(): BatchMapQueryResponse_ return { key: "", value: undefined }; } -export const BatchMapQueryResponse_EntitiesEntry = { +export const BatchMapQueryResponse_EntitiesEntry: MessageFns = { encode(message: BatchMapQueryResponse_EntitiesEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -382,7 +382,7 @@ function createBaseGetOnlyMethodRequest(): GetOnlyMethodRequest { return { id: "" }; } -export const GetOnlyMethodRequest = { +export const GetOnlyMethodRequest: MessageFns = { encode(message: GetOnlyMethodRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== "") { writer.uint32(10).string(message.id); @@ -439,7 +439,7 @@ function createBaseGetOnlyMethodResponse(): GetOnlyMethodResponse { return { entity: undefined }; } -export const GetOnlyMethodResponse = { +export const GetOnlyMethodResponse: MessageFns = { encode(message: GetOnlyMethodResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.entity !== undefined) { Entity.encode(message.entity, writer.uint32(10).fork()).join(); @@ -498,7 +498,7 @@ function createBaseWriteMethodRequest(): WriteMethodRequest { return { id: "" }; } -export const WriteMethodRequest = { +export const WriteMethodRequest: MessageFns = { encode(message: WriteMethodRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== "") { writer.uint32(10).string(message.id); @@ -555,7 +555,7 @@ function createBaseWriteMethodResponse(): WriteMethodResponse { return {}; } -export const WriteMethodResponse = { +export const WriteMethodResponse: MessageFns = { encode(_: WriteMethodResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -598,7 +598,7 @@ function createBaseEntity(): Entity { return { id: "", name: "" }; } -export const Entity = { +export const Entity: MessageFns = { encode(message: Entity, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== "") { writer.uint32(10).string(message.id); @@ -737,3 +737,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/before-after-request-streaming/example.ts b/integration/before-after-request-streaming/example.ts index 6fef476c1..94e8a89d9 100644 --- a/integration/before-after-request-streaming/example.ts +++ b/integration/before-after-request-streaming/example.ts @@ -101,7 +101,7 @@ function createBaseDashFlash(): DashFlash { return { msg: "", type: 0 }; } -export const DashFlash = { +export const DashFlash: MessageFns = { encode(message: DashFlash, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.msg !== "") { writer.uint32(10).string(message.msg); @@ -175,7 +175,7 @@ function createBaseDashUserSettingsState(): DashUserSettingsState { return { email: "", urls: undefined, flashes: [] }; } -export const DashUserSettingsState = { +export const DashUserSettingsState: MessageFns = { encode(message: DashUserSettingsState, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.email !== "") { writer.uint32(10).string(message.email); @@ -266,7 +266,7 @@ function createBaseDashUserSettingsState_URLs(): DashUserSettingsState_URLs { return { connectGoogle: "", connectGithub: "" }; } -export const DashUserSettingsState_URLs = { +export const DashUserSettingsState_URLs: MessageFns = { encode(message: DashUserSettingsState_URLs, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.connectGoogle !== "") { writer.uint32(10).string(message.connectGoogle); @@ -340,7 +340,7 @@ function createBaseDashCred(): DashCred { return { description: "", metadata: "", token: "", id: "" }; } -export const DashCred = { +export const DashCred: MessageFns = { encode(message: DashCred, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.description !== "") { writer.uint32(18).string(message.description); @@ -444,7 +444,7 @@ function createBaseDashAPICredsCreateReq(): DashAPICredsCreateReq { return { description: "", metadata: "" }; } -export const DashAPICredsCreateReq = { +export const DashAPICredsCreateReq: MessageFns = { encode(message: DashAPICredsCreateReq, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.description !== "") { writer.uint32(10).string(message.description); @@ -518,7 +518,7 @@ function createBaseDashAPICredsUpdateReq(): DashAPICredsUpdateReq { return { credSid: "", description: "", metadata: "", id: "" }; } -export const DashAPICredsUpdateReq = { +export const DashAPICredsUpdateReq: MessageFns = { encode(message: DashAPICredsUpdateReq, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.credSid !== "") { writer.uint32(10).string(message.credSid); @@ -622,7 +622,7 @@ function createBaseDashAPICredsDeleteReq(): DashAPICredsDeleteReq { return { credSid: "", id: "" }; } -export const DashAPICredsDeleteReq = { +export const DashAPICredsDeleteReq: MessageFns = { encode(message: DashAPICredsDeleteReq, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.credSid !== "") { writer.uint32(10).string(message.credSid); @@ -696,7 +696,7 @@ function createBaseEmpty(): Empty { return {}; } -export const Empty = { +export const Empty: MessageFns = { encode(_: Empty, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -1043,3 +1043,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/before-after-request-streaming/google/protobuf/wrappers.ts b/integration/before-after-request-streaming/google/protobuf/wrappers.ts index 52a93ce56..fd5825f88 100644 --- a/integration/before-after-request-streaming/google/protobuf/wrappers.ts +++ b/integration/before-after-request-streaming/google/protobuf/wrappers.ts @@ -100,7 +100,7 @@ function createBaseDoubleValue(): DoubleValue { return { value: 0 }; } -export const DoubleValue = { +export const DoubleValue: MessageFns = { encode(message: DoubleValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(9).double(message.value); @@ -157,7 +157,7 @@ function createBaseFloatValue(): FloatValue { return { value: 0 }; } -export const FloatValue = { +export const FloatValue: MessageFns = { encode(message: FloatValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(13).float(message.value); @@ -214,7 +214,7 @@ function createBaseInt64Value(): Int64Value { return { value: 0 }; } -export const Int64Value = { +export const Int64Value: MessageFns = { encode(message: Int64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int64(message.value); @@ -271,7 +271,7 @@ function createBaseUInt64Value(): UInt64Value { return { value: 0 }; } -export const UInt64Value = { +export const UInt64Value: MessageFns = { encode(message: UInt64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint64(message.value); @@ -328,7 +328,7 @@ function createBaseInt32Value(): Int32Value { return { value: 0 }; } -export const Int32Value = { +export const Int32Value: MessageFns = { encode(message: Int32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int32(message.value); @@ -385,7 +385,7 @@ function createBaseUInt32Value(): UInt32Value { return { value: 0 }; } -export const UInt32Value = { +export const UInt32Value: MessageFns = { encode(message: UInt32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint32(message.value); @@ -442,7 +442,7 @@ function createBaseBoolValue(): BoolValue { return { value: false }; } -export const BoolValue = { +export const BoolValue: MessageFns = { encode(message: BoolValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== false) { writer.uint32(8).bool(message.value); @@ -499,7 +499,7 @@ function createBaseStringValue(): StringValue { return { value: "" }; } -export const StringValue = { +export const StringValue: MessageFns = { encode(message: StringValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "") { writer.uint32(10).string(message.value); @@ -556,7 +556,7 @@ function createBaseBytesValue(): BytesValue { return { value: new Uint8Array(0) }; } -export const BytesValue = { +export const BytesValue: MessageFns = { encode(message: BytesValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value.length !== 0) { writer.uint32(10).bytes(message.value); @@ -660,3 +660,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/before-after-request/simple.ts b/integration/before-after-request/simple.ts index 9a09ae995..d02369306 100644 --- a/integration/before-after-request/simple.ts +++ b/integration/before-after-request/simple.ts @@ -81,7 +81,7 @@ function createBaseSimple(): Simple { return { name: "", otherSimple: undefined }; } -export const Simple = { +export const Simple: MessageFns = { encode(message: Simple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -157,7 +157,7 @@ function createBaseDifferentSimple(): DifferentSimple { return { name: "", otherOptionalSimple2: undefined }; } -export const DifferentSimple = { +export const DifferentSimple: MessageFns = { encode(message: DifferentSimple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -235,7 +235,7 @@ function createBaseSimpleEnums(): SimpleEnums { return { localEnum: 0, importEnum: 0 }; } -export const SimpleEnums = { +export const SimpleEnums: MessageFns = { encode(message: SimpleEnums, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.localEnum !== 0) { writer.uint32(8).int32(message.localEnum); @@ -309,7 +309,7 @@ function createBaseFooServiceCreateRequest(): FooServiceCreateRequest { return { kind: 0 }; } -export const FooServiceCreateRequest = { +export const FooServiceCreateRequest: MessageFns = { encode(message: FooServiceCreateRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.kind !== 0) { writer.uint32(8).int32(message.kind); @@ -366,7 +366,7 @@ function createBaseFooServiceCreateResponse(): FooServiceCreateResponse { return { kind: 0 }; } -export const FooServiceCreateResponse = { +export const FooServiceCreateResponse: MessageFns = { encode(message: FooServiceCreateResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.kind !== 0) { writer.uint32(8).int32(message.kind); @@ -485,3 +485,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/before-after-request/simple2.ts b/integration/before-after-request/simple2.ts index 4d7a9d603..5947c12b0 100644 --- a/integration/before-after-request/simple2.ts +++ b/integration/before-after-request/simple2.ts @@ -93,7 +93,7 @@ function createBaseSimple(): Simple { return { name: "", age: 0 }; } -export const Simple = { +export const Simple: MessageFns = { encode(message: Simple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -178,3 +178,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/bytes-as-base64-browser/message.ts b/integration/bytes-as-base64-browser/message.ts index f525e87dc..b2b020e29 100644 --- a/integration/bytes-as-base64-browser/message.ts +++ b/integration/bytes-as-base64-browser/message.ts @@ -13,7 +13,7 @@ function createBaseMessage(): Message { return { data: new Uint8Array(0) }; } -export const Message = { +export const Message: MessageFns = { fromJSON(object: any): Message { return { data: isSet(object.data) ? bytesFromBase64(object.data) : new Uint8Array(0) }; }, @@ -68,3 +68,10 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/bytes-as-base64-node/message.ts b/integration/bytes-as-base64-node/message.ts index b1c8248c3..1f3fc171f 100644 --- a/integration/bytes-as-base64-node/message.ts +++ b/integration/bytes-as-base64-node/message.ts @@ -13,7 +13,7 @@ function createBaseMessage(): Message { return { data: Buffer.alloc(0) }; } -export const Message = { +export const Message: MessageFns = { fromJSON(object: any): Message { return { data: isSet(object.data) ? Buffer.from(bytesFromBase64(object.data)) : Buffer.alloc(0) }; }, @@ -59,3 +59,10 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/bytes-as-base64/message.ts b/integration/bytes-as-base64/message.ts index eadf1a346..8e3079d27 100644 --- a/integration/bytes-as-base64/message.ts +++ b/integration/bytes-as-base64/message.ts @@ -13,7 +13,7 @@ function createBaseMessage(): Message { return { data: new Uint8Array(0) }; } -export const Message = { +export const Message: MessageFns = { fromJSON(object: any): Message { return { data: isSet(object.data) ? bytesFromBase64(object.data) : new Uint8Array(0) }; }, @@ -76,3 +76,10 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/bytes-node/google/protobuf/wrappers.ts b/integration/bytes-node/google/protobuf/wrappers.ts index ec2b3cbca..56b1dd486 100644 --- a/integration/bytes-node/google/protobuf/wrappers.ts +++ b/integration/bytes-node/google/protobuf/wrappers.ts @@ -100,7 +100,7 @@ function createBaseDoubleValue(): DoubleValue { return { value: 0 }; } -export const DoubleValue = { +export const DoubleValue: MessageFns = { encode(message: DoubleValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(9).double(message.value); @@ -157,7 +157,7 @@ function createBaseFloatValue(): FloatValue { return { value: 0 }; } -export const FloatValue = { +export const FloatValue: MessageFns = { encode(message: FloatValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(13).float(message.value); @@ -214,7 +214,7 @@ function createBaseInt64Value(): Int64Value { return { value: 0 }; } -export const Int64Value = { +export const Int64Value: MessageFns = { encode(message: Int64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int64(message.value); @@ -271,7 +271,7 @@ function createBaseUInt64Value(): UInt64Value { return { value: 0 }; } -export const UInt64Value = { +export const UInt64Value: MessageFns = { encode(message: UInt64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint64(message.value); @@ -328,7 +328,7 @@ function createBaseInt32Value(): Int32Value { return { value: 0 }; } -export const Int32Value = { +export const Int32Value: MessageFns = { encode(message: Int32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int32(message.value); @@ -385,7 +385,7 @@ function createBaseUInt32Value(): UInt32Value { return { value: 0 }; } -export const UInt32Value = { +export const UInt32Value: MessageFns = { encode(message: UInt32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint32(message.value); @@ -442,7 +442,7 @@ function createBaseBoolValue(): BoolValue { return { value: false }; } -export const BoolValue = { +export const BoolValue: MessageFns = { encode(message: BoolValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== false) { writer.uint32(8).bool(message.value); @@ -499,7 +499,7 @@ function createBaseStringValue(): StringValue { return { value: "" }; } -export const StringValue = { +export const StringValue: MessageFns = { encode(message: StringValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "") { writer.uint32(10).string(message.value); @@ -556,7 +556,7 @@ function createBaseBytesValue(): BytesValue { return { value: Buffer.alloc(0) }; } -export const BytesValue = { +export const BytesValue: MessageFns = { encode(message: BytesValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value.length !== 0) { writer.uint32(10).bytes(message.value); @@ -643,3 +643,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/bytes-node/point.ts b/integration/bytes-node/point.ts index 7bcbc982a..27af73f05 100644 --- a/integration/bytes-node/point.ts +++ b/integration/bytes-node/point.ts @@ -16,7 +16,7 @@ function createBasePoint(): Point { return { data: Buffer.alloc(0), dataWrapped: undefined }; } -export const Point = { +export const Point: MessageFns = { encode(message: Point, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.data.length !== 0) { writer.uint32(10).bytes(message.data); @@ -109,3 +109,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/const-enum/const-enum.ts b/integration/const-enum/const-enum.ts index 0389992f1..cc29feb71 100644 --- a/integration/const-enum/const-enum.ts +++ b/integration/const-enum/const-enum.ts @@ -81,7 +81,7 @@ function createBaseDividerData(): DividerData { return { type: DividerData_DividerType.DOUBLE, typeMap: {} }; } -export const DividerData = { +export const DividerData: MessageFns = { encode(message: DividerData, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.type !== DividerData_DividerType.DOUBLE) { writer.uint32(8).int32(dividerData_DividerTypeToNumber(message.type)); @@ -177,7 +177,7 @@ function createBaseDividerData_TypeMapEntry(): DividerData_TypeMapEntry { return { key: "", value: DividerData_DividerType.DOUBLE }; } -export const DividerData_TypeMapEntry = { +export const DividerData_TypeMapEntry: MessageFns = { encode(message: DividerData_TypeMapEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -266,3 +266,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/default-with-custom-metadata/default-with-custom-metadata.ts b/integration/default-with-custom-metadata/default-with-custom-metadata.ts index 9640aed61..539aa410c 100644 --- a/integration/default-with-custom-metadata/default-with-custom-metadata.ts +++ b/integration/default-with-custom-metadata/default-with-custom-metadata.ts @@ -19,7 +19,7 @@ function createBaseGetBasicRequest(): GetBasicRequest { return { name: "" }; } -export const GetBasicRequest = { +export const GetBasicRequest: MessageFns = { encode(message: GetBasicRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -76,7 +76,7 @@ function createBaseGetBasicResponse(): GetBasicResponse { return { name: "" }; } -export const GetBasicResponse = { +export const GetBasicResponse: MessageFns = { encode(message: GetBasicResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -168,3 +168,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/default-with-metadata/default-with-metadata.ts b/integration/default-with-metadata/default-with-metadata.ts index 94f4072b7..d5d7067d5 100644 --- a/integration/default-with-metadata/default-with-metadata.ts +++ b/integration/default-with-metadata/default-with-metadata.ts @@ -19,7 +19,7 @@ function createBaseGetBasicRequest(): GetBasicRequest { return { name: "" }; } -export const GetBasicRequest = { +export const GetBasicRequest: MessageFns = { encode(message: GetBasicRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -76,7 +76,7 @@ function createBaseGetBasicResponse(): GetBasicResponse { return { name: "" }; } -export const GetBasicResponse = { +export const GetBasicResponse: MessageFns = { encode(message: GetBasicResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -168,3 +168,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/emit-default-values-json/google/protobuf/timestamp.ts b/integration/emit-default-values-json/google/protobuf/timestamp.ts index 45ad1ebe4..c2d70a267 100644 --- a/integration/emit-default-values-json/google/protobuf/timestamp.ts +++ b/integration/emit-default-values-json/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -213,3 +213,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/emit-default-values-json/test.ts b/integration/emit-default-values-json/test.ts index af6bda9dd..88a51f279 100644 --- a/integration/emit-default-values-json/test.ts +++ b/integration/emit-default-values-json/test.ts @@ -108,7 +108,7 @@ function createBaseDefaultValuesTest(): DefaultValuesTest { }; } -export const DefaultValuesTest = { +export const DefaultValuesTest: MessageFns = { encode(message: DefaultValuesTest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== 0) { writer.uint32(8).int32(message.id); @@ -573,7 +573,7 @@ function createBaseDefaultValuesTest_TranslationsEntry(): DefaultValuesTest_Tran return { key: "", value: "" }; } -export const DefaultValuesTest_TranslationsEntry = { +export const DefaultValuesTest_TranslationsEntry: MessageFns = { encode(message: DefaultValuesTest_TranslationsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -651,7 +651,7 @@ function createBaseChild(): Child { return {}; } -export const Child = { +export const Child: MessageFns = { encode(_: Child, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -767,3 +767,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/enums-as-literals-with-string-enums/enums-as-literals-with-string-enums.ts b/integration/enums-as-literals-with-string-enums/enums-as-literals-with-string-enums.ts index f531bdb90..eb4ef6a52 100644 --- a/integration/enums-as-literals-with-string-enums/enums-as-literals-with-string-enums.ts +++ b/integration/enums-as-literals-with-string-enums/enums-as-literals-with-string-enums.ts @@ -85,7 +85,7 @@ function createBaseDividerData(): DividerData { return { type: DividerData_DividerType.DOUBLE }; } -export const DividerData = { +export const DividerData: MessageFns = { encode(message: DividerData, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.type !== DividerData_DividerType.DOUBLE) { writer.uint32(8).int32(dividerData_DividerTypeToNumber(message.type)); @@ -153,3 +153,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/enums-as-literals/enums-as-literals.ts b/integration/enums-as-literals/enums-as-literals.ts index de6428f00..dd31699ab 100644 --- a/integration/enums-as-literals/enums-as-literals.ts +++ b/integration/enums-as-literals/enums-as-literals.ts @@ -63,7 +63,7 @@ function createBaseDividerData(): DividerData { return { type: 0 }; } -export const DividerData = { +export const DividerData: MessageFns = { encode(message: DividerData, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.type !== 0) { writer.uint32(8).int32(message.type); @@ -131,3 +131,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/extension-import/base.ts b/integration/extension-import/base.ts index 0dd35c515..faf7edb95 100644 --- a/integration/extension-import/base.ts +++ b/integration/extension-import/base.ts @@ -12,7 +12,7 @@ function createBaseExtendable(): Extendable { return { field: "" }; } -export const Extendable = { +export const Extendable: MessageFns = { encode(message: Extendable, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.field !== "") { writer.uint32(10).string(message.field); @@ -80,3 +80,12 @@ type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/extensions/test.ts b/integration/extensions/test.ts index 62062b25a..993167d64 100644 --- a/integration/extensions/test.ts +++ b/integration/extensions/test.ts @@ -66,7 +66,7 @@ function createBaseExtendable(): Extendable { return {}; } -export const Extendable = { +export const Extendable: MessageFns & ExtensionFns = { encode(message: Extendable, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.field !== undefined && message.field !== "") { writer.uint32(10).string(message.field); @@ -195,7 +195,7 @@ function createBaseNested(): Nested { return {}; } -export const Nested = { +export const Nested: MessageFns & ExtensionHolder<"message", Nested[]> = { message: > { number: 4, tag: 34, @@ -297,7 +297,7 @@ function createBaseGroup(): Group { return {}; } -export const Group = { +export const Group: MessageFns = { encode(message: Group, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -604,3 +604,19 @@ export interface Extension { function fail(message?: string): never { throw new globalThis.Error(message ?? "Failed"); } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} + +export interface ExtensionFns { + setExtension(message: T, extension: Extension, value: E): void; + getExtension(message: T, extension: Extension): E | undefined; +} + +export type ExtensionHolder = { [key in T]: Extension }; diff --git a/integration/fieldmask-optional-all/fieldmask-optional.ts b/integration/fieldmask-optional-all/fieldmask-optional.ts index 1ca9deb4d..d10073b5b 100644 --- a/integration/fieldmask-optional-all/fieldmask-optional.ts +++ b/integration/fieldmask-optional-all/fieldmask-optional.ts @@ -15,7 +15,7 @@ function createBaseExample(): Example { return { mask: undefined }; } -export const Example = { +export const Example: MessageFns = { encode(message: Example, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.mask !== undefined) { FieldMask.encode(FieldMask.wrap(message.mask), writer.uint32(10).fork()).join(); @@ -83,3 +83,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/fieldmask-optional-all/google/protobuf/field_mask.ts b/integration/fieldmask-optional-all/google/protobuf/field_mask.ts index efa7009b3..75912777a 100644 --- a/integration/fieldmask-optional-all/google/protobuf/field_mask.ts +++ b/integration/fieldmask-optional-all/google/protobuf/field_mask.ts @@ -215,7 +215,7 @@ function createBaseFieldMask(): FieldMask { return { paths: [] }; } -export const FieldMask = { +export const FieldMask: MessageFns & FieldMaskWrapperFns = { encode(message: FieldMask, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.paths !== undefined && message.paths.length !== 0) { for (const v of message.paths) { @@ -293,3 +293,17 @@ export type DeepPartial = T extends Builtin ? T type KeysOfUnion = T extends T ? keyof T : never; export type Exact = P extends Builtin ? P : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} + +export interface FieldMaskWrapperFns { + wrap(paths: string[]): FieldMask; + unwrap(message: FieldMask): string[] | undefined; +} diff --git a/integration/fieldmask/fieldmask.ts b/integration/fieldmask/fieldmask.ts index f28e346bc..fe0300442 100644 --- a/integration/fieldmask/fieldmask.ts +++ b/integration/fieldmask/fieldmask.ts @@ -15,7 +15,7 @@ function createBaseFieldMaskMessage(): FieldMaskMessage { return { fieldMask: undefined }; } -export const FieldMaskMessage = { +export const FieldMaskMessage: MessageFns = { encode(message: FieldMaskMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.fieldMask !== undefined) { FieldMask.encode(FieldMask.wrap(message.fieldMask), writer.uint32(10).fork()).join(); @@ -83,3 +83,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/fieldmask/google/protobuf/field_mask.ts b/integration/fieldmask/google/protobuf/field_mask.ts index 96f7d8b55..060bf3826 100644 --- a/integration/fieldmask/google/protobuf/field_mask.ts +++ b/integration/fieldmask/google/protobuf/field_mask.ts @@ -215,7 +215,7 @@ function createBaseFieldMask(): FieldMask { return { paths: [] }; } -export const FieldMask = { +export const FieldMask: MessageFns & FieldMaskWrapperFns = { encode(message: FieldMask, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.paths) { writer.uint32(10).string(v!); @@ -291,3 +291,17 @@ export type DeepPartial = T extends Builtin ? T type KeysOfUnion = T extends T ? keyof T : never; export type Exact = P extends Builtin ? P : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} + +export interface FieldMaskWrapperFns { + wrap(paths: string[]): FieldMask; + unwrap(message: FieldMask): string[]; +} diff --git a/integration/fieldoption-jstype-with-forcelong-bigint/fieldoption-jstype-with-forcelong-bigint.ts b/integration/fieldoption-jstype-with-forcelong-bigint/fieldoption-jstype-with-forcelong-bigint.ts index a67218583..d1877e163 100644 --- a/integration/fieldoption-jstype-with-forcelong-bigint/fieldoption-jstype-with-forcelong-bigint.ts +++ b/integration/fieldoption-jstype-with-forcelong-bigint/fieldoption-jstype-with-forcelong-bigint.ts @@ -16,7 +16,7 @@ function createBaseFieldOption(): FieldOption { return { normalField: 0n, numberField: 0, stringField: "0" }; } -export const FieldOption = { +export const FieldOption: MessageFns = { encode(message: FieldOption, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.normalField !== 0n) { if (BigInt.asIntN(64, message.normalField) !== message.normalField) { @@ -136,3 +136,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/fieldoption-jstype-with-forcelong-long/fieldoption-jstype-with-forcelong-long.ts b/integration/fieldoption-jstype-with-forcelong-long/fieldoption-jstype-with-forcelong-long.ts index 4419c5706..1a173982c 100644 --- a/integration/fieldoption-jstype-with-forcelong-long/fieldoption-jstype-with-forcelong-long.ts +++ b/integration/fieldoption-jstype-with-forcelong-long/fieldoption-jstype-with-forcelong-long.ts @@ -17,7 +17,7 @@ function createBaseFieldOption(): FieldOption { return { normalField: Long.ZERO, numberField: 0, stringField: "0" }; } -export const FieldOption = { +export const FieldOption: MessageFns = { encode(message: FieldOption, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (!message.normalField.equals(Long.ZERO)) { writer.uint32(8).int64(message.normalField.toString()); @@ -130,3 +130,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/fieldoption-jstype-with-forcelong-number/fieldoption-jstype-with-forcelong-number.ts b/integration/fieldoption-jstype-with-forcelong-number/fieldoption-jstype-with-forcelong-number.ts index 14e94438b..39e05a702 100644 --- a/integration/fieldoption-jstype-with-forcelong-number/fieldoption-jstype-with-forcelong-number.ts +++ b/integration/fieldoption-jstype-with-forcelong-number/fieldoption-jstype-with-forcelong-number.ts @@ -16,7 +16,7 @@ function createBaseFieldOption(): FieldOption { return { normalField: 0, numberField: 0, stringField: "0" }; } -export const FieldOption = { +export const FieldOption: MessageFns = { encode(message: FieldOption, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.normalField !== 0) { writer.uint32(8).int64(message.normalField); @@ -127,3 +127,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/fieldoption-jstype-with-forcelong-string/fieldoption-jstype-with-forcelong-string.ts b/integration/fieldoption-jstype-with-forcelong-string/fieldoption-jstype-with-forcelong-string.ts index da82fd8fd..7c538af40 100644 --- a/integration/fieldoption-jstype-with-forcelong-string/fieldoption-jstype-with-forcelong-string.ts +++ b/integration/fieldoption-jstype-with-forcelong-string/fieldoption-jstype-with-forcelong-string.ts @@ -16,7 +16,7 @@ function createBaseFieldOption(): FieldOption { return { normalField: "0", numberField: 0, stringField: "0" }; } -export const FieldOption = { +export const FieldOption: MessageFns = { encode(message: FieldOption, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.normalField !== "0") { writer.uint32(8).int64(message.normalField); @@ -127,3 +127,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/fieldoption-jstype/fieldoption-jstype.ts b/integration/fieldoption-jstype/fieldoption-jstype.ts index c551836a1..92f354f29 100644 --- a/integration/fieldoption-jstype/fieldoption-jstype.ts +++ b/integration/fieldoption-jstype/fieldoption-jstype.ts @@ -40,7 +40,7 @@ function createBaseInt64FieldOption(): Int64FieldOption { return { normalField: 0, numberField: 0, stringField: "0" }; } -export const Int64FieldOption = { +export const Int64FieldOption: MessageFns = { encode(message: Int64FieldOption, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.normalField !== 0) { writer.uint32(8).int64(message.normalField); @@ -129,7 +129,7 @@ function createBaseUInt64FieldOption(): UInt64FieldOption { return { normalField: 0, numberField: 0, stringField: "0" }; } -export const UInt64FieldOption = { +export const UInt64FieldOption: MessageFns = { encode(message: UInt64FieldOption, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.normalField !== 0) { writer.uint32(8).uint64(message.normalField); @@ -218,7 +218,7 @@ function createBaseSInt64FieldOption(): SInt64FieldOption { return { normalField: 0, numberField: 0, stringField: "0" }; } -export const SInt64FieldOption = { +export const SInt64FieldOption: MessageFns = { encode(message: SInt64FieldOption, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.normalField !== 0) { writer.uint32(8).sint64(message.normalField); @@ -307,7 +307,7 @@ function createBaseFixed64FieldOption(): Fixed64FieldOption { return { normalField: 0, numberField: 0, stringField: "0" }; } -export const Fixed64FieldOption = { +export const Fixed64FieldOption: MessageFns = { encode(message: Fixed64FieldOption, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.normalField !== 0) { writer.uint32(9).fixed64(message.normalField); @@ -396,7 +396,7 @@ function createBaseSFixed64FieldOption(): SFixed64FieldOption { return { normalField: 0, numberField: 0, stringField: "0" }; } -export const SFixed64FieldOption = { +export const SFixed64FieldOption: MessageFns = { encode(message: SFixed64FieldOption, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.normalField !== 0) { writer.uint32(9).sfixed64(message.normalField); @@ -507,3 +507,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/file-suffix/child.pb.ts b/integration/file-suffix/child.pb.ts index 0546e5c72..3c7f7a16b 100644 --- a/integration/file-suffix/child.pb.ts +++ b/integration/file-suffix/child.pb.ts @@ -47,7 +47,7 @@ function createBaseChild(): Child { return { name: "" }; } -export const Child = { +export const Child: MessageFns = { encode(message: Child, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -115,3 +115,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/file-suffix/google/protobuf/timestamp.pb.ts b/integration/file-suffix/google/protobuf/timestamp.pb.ts index a4ccaeb2e..f4a29a6af 100644 --- a/integration/file-suffix/google/protobuf/timestamp.pb.ts +++ b/integration/file-suffix/google/protobuf/timestamp.pb.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -213,3 +213,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/file-suffix/parent.pb.ts b/integration/file-suffix/parent.pb.ts index fb89e48b5..9ae226747 100644 --- a/integration/file-suffix/parent.pb.ts +++ b/integration/file-suffix/parent.pb.ts @@ -18,7 +18,7 @@ function createBaseParent(): Parent { return { child: undefined, childEnum: 0, createdAt: undefined }; } -export const Parent = { +export const Parent: MessageFns = { encode(message: Parent, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.child !== undefined) { Child.encode(message.child, writer.uint32(10).fork()).join(); @@ -140,3 +140,12 @@ function fromJsonTimestamp(o: any): Date { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/from-partial-no-initialize/test.ts b/integration/from-partial-no-initialize/test.ts index 41bb1062a..ad505ed7e 100644 --- a/integration/from-partial-no-initialize/test.ts +++ b/integration/from-partial-no-initialize/test.ts @@ -29,7 +29,7 @@ function createBaseTPartialMessage(): TPartialMessage { return {}; } -export const TPartialMessage = { +export const TPartialMessage: MessageFns = { encode(message: TPartialMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.field !== undefined && message.field !== "") { writer.uint32(10).string(message.field); @@ -86,7 +86,7 @@ function createBaseTPartial(): TPartial { return {}; } -export const TPartial = { +export const TPartial: MessageFns = { encode(message: TPartial, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.number !== undefined && message.number !== 0) { writer.uint32(8).int32(message.number); @@ -297,7 +297,7 @@ function createBaseTPartial_MapEntry(): TPartial_MapEntry { return { key: "", value: "" }; } -export const TPartial_MapEntry = { +export const TPartial_MapEntry: MessageFns = { encode(message: TPartial_MapEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -386,3 +386,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/fromJson-enums/from-json.ts b/integration/fromJson-enums/from-json.ts index bdbeaeb28..6409d3866 100644 --- a/integration/fromJson-enums/from-json.ts +++ b/integration/fromJson-enums/from-json.ts @@ -32,9 +32,13 @@ export function test_TestTypeToJSON(object: Test_TestType): string { } } -export const Test = { +export const Test: MessageFns = { toJSON(_: Test): unknown { const obj: any = {}; return obj; }, }; + +export interface MessageFns { + toJSON(message: T): unknown; +} diff --git a/integration/generic-metadata/hero.ts b/integration/generic-metadata/hero.ts index 91f47da31..6da273a5d 100644 --- a/integration/generic-metadata/hero.ts +++ b/integration/generic-metadata/hero.ts @@ -31,7 +31,7 @@ function createBaseHeroById(): HeroById { return { id: 0 }; } -export const HeroById = { +export const HeroById: MessageFns = { encode(message: HeroById, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== 0) { writer.uint32(8).int32(message.id); @@ -88,7 +88,7 @@ function createBaseVillainById(): VillainById { return { id: 0 }; } -export const VillainById = { +export const VillainById: MessageFns = { encode(message: VillainById, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== 0) { writer.uint32(8).int32(message.id); @@ -145,7 +145,7 @@ function createBaseHero(): Hero { return { id: 0, name: "" }; } -export const Hero = { +export const Hero: MessageFns = { encode(message: Hero, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== 0) { writer.uint32(8).int32(message.id); @@ -219,7 +219,7 @@ function createBaseVillain(): Villain { return { id: 0, name: "" }; } -export const Villain = { +export const Villain: MessageFns = { encode(message: Villain, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== 0) { writer.uint32(8).int32(message.id); @@ -389,3 +389,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/generic-service-definitions-and-services/simple.ts b/integration/generic-service-definitions-and-services/simple.ts index b68aeeb20..235ffa8e3 100644 --- a/integration/generic-service-definitions-and-services/simple.ts +++ b/integration/generic-service-definitions-and-services/simple.ts @@ -14,7 +14,7 @@ function createBaseTestMessage(): TestMessage { return { value: "" }; } -export const TestMessage = { +export const TestMessage: MessageFns = { encode(message: TestMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "") { writer.uint32(10).string(message.value); @@ -148,3 +148,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/generic-service-definitions/simple.ts b/integration/generic-service-definitions/simple.ts index b68aeeb20..235ffa8e3 100644 --- a/integration/generic-service-definitions/simple.ts +++ b/integration/generic-service-definitions/simple.ts @@ -14,7 +14,7 @@ function createBaseTestMessage(): TestMessage { return { value: "" }; } -export const TestMessage = { +export const TestMessage: MessageFns = { encode(message: TestMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "") { writer.uint32(10).string(message.value); @@ -148,3 +148,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/global-this/global-this.ts b/integration/global-this/global-this.ts index c41157fa7..421314a9b 100644 --- a/integration/global-this/global-this.ts +++ b/integration/global-this/global-this.ts @@ -34,7 +34,7 @@ function createBaseObject(): Object { return { name: "" }; } -export const Object = { +export const Object: MessageFns = { encode(message: Object, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -91,7 +91,7 @@ function createBaseError(): Error { return { name: "" }; } -export const Error = { +export const Error: MessageFns = { encode(message: Error, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -148,7 +148,7 @@ function createBaseString(): String { return { value: "" }; } -export const String = { +export const String: MessageFns = { encode(message: String, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "") { writer.uint32(10).string(message.value); @@ -205,7 +205,7 @@ function createBaseBoolean(): Boolean { return { value: false }; } -export const Boolean = { +export const Boolean: MessageFns = { encode(message: Boolean, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== false) { writer.uint32(8).bool(message.value); @@ -262,7 +262,7 @@ function createBaseNumber(): Number { return { value: 0 }; } -export const Number = { +export const Number: MessageFns = { encode(message: Number, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(9).double(message.value); @@ -319,7 +319,7 @@ function createBaseArray(): Array { return { values: [] }; } -export const Array = { +export const Array: MessageFns = { encode(message: Array, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.values) { String.encode(v!, writer.uint32(10).fork()).join(); @@ -406,3 +406,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/groups/test.ts b/integration/groups/test.ts index 3f31228b0..b248948cb 100644 --- a/integration/groups/test.ts +++ b/integration/groups/test.ts @@ -58,7 +58,7 @@ function createBaseGroupsOptionalTest(): GroupsOptionalTest { return {}; } -export const GroupsOptionalTest = { +export const GroupsOptionalTest: MessageFns = { encode(message: GroupsOptionalTest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.int1 !== undefined && message.int1 !== 0) { writer.uint32(8).int32(message.int1); @@ -169,7 +169,7 @@ function createBaseGroupsOptionalTest_Group(): GroupsOptionalTest_Group { return {}; } -export const GroupsOptionalTest_Group = { +export const GroupsOptionalTest_Group: MessageFns = { encode(message: GroupsOptionalTest_Group, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== undefined && message.key !== "") { writer.uint32(10).string(message.key); @@ -263,7 +263,7 @@ function createBaseGroupsRepeatedTest(): GroupsRepeatedTest { return {}; } -export const GroupsRepeatedTest = { +export const GroupsRepeatedTest: MessageFns = { encode(message: GroupsRepeatedTest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.int1 !== undefined && message.int1.length !== 0) { writer.uint32(10).fork(); @@ -419,7 +419,7 @@ function createBaseGroupsRepeatedTest_Group(): GroupsRepeatedTest_Group { return {}; } -export const GroupsRepeatedTest_Group = { +export const GroupsRepeatedTest_Group: MessageFns = { encode(message: GroupsRepeatedTest_Group, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== undefined && message.key.length !== 0) { for (const v of message.key) { @@ -523,7 +523,7 @@ function createBaseGroupsNestedTest(): GroupsNestedTest { return {}; } -export const GroupsNestedTest = { +export const GroupsNestedTest: MessageFns = { encode(message: GroupsNestedTest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.int1 !== undefined && message.int1.length !== 0) { writer.uint32(10).fork(); @@ -679,7 +679,7 @@ function createBaseGroupsNestedTest_Group(): GroupsNestedTest_Group { return {}; } -export const GroupsNestedTest_Group = { +export const GroupsNestedTest_Group: MessageFns = { encode(message: GroupsNestedTest_Group, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.nested !== undefined && message.nested.length !== 0) { for (const v of message.nested) { @@ -765,7 +765,7 @@ function createBaseGroupsNestedTest_Group_Nested(): GroupsNestedTest_Group_Neste return {}; } -export const GroupsNestedTest_Group_Nested = { +export const GroupsNestedTest_Group_Nested: MessageFns = { encode(message: GroupsNestedTest_Group_Nested, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.nested2 !== undefined && message.nested2.length !== 0) { for (const v of message.nested2) { @@ -853,7 +853,7 @@ function createBaseGroupsNestedTest_Group_Nested_Nested2(): GroupsNestedTest_Gro return {}; } -export const GroupsNestedTest_Group_Nested_Nested2 = { +export const GroupsNestedTest_Group_Nested_Nested2: MessageFns = { encode(message: GroupsNestedTest_Group_Nested_Nested2, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.string1 !== undefined && message.string1 !== "") { writer.uint32(10).string(message.string1); @@ -945,3 +945,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/grpc-js-use-date-false/google/protobuf/timestamp.ts b/integration/grpc-js-use-date-false/google/protobuf/timestamp.ts index a4ccaeb2e..f4a29a6af 100644 --- a/integration/grpc-js-use-date-false/google/protobuf/timestamp.ts +++ b/integration/grpc-js-use-date-false/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -213,3 +213,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/grpc-js-use-date-false/grpc-js-use-date-false.ts b/integration/grpc-js-use-date-false/grpc-js-use-date-false.ts index 09a96fea2..d01a6f652 100644 --- a/integration/grpc-js-use-date-false/grpc-js-use-date-false.ts +++ b/integration/grpc-js-use-date-false/grpc-js-use-date-false.ts @@ -24,7 +24,7 @@ function createBaseTimestampMessage(): TimestampMessage { return { timestamp: undefined }; } -export const TimestampMessage = { +export const TimestampMessage: MessageFns = { encode(message: TimestampMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.timestamp !== undefined) { Timestamp.encode(message.timestamp, writer.uint32(10).fork()).join(); @@ -179,3 +179,12 @@ function fromJsonTimestamp(o: any): Timestamp { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/grpc-js-use-date-string-nano/google/protobuf/timestamp.ts b/integration/grpc-js-use-date-string-nano/google/protobuf/timestamp.ts index a4ccaeb2e..f4a29a6af 100644 --- a/integration/grpc-js-use-date-string-nano/google/protobuf/timestamp.ts +++ b/integration/grpc-js-use-date-string-nano/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -213,3 +213,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/grpc-js-use-date-string-nano/grpc-js-use-date-string-nano.ts b/integration/grpc-js-use-date-string-nano/grpc-js-use-date-string-nano.ts index 8e3363127..c7b170933 100644 --- a/integration/grpc-js-use-date-string-nano/grpc-js-use-date-string-nano.ts +++ b/integration/grpc-js-use-date-string-nano/grpc-js-use-date-string-nano.ts @@ -25,7 +25,7 @@ function createBaseTimestampMessage(): TimestampMessage { return { timestamp: undefined }; } -export const TimestampMessage = { +export const TimestampMessage: MessageFns = { encode(message: TimestampMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.timestamp !== undefined) { Timestamp.encode(toTimestamp(message.timestamp), writer.uint32(10).fork()).join(); @@ -183,3 +183,12 @@ function fromTimestamp(t: Timestamp): string { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/grpc-js-use-date-string/google/protobuf/timestamp.ts b/integration/grpc-js-use-date-string/google/protobuf/timestamp.ts index a4ccaeb2e..f4a29a6af 100644 --- a/integration/grpc-js-use-date-string/google/protobuf/timestamp.ts +++ b/integration/grpc-js-use-date-string/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -213,3 +213,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/grpc-js-use-date-string/grpc-js-use-date-string.ts b/integration/grpc-js-use-date-string/grpc-js-use-date-string.ts index 9b3e967b2..837380be8 100644 --- a/integration/grpc-js-use-date-string/grpc-js-use-date-string.ts +++ b/integration/grpc-js-use-date-string/grpc-js-use-date-string.ts @@ -24,7 +24,7 @@ function createBaseTimestampMessage(): TimestampMessage { return { timestamp: undefined }; } -export const TimestampMessage = { +export const TimestampMessage: MessageFns = { encode(message: TimestampMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.timestamp !== undefined) { Timestamp.encode(toTimestamp(message.timestamp), writer.uint32(10).fork()).join(); @@ -168,3 +168,12 @@ function fromTimestamp(t: Timestamp): string { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/grpc-js-use-date-true/google/protobuf/timestamp.ts b/integration/grpc-js-use-date-true/google/protobuf/timestamp.ts index a4ccaeb2e..f4a29a6af 100644 --- a/integration/grpc-js-use-date-true/google/protobuf/timestamp.ts +++ b/integration/grpc-js-use-date-true/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -213,3 +213,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/grpc-js-use-date-true/grpc-js-use-date-true.ts b/integration/grpc-js-use-date-true/grpc-js-use-date-true.ts index 7ca85e325..411df50e6 100644 --- a/integration/grpc-js-use-date-true/grpc-js-use-date-true.ts +++ b/integration/grpc-js-use-date-true/grpc-js-use-date-true.ts @@ -24,7 +24,7 @@ function createBaseTimestampMessage(): TimestampMessage { return { timestamp: undefined }; } -export const TimestampMessage = { +export const TimestampMessage: MessageFns = { encode(message: TimestampMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.timestamp !== undefined) { Timestamp.encode(toTimestamp(message.timestamp), writer.uint32(10).fork()).join(); @@ -177,3 +177,12 @@ function fromJsonTimestamp(o: any): Date { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/grpc-js/google/protobuf/empty.ts b/integration/grpc-js/google/protobuf/empty.ts index 0cb5ae54e..f2d153f47 100644 --- a/integration/grpc-js/google/protobuf/empty.ts +++ b/integration/grpc-js/google/protobuf/empty.ts @@ -24,7 +24,7 @@ function createBaseEmpty(): Empty { return {}; } -export const Empty = { +export const Empty: MessageFns = { encode(_: Empty, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -74,3 +74,12 @@ export type DeepPartial = T extends Builtin ? T type KeysOfUnion = T extends T ? keyof T : never; export type Exact = P extends Builtin ? P : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/grpc-js/google/protobuf/struct.ts b/integration/grpc-js/google/protobuf/struct.ts index 5172cf05f..c89463b36 100644 --- a/integration/grpc-js/google/protobuf/struct.ts +++ b/integration/grpc-js/google/protobuf/struct.ts @@ -107,7 +107,7 @@ function createBaseStruct(): Struct { return { fields: {} }; } -export const Struct = { +export const Struct: MessageFns & StructWrapperFns = { encode(message: Struct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.fields).forEach(([key, value]) => { if (value !== undefined) { @@ -211,7 +211,7 @@ function createBaseStruct_FieldsEntry(): Struct_FieldsEntry { return { key: "", value: undefined }; } -export const Struct_FieldsEntry = { +export const Struct_FieldsEntry: MessageFns = { encode(message: Struct_FieldsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -292,7 +292,7 @@ function createBaseValue(): Value { }; } -export const Value = { +export const Value: MessageFns & AnyValueWrapperFns = { encode(message: Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.nullValue !== undefined) { writer.uint32(8).int32(message.nullValue); @@ -463,7 +463,7 @@ function createBaseListValue(): ListValue { return { values: [] }; } -export const ListValue = { +export const ListValue: MessageFns & ListValueWrapperFns = { encode(message: ListValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.values) { Value.encode(Value.wrap(v!), writer.uint32(10).fork()).join(); @@ -549,3 +549,27 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} + +export interface StructWrapperFns { + wrap(object: { [key: string]: any } | undefined): Struct; + unwrap(message: Struct): { [key: string]: any }; +} + +export interface AnyValueWrapperFns { + wrap(value: any): Value; + unwrap(message: any): string | number | boolean | Object | null | Array | undefined; +} + +export interface ListValueWrapperFns { + wrap(array: Array | undefined): ListValue; + unwrap(message: ListValue): Array; +} diff --git a/integration/grpc-js/google/protobuf/timestamp.ts b/integration/grpc-js/google/protobuf/timestamp.ts index a4ccaeb2e..f4a29a6af 100644 --- a/integration/grpc-js/google/protobuf/timestamp.ts +++ b/integration/grpc-js/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -213,3 +213,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/grpc-js/google/protobuf/wrappers.ts b/integration/grpc-js/google/protobuf/wrappers.ts index 52a93ce56..fd5825f88 100644 --- a/integration/grpc-js/google/protobuf/wrappers.ts +++ b/integration/grpc-js/google/protobuf/wrappers.ts @@ -100,7 +100,7 @@ function createBaseDoubleValue(): DoubleValue { return { value: 0 }; } -export const DoubleValue = { +export const DoubleValue: MessageFns = { encode(message: DoubleValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(9).double(message.value); @@ -157,7 +157,7 @@ function createBaseFloatValue(): FloatValue { return { value: 0 }; } -export const FloatValue = { +export const FloatValue: MessageFns = { encode(message: FloatValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(13).float(message.value); @@ -214,7 +214,7 @@ function createBaseInt64Value(): Int64Value { return { value: 0 }; } -export const Int64Value = { +export const Int64Value: MessageFns = { encode(message: Int64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int64(message.value); @@ -271,7 +271,7 @@ function createBaseUInt64Value(): UInt64Value { return { value: 0 }; } -export const UInt64Value = { +export const UInt64Value: MessageFns = { encode(message: UInt64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint64(message.value); @@ -328,7 +328,7 @@ function createBaseInt32Value(): Int32Value { return { value: 0 }; } -export const Int32Value = { +export const Int32Value: MessageFns = { encode(message: Int32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int32(message.value); @@ -385,7 +385,7 @@ function createBaseUInt32Value(): UInt32Value { return { value: 0 }; } -export const UInt32Value = { +export const UInt32Value: MessageFns = { encode(message: UInt32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint32(message.value); @@ -442,7 +442,7 @@ function createBaseBoolValue(): BoolValue { return { value: false }; } -export const BoolValue = { +export const BoolValue: MessageFns = { encode(message: BoolValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== false) { writer.uint32(8).bool(message.value); @@ -499,7 +499,7 @@ function createBaseStringValue(): StringValue { return { value: "" }; } -export const StringValue = { +export const StringValue: MessageFns = { encode(message: StringValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "") { writer.uint32(10).string(message.value); @@ -556,7 +556,7 @@ function createBaseBytesValue(): BytesValue { return { value: new Uint8Array(0) }; } -export const BytesValue = { +export const BytesValue: MessageFns = { encode(message: BytesValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value.length !== 0) { writer.uint32(10).bytes(message.value); @@ -660,3 +660,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/grpc-js/simple.ts b/integration/grpc-js/simple.ts index 35629b2a8..4114bc5b2 100644 --- a/integration/grpc-js/simple.ts +++ b/integration/grpc-js/simple.ts @@ -48,7 +48,7 @@ function createBaseTestMessage(): TestMessage { return { timestamp: undefined }; } -export const TestMessage = { +export const TestMessage: MessageFns = { encode(message: TestMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.timestamp !== undefined) { Timestamp.encode(toTimestamp(message.timestamp), writer.uint32(10).fork()).join(); @@ -674,3 +674,12 @@ function fromJsonTimestamp(o: any): Date { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/grpc-web-abort-signal/example.ts b/integration/grpc-web-abort-signal/example.ts index 8bc6efca4..4f3f9d338 100644 --- a/integration/grpc-web-abort-signal/example.ts +++ b/integration/grpc-web-abort-signal/example.ts @@ -102,7 +102,7 @@ function createBaseDashFlash(): DashFlash { return { msg: "", type: 0 }; } -export const DashFlash = { +export const DashFlash: MessageFns = { encode(message: DashFlash, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.msg !== "") { writer.uint32(10).string(message.msg); @@ -176,7 +176,7 @@ function createBaseDashUserSettingsState(): DashUserSettingsState { return { email: "", urls: undefined, flashes: [] }; } -export const DashUserSettingsState = { +export const DashUserSettingsState: MessageFns = { encode(message: DashUserSettingsState, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.email !== "") { writer.uint32(10).string(message.email); @@ -267,7 +267,7 @@ function createBaseDashUserSettingsState_URLs(): DashUserSettingsState_URLs { return { connectGoogle: "", connectGithub: "" }; } -export const DashUserSettingsState_URLs = { +export const DashUserSettingsState_URLs: MessageFns = { encode(message: DashUserSettingsState_URLs, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.connectGoogle !== "") { writer.uint32(10).string(message.connectGoogle); @@ -341,7 +341,7 @@ function createBaseDashCred(): DashCred { return { description: "", metadata: "", token: "", id: "" }; } -export const DashCred = { +export const DashCred: MessageFns = { encode(message: DashCred, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.description !== "") { writer.uint32(18).string(message.description); @@ -445,7 +445,7 @@ function createBaseDashAPICredsCreateReq(): DashAPICredsCreateReq { return { description: "", metadata: "" }; } -export const DashAPICredsCreateReq = { +export const DashAPICredsCreateReq: MessageFns = { encode(message: DashAPICredsCreateReq, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.description !== "") { writer.uint32(10).string(message.description); @@ -519,7 +519,7 @@ function createBaseDashAPICredsUpdateReq(): DashAPICredsUpdateReq { return { credSid: "", description: "", metadata: "", id: "" }; } -export const DashAPICredsUpdateReq = { +export const DashAPICredsUpdateReq: MessageFns = { encode(message: DashAPICredsUpdateReq, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.credSid !== "") { writer.uint32(10).string(message.credSid); @@ -623,7 +623,7 @@ function createBaseDashAPICredsDeleteReq(): DashAPICredsDeleteReq { return { credSid: "", id: "" }; } -export const DashAPICredsDeleteReq = { +export const DashAPICredsDeleteReq: MessageFns = { encode(message: DashAPICredsDeleteReq, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.credSid !== "") { writer.uint32(10).string(message.credSid); @@ -697,7 +697,7 @@ function createBaseEmpty(): Empty { return {}; } -export const Empty = { +export const Empty: MessageFns = { encode(_: Empty, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -1129,3 +1129,12 @@ export class GrpcWebError extends globalThis.Error { super(message); } } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/grpc-web-go-server/example.ts b/integration/grpc-web-go-server/example.ts index cef8a4964..cc0c1a207 100644 --- a/integration/grpc-web-go-server/example.ts +++ b/integration/grpc-web-go-server/example.ts @@ -100,7 +100,7 @@ function createBaseDashFlash(): DashFlash { return { msg: "", type: 0 }; } -export const DashFlash = { +export const DashFlash: MessageFns = { encode(message: DashFlash, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.msg !== "") { writer.uint32(10).string(message.msg); @@ -174,7 +174,7 @@ function createBaseDashUserSettingsState(): DashUserSettingsState { return { email: "", urls: undefined, flashes: [] }; } -export const DashUserSettingsState = { +export const DashUserSettingsState: MessageFns = { encode(message: DashUserSettingsState, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.email !== "") { writer.uint32(10).string(message.email); @@ -265,7 +265,7 @@ function createBaseDashUserSettingsState_URLs(): DashUserSettingsState_URLs { return { connectGoogle: "", connectGithub: "" }; } -export const DashUserSettingsState_URLs = { +export const DashUserSettingsState_URLs: MessageFns = { encode(message: DashUserSettingsState_URLs, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.connectGoogle !== "") { writer.uint32(10).string(message.connectGoogle); @@ -339,7 +339,7 @@ function createBaseDashCred(): DashCred { return { description: "", metadata: "", token: "", id: "" }; } -export const DashCred = { +export const DashCred: MessageFns = { encode(message: DashCred, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.description !== "") { writer.uint32(18).string(message.description); @@ -443,7 +443,7 @@ function createBaseDashAPICredsCreateReq(): DashAPICredsCreateReq { return { description: "", metadata: "" }; } -export const DashAPICredsCreateReq = { +export const DashAPICredsCreateReq: MessageFns = { encode(message: DashAPICredsCreateReq, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.description !== "") { writer.uint32(10).string(message.description); @@ -517,7 +517,7 @@ function createBaseDashAPICredsUpdateReq(): DashAPICredsUpdateReq { return { credSid: "", description: "", metadata: "", id: "" }; } -export const DashAPICredsUpdateReq = { +export const DashAPICredsUpdateReq: MessageFns = { encode(message: DashAPICredsUpdateReq, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.credSid !== "") { writer.uint32(10).string(message.credSid); @@ -621,7 +621,7 @@ function createBaseDashAPICredsDeleteReq(): DashAPICredsDeleteReq { return { credSid: "", id: "" }; } -export const DashAPICredsDeleteReq = { +export const DashAPICredsDeleteReq: MessageFns = { encode(message: DashAPICredsDeleteReq, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.credSid !== "") { writer.uint32(10).string(message.credSid); @@ -695,7 +695,7 @@ function createBaseEmpty(): Empty { return {}; } -export const Empty = { +export const Empty: MessageFns = { encode(_: Empty, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -825,3 +825,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/grpc-web-no-streaming-observable/example.ts b/integration/grpc-web-no-streaming-observable/example.ts index d0c0798d5..9ccd929b2 100644 --- a/integration/grpc-web-no-streaming-observable/example.ts +++ b/integration/grpc-web-no-streaming-observable/example.ts @@ -78,7 +78,7 @@ function createBaseDashFlash(): DashFlash { return { msg: "", type: 0 }; } -export const DashFlash = { +export const DashFlash: MessageFns = { encode(message: DashFlash, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.msg !== "") { writer.uint32(10).string(message.msg); @@ -152,7 +152,7 @@ function createBaseDashUserSettingsState(): DashUserSettingsState { return { email: "", urls: undefined, flashes: [] }; } -export const DashUserSettingsState = { +export const DashUserSettingsState: MessageFns = { encode(message: DashUserSettingsState, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.email !== "") { writer.uint32(10).string(message.email); @@ -243,7 +243,7 @@ function createBaseDashUserSettingsState_URLs(): DashUserSettingsState_URLs { return { connectGoogle: "", connectGithub: "" }; } -export const DashUserSettingsState_URLs = { +export const DashUserSettingsState_URLs: MessageFns = { encode(message: DashUserSettingsState_URLs, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.connectGoogle !== "") { writer.uint32(10).string(message.connectGoogle); @@ -317,7 +317,7 @@ function createBaseEmpty(): Empty { return {}; } -export const Empty = { +export const Empty: MessageFns = { encode(_: Empty, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -492,3 +492,12 @@ export class GrpcWebError extends globalThis.Error { super(message); } } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/grpc-web-no-streaming/example.ts b/integration/grpc-web-no-streaming/example.ts index 6777463a1..61b1ac7bc 100644 --- a/integration/grpc-web-no-streaming/example.ts +++ b/integration/grpc-web-no-streaming/example.ts @@ -76,7 +76,7 @@ function createBaseDashFlash(): DashFlash { return { msg: "", type: 0 }; } -export const DashFlash = { +export const DashFlash: MessageFns = { encode(message: DashFlash, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.msg !== "") { writer.uint32(10).string(message.msg); @@ -150,7 +150,7 @@ function createBaseDashUserSettingsState(): DashUserSettingsState { return { email: "", urls: undefined, flashes: [] }; } -export const DashUserSettingsState = { +export const DashUserSettingsState: MessageFns = { encode(message: DashUserSettingsState, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.email !== "") { writer.uint32(10).string(message.email); @@ -241,7 +241,7 @@ function createBaseDashUserSettingsState_URLs(): DashUserSettingsState_URLs { return { connectGoogle: "", connectGithub: "" }; } -export const DashUserSettingsState_URLs = { +export const DashUserSettingsState_URLs: MessageFns = { encode(message: DashUserSettingsState_URLs, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.connectGoogle !== "") { writer.uint32(10).string(message.connectGoogle); @@ -315,7 +315,7 @@ function createBaseEmpty(): Empty { return {}; } -export const Empty = { +export const Empty: MessageFns = { encode(_: Empty, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -489,3 +489,12 @@ export class GrpcWebError extends globalThis.Error { super(message); } } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/grpc-web/example.ts b/integration/grpc-web/example.ts index b852672ea..e46681066 100644 --- a/integration/grpc-web/example.ts +++ b/integration/grpc-web/example.ts @@ -103,7 +103,7 @@ function createBaseDashFlash(): DashFlash { return { msg: "", type: 0 }; } -export const DashFlash = { +export const DashFlash: MessageFns = { encode(message: DashFlash, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.msg !== "") { writer.uint32(10).string(message.msg); @@ -177,7 +177,7 @@ function createBaseDashUserSettingsState(): DashUserSettingsState { return { email: "", urls: undefined, flashes: [] }; } -export const DashUserSettingsState = { +export const DashUserSettingsState: MessageFns = { encode(message: DashUserSettingsState, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.email !== "") { writer.uint32(10).string(message.email); @@ -268,7 +268,7 @@ function createBaseDashUserSettingsState_URLs(): DashUserSettingsState_URLs { return { connectGoogle: "", connectGithub: "" }; } -export const DashUserSettingsState_URLs = { +export const DashUserSettingsState_URLs: MessageFns = { encode(message: DashUserSettingsState_URLs, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.connectGoogle !== "") { writer.uint32(10).string(message.connectGoogle); @@ -342,7 +342,7 @@ function createBaseDashCred(): DashCred { return { description: "", metadata: "", token: "", id: "" }; } -export const DashCred = { +export const DashCred: MessageFns = { encode(message: DashCred, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.description !== "") { writer.uint32(18).string(message.description); @@ -446,7 +446,7 @@ function createBaseDashAPICredsCreateReq(): DashAPICredsCreateReq { return { description: "", metadata: "" }; } -export const DashAPICredsCreateReq = { +export const DashAPICredsCreateReq: MessageFns = { encode(message: DashAPICredsCreateReq, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.description !== "") { writer.uint32(10).string(message.description); @@ -520,7 +520,7 @@ function createBaseDashAPICredsUpdateReq(): DashAPICredsUpdateReq { return { credSid: "", description: "", metadata: "", id: "" }; } -export const DashAPICredsUpdateReq = { +export const DashAPICredsUpdateReq: MessageFns = { encode(message: DashAPICredsUpdateReq, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.credSid !== "") { writer.uint32(10).string(message.credSid); @@ -624,7 +624,7 @@ function createBaseDashAPICredsDeleteReq(): DashAPICredsDeleteReq { return { credSid: "", id: "" }; } -export const DashAPICredsDeleteReq = { +export const DashAPICredsDeleteReq: MessageFns = { encode(message: DashAPICredsDeleteReq, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.credSid !== "") { writer.uint32(10).string(message.credSid); @@ -698,7 +698,7 @@ function createBaseEmpty(): Empty { return {}; } -export const Empty = { +export const Empty: MessageFns = { encode(_: Empty, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -1089,3 +1089,12 @@ export class GrpcWebError extends globalThis.Error { super(message); } } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/grpc-web/google/protobuf/wrappers.ts b/integration/grpc-web/google/protobuf/wrappers.ts index 52a93ce56..fd5825f88 100644 --- a/integration/grpc-web/google/protobuf/wrappers.ts +++ b/integration/grpc-web/google/protobuf/wrappers.ts @@ -100,7 +100,7 @@ function createBaseDoubleValue(): DoubleValue { return { value: 0 }; } -export const DoubleValue = { +export const DoubleValue: MessageFns = { encode(message: DoubleValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(9).double(message.value); @@ -157,7 +157,7 @@ function createBaseFloatValue(): FloatValue { return { value: 0 }; } -export const FloatValue = { +export const FloatValue: MessageFns = { encode(message: FloatValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(13).float(message.value); @@ -214,7 +214,7 @@ function createBaseInt64Value(): Int64Value { return { value: 0 }; } -export const Int64Value = { +export const Int64Value: MessageFns = { encode(message: Int64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int64(message.value); @@ -271,7 +271,7 @@ function createBaseUInt64Value(): UInt64Value { return { value: 0 }; } -export const UInt64Value = { +export const UInt64Value: MessageFns = { encode(message: UInt64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint64(message.value); @@ -328,7 +328,7 @@ function createBaseInt32Value(): Int32Value { return { value: 0 }; } -export const Int32Value = { +export const Int32Value: MessageFns = { encode(message: Int32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int32(message.value); @@ -385,7 +385,7 @@ function createBaseUInt32Value(): UInt32Value { return { value: 0 }; } -export const UInt32Value = { +export const UInt32Value: MessageFns = { encode(message: UInt32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint32(message.value); @@ -442,7 +442,7 @@ function createBaseBoolValue(): BoolValue { return { value: false }; } -export const BoolValue = { +export const BoolValue: MessageFns = { encode(message: BoolValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== false) { writer.uint32(8).bool(message.value); @@ -499,7 +499,7 @@ function createBaseStringValue(): StringValue { return { value: "" }; } -export const StringValue = { +export const StringValue: MessageFns = { encode(message: StringValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "") { writer.uint32(10).string(message.value); @@ -556,7 +556,7 @@ function createBaseBytesValue(): BytesValue { return { value: new Uint8Array(0) }; } -export const BytesValue = { +export const BytesValue: MessageFns = { encode(message: BytesValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value.length !== 0) { writer.uint32(10).bytes(message.value); @@ -660,3 +660,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/handle-error-in-default-service/simple.ts b/integration/handle-error-in-default-service/simple.ts index f73625d54..5aace25fe 100644 --- a/integration/handle-error-in-default-service/simple.ts +++ b/integration/handle-error-in-default-service/simple.ts @@ -18,7 +18,7 @@ function createBaseGetBasicRequest(): GetBasicRequest { return { name: "" }; } -export const GetBasicRequest = { +export const GetBasicRequest: MessageFns = { encode(message: GetBasicRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -75,7 +75,7 @@ function createBaseGetBasicResponse(): GetBasicResponse { return { name: "" }; } -export const GetBasicResponse = { +export const GetBasicResponse: MessageFns = { encode(message: GetBasicResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -179,3 +179,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/handle-error-with-after-response/simple.ts b/integration/handle-error-with-after-response/simple.ts index a3f8a5a4c..9dbbaeeed 100644 --- a/integration/handle-error-with-after-response/simple.ts +++ b/integration/handle-error-with-after-response/simple.ts @@ -18,7 +18,7 @@ function createBaseGetBasicRequest(): GetBasicRequest { return { name: "" }; } -export const GetBasicRequest = { +export const GetBasicRequest: MessageFns = { encode(message: GetBasicRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -75,7 +75,7 @@ function createBaseGetBasicResponse(): GetBasicResponse { return { name: "" }; } -export const GetBasicResponse = { +export const GetBasicResponse: MessageFns = { encode(message: GetBasicResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -184,3 +184,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/import-mapping/google/protobuf/timestamp.ts b/integration/import-mapping/google/protobuf/timestamp.ts index a4ccaeb2e..f4a29a6af 100644 --- a/integration/import-mapping/google/protobuf/timestamp.ts +++ b/integration/import-mapping/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -213,3 +213,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/import-mapping/mapping.ts b/integration/import-mapping/mapping.ts index 51c32a5a7..a1f6d6dc8 100644 --- a/integration/import-mapping/mapping.ts +++ b/integration/import-mapping/mapping.ts @@ -35,7 +35,7 @@ function createBaseWithEmtpy(): WithEmtpy { return { empty: undefined }; } -export const WithEmtpy = { +export const WithEmtpy: MessageFns = { encode(message: WithEmtpy, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.empty !== undefined) { Empty.encode(message.empty, writer.uint32(10).fork()).join(); @@ -92,7 +92,7 @@ function createBaseWithStruct(): WithStruct { return { strut: undefined }; } -export const WithStruct = { +export const WithStruct: MessageFns = { encode(message: WithStruct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.strut !== undefined) { Struct.encode(Struct.wrap(message.strut), writer.uint32(10).fork()).join(); @@ -149,7 +149,7 @@ function createBaseWithTimestamp(): WithTimestamp { return { timestamp: undefined }; } -export const WithTimestamp = { +export const WithTimestamp: MessageFns = { encode(message: WithTimestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.timestamp !== undefined) { Timestamp.encode(toTimestamp(message.timestamp), writer.uint32(10).fork()).join(); @@ -206,7 +206,7 @@ function createBaseWithAll(): WithAll { return { empty: undefined, strut: undefined, timestamp: undefined, duration: undefined, veryVerySecret: undefined }; } -export const WithAll = { +export const WithAll: MessageFns = { encode(message: WithAll, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.empty !== undefined) { Empty.encode(message.empty, writer.uint32(10).fork()).join(); @@ -366,3 +366,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/import-suffix/child.pb.ts b/integration/import-suffix/child.pb.ts index 0546e5c72..3c7f7a16b 100644 --- a/integration/import-suffix/child.pb.ts +++ b/integration/import-suffix/child.pb.ts @@ -47,7 +47,7 @@ function createBaseChild(): Child { return { name: "" }; } -export const Child = { +export const Child: MessageFns = { encode(message: Child, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -115,3 +115,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/import-suffix/google/protobuf/timestamp.pb.ts b/integration/import-suffix/google/protobuf/timestamp.pb.ts index a4ccaeb2e..f4a29a6af 100644 --- a/integration/import-suffix/google/protobuf/timestamp.pb.ts +++ b/integration/import-suffix/google/protobuf/timestamp.pb.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -213,3 +213,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/import-suffix/parent.pb.ts b/integration/import-suffix/parent.pb.ts index 24c542818..4eeddc7f1 100644 --- a/integration/import-suffix/parent.pb.ts +++ b/integration/import-suffix/parent.pb.ts @@ -18,7 +18,7 @@ function createBaseParent(): Parent { return { child: undefined, childEnum: 0, createdAt: undefined }; } -export const Parent = { +export const Parent: MessageFns = { encode(message: Parent, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.child !== undefined) { Child.encode(message.child, writer.uint32(10).fork()).join(); @@ -140,3 +140,12 @@ function fromJsonTimestamp(o: any): Date { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/lower-case-svc-methods/math.ts b/integration/lower-case-svc-methods/math.ts index 2be73b4c9..b67b6cd81 100644 --- a/integration/lower-case-svc-methods/math.ts +++ b/integration/lower-case-svc-methods/math.ts @@ -25,7 +25,7 @@ function createBaseNumPair(): NumPair { return { num1: 0, num2: 0 }; } -export const NumPair = { +export const NumPair: MessageFns = { encode(message: NumPair, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.num1 !== 0) { writer.uint32(9).double(message.num1); @@ -99,7 +99,7 @@ function createBaseNumSingle(): NumSingle { return { num: 0 }; } -export const NumSingle = { +export const NumSingle: MessageFns = { encode(message: NumSingle, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.num !== 0) { writer.uint32(9).double(message.num); @@ -156,7 +156,7 @@ function createBaseNumbers(): Numbers { return { num: [] }; } -export const Numbers = { +export const Numbers: MessageFns = { encode(message: Numbers, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { writer.uint32(10).fork(); for (const v of message.num) { @@ -296,3 +296,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/map-bigint-optional/test.ts b/integration/map-bigint-optional/test.ts index 40d8fdafe..6b6de7957 100644 --- a/integration/map-bigint-optional/test.ts +++ b/integration/map-bigint-optional/test.ts @@ -21,7 +21,7 @@ function createBaseMapBigInt(): MapBigInt { return {}; } -export const MapBigInt = { +export const MapBigInt: MessageFns = { encode(message: MapBigInt, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { (message.map || new Map()).forEach((value, key) => { MapBigInt_MapEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).join(); @@ -122,7 +122,7 @@ function createBaseMapBigInt_MapEntry(): MapBigInt_MapEntry { return { key: 0n, value: 0n }; } -export const MapBigInt_MapEntry = { +export const MapBigInt_MapEntry: MessageFns = { encode(message: MapBigInt_MapEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0n) { if (BigInt.asUintN(64, message.key) !== message.key) { @@ -234,3 +234,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/map-long-optional/test.ts b/integration/map-long-optional/test.ts index 1731a9ffc..ccd3bccb9 100644 --- a/integration/map-long-optional/test.ts +++ b/integration/map-long-optional/test.ts @@ -22,7 +22,7 @@ function createBaseMapBigInt(): MapBigInt { return {}; } -export const MapBigInt = { +export const MapBigInt: MessageFns = { encode(message: MapBigInt, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { (message.map || new Map()).forEach((value, key) => { MapBigInt_MapEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).join(); @@ -123,7 +123,7 @@ function createBaseMapBigInt_MapEntry(): MapBigInt_MapEntry { return { key: Long.UZERO, value: Long.ZERO }; } -export const MapBigInt_MapEntry = { +export const MapBigInt_MapEntry: MessageFns = { encode(message: MapBigInt_MapEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (!message.key.equals(Long.UZERO)) { writer.uint32(9).fixed64(message.key.toString()); @@ -243,3 +243,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/map-longstring-optional/test.ts b/integration/map-longstring-optional/test.ts index 074099f21..6db328d33 100644 --- a/integration/map-longstring-optional/test.ts +++ b/integration/map-longstring-optional/test.ts @@ -21,7 +21,7 @@ function createBaseMapBigInt(): MapBigInt { return {}; } -export const MapBigInt = { +export const MapBigInt: MessageFns = { encode(message: MapBigInt, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { (message.map || new Map()).forEach((value, key) => { MapBigInt_MapEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).join(); @@ -122,7 +122,7 @@ function createBaseMapBigInt_MapEntry(): MapBigInt_MapEntry { return { key: "0", value: "0" }; } -export const MapBigInt_MapEntry = { +export const MapBigInt_MapEntry: MessageFns = { encode(message: MapBigInt_MapEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "0") { writer.uint32(9).fixed64(message.key); @@ -231,3 +231,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/meta-typings-as-const/google/protobuf/descriptor.ts b/integration/meta-typings-as-const/google/protobuf/descriptor.ts index 2bab0f690..7579b9165 100644 --- a/integration/meta-typings-as-const/google/protobuf/descriptor.ts +++ b/integration/meta-typings-as-const/google/protobuf/descriptor.ts @@ -959,7 +959,7 @@ function createBaseFileDescriptorSet(): FileDescriptorSet { return { file: [] }; } -export const FileDescriptorSet = { +export const FileDescriptorSet: MessageFns = { encode(message: FileDescriptorSet, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.file) { FileDescriptorProto.encode(v!, writer.uint32(10).fork()).join(); @@ -1008,7 +1008,7 @@ function createBaseFileDescriptorProto(): FileDescriptorProto { }; } -export const FileDescriptorProto = { +export const FileDescriptorProto: MessageFns = { encode(message: FileDescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -1189,7 +1189,7 @@ function createBaseDescriptorProto(): DescriptorProto { }; } -export const DescriptorProto = { +export const DescriptorProto: MessageFns = { encode(message: DescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -1315,7 +1315,7 @@ function createBaseDescriptorProto_ExtensionRange(): DescriptorProto_ExtensionRa return { start: 0, end: 0, options: undefined }; } -export const DescriptorProto_ExtensionRange = { +export const DescriptorProto_ExtensionRange: MessageFns = { encode(message: DescriptorProto_ExtensionRange, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.start !== undefined && message.start !== 0) { writer.uint32(8).int32(message.start); @@ -1371,7 +1371,7 @@ function createBaseDescriptorProto_ReservedRange(): DescriptorProto_ReservedRang return { start: 0, end: 0 }; } -export const DescriptorProto_ReservedRange = { +export const DescriptorProto_ReservedRange: MessageFns = { encode(message: DescriptorProto_ReservedRange, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.start !== undefined && message.start !== 0) { writer.uint32(8).int32(message.start); @@ -1417,7 +1417,7 @@ function createBaseExtensionRangeOptions(): ExtensionRangeOptions { return { uninterpretedOption: [] }; } -export const ExtensionRangeOptions = { +export const ExtensionRangeOptions: MessageFns = { encode(message: ExtensionRangeOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.uninterpretedOption) { UninterpretedOption.encode(v!, writer.uint32(7994).fork()).join(); @@ -1465,7 +1465,7 @@ function createBaseFieldDescriptorProto(): FieldDescriptorProto { }; } -export const FieldDescriptorProto = { +export const FieldDescriptorProto: MessageFns = { encode(message: FieldDescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -1601,7 +1601,7 @@ function createBaseOneofDescriptorProto(): OneofDescriptorProto { return { name: "", options: undefined }; } -export const OneofDescriptorProto = { +export const OneofDescriptorProto: MessageFns = { encode(message: OneofDescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -1647,7 +1647,7 @@ function createBaseEnumDescriptorProto(): EnumDescriptorProto { return { name: "", value: [], options: undefined, reservedRange: [], reservedName: [] }; } -export const EnumDescriptorProto = { +export const EnumDescriptorProto: MessageFns = { encode(message: EnumDescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -1723,7 +1723,7 @@ function createBaseEnumDescriptorProto_EnumReservedRange(): EnumDescriptorProto_ return { start: 0, end: 0 }; } -export const EnumDescriptorProto_EnumReservedRange = { +export const EnumDescriptorProto_EnumReservedRange: MessageFns = { encode(message: EnumDescriptorProto_EnumReservedRange, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.start !== undefined && message.start !== 0) { writer.uint32(8).int32(message.start); @@ -1769,7 +1769,7 @@ function createBaseEnumValueDescriptorProto(): EnumValueDescriptorProto { return { name: "", number: 0, options: undefined }; } -export const EnumValueDescriptorProto = { +export const EnumValueDescriptorProto: MessageFns = { encode(message: EnumValueDescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -1825,7 +1825,7 @@ function createBaseServiceDescriptorProto(): ServiceDescriptorProto { return { name: "", method: [], options: undefined }; } -export const ServiceDescriptorProto = { +export const ServiceDescriptorProto: MessageFns = { encode(message: ServiceDescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -1888,7 +1888,7 @@ function createBaseMethodDescriptorProto(): MethodDescriptorProto { }; } -export const MethodDescriptorProto = { +export const MethodDescriptorProto: MessageFns = { encode(message: MethodDescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -1996,7 +1996,7 @@ function createBaseFileOptions(): FileOptions { }; } -export const FileOptions = { +export const FileOptions: MessageFns = { encode(message: FileOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.javaPackage !== undefined && message.javaPackage !== "") { writer.uint32(10).string(message.javaPackage); @@ -2238,7 +2238,7 @@ function createBaseMessageOptions(): MessageOptions { }; } -export const MessageOptions = { +export const MessageOptions: MessageFns = { encode(message: MessageOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.messageSetWireFormat !== undefined && message.messageSetWireFormat !== false) { writer.uint32(8).bool(message.messageSetWireFormat); @@ -2314,7 +2314,7 @@ function createBaseFieldOptions(): FieldOptions { return { ctype: 0, packed: false, jstype: 0, lazy: false, deprecated: false, weak: false, uninterpretedOption: [] }; } -export const FieldOptions = { +export const FieldOptions: MessageFns = { encode(message: FieldOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.ctype !== undefined && message.ctype !== 0) { writer.uint32(8).int32(message.ctype); @@ -2410,7 +2410,7 @@ function createBaseOneofOptions(): OneofOptions { return { uninterpretedOption: [] }; } -export const OneofOptions = { +export const OneofOptions: MessageFns = { encode(message: OneofOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.uninterpretedOption) { UninterpretedOption.encode(v!, writer.uint32(7994).fork()).join(); @@ -2446,7 +2446,7 @@ function createBaseEnumOptions(): EnumOptions { return { allowAlias: false, deprecated: false, uninterpretedOption: [] }; } -export const EnumOptions = { +export const EnumOptions: MessageFns = { encode(message: EnumOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.allowAlias !== undefined && message.allowAlias !== false) { writer.uint32(16).bool(message.allowAlias); @@ -2502,7 +2502,7 @@ function createBaseEnumValueOptions(): EnumValueOptions { return { deprecated: false, uninterpretedOption: [] }; } -export const EnumValueOptions = { +export const EnumValueOptions: MessageFns = { encode(message: EnumValueOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.deprecated !== undefined && message.deprecated !== false) { writer.uint32(8).bool(message.deprecated); @@ -2548,7 +2548,7 @@ function createBaseServiceOptions(): ServiceOptions { return { deprecated: false, uninterpretedOption: [] }; } -export const ServiceOptions = { +export const ServiceOptions: MessageFns = { encode(message: ServiceOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.deprecated !== undefined && message.deprecated !== false) { writer.uint32(264).bool(message.deprecated); @@ -2594,7 +2594,7 @@ function createBaseMethodOptions(): MethodOptions { return { deprecated: false, idempotencyLevel: 0, uninterpretedOption: [] }; } -export const MethodOptions = { +export const MethodOptions: MessageFns = { encode(message: MethodOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.deprecated !== undefined && message.deprecated !== false) { writer.uint32(264).bool(message.deprecated); @@ -2658,7 +2658,7 @@ function createBaseUninterpretedOption(): UninterpretedOption { }; } -export const UninterpretedOption = { +export const UninterpretedOption: MessageFns = { encode(message: UninterpretedOption, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.name) { UninterpretedOption_NamePart.encode(v!, writer.uint32(18).fork()).join(); @@ -2754,7 +2754,7 @@ function createBaseUninterpretedOption_NamePart(): UninterpretedOption_NamePart return { namePart: "", isExtension: false }; } -export const UninterpretedOption_NamePart = { +export const UninterpretedOption_NamePart: MessageFns = { encode(message: UninterpretedOption_NamePart, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.namePart !== "") { writer.uint32(10).string(message.namePart); @@ -2800,7 +2800,7 @@ function createBaseSourceCodeInfo(): SourceCodeInfo { return { location: [] }; } -export const SourceCodeInfo = { +export const SourceCodeInfo: MessageFns = { encode(message: SourceCodeInfo, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.location) { SourceCodeInfo_Location.encode(v!, writer.uint32(10).fork()).join(); @@ -2836,7 +2836,7 @@ function createBaseSourceCodeInfo_Location(): SourceCodeInfo_Location { return { path: [], span: [], leadingComments: "", trailingComments: "", leadingDetachedComments: [] }; } -export const SourceCodeInfo_Location = { +export const SourceCodeInfo_Location: MessageFns = { encode(message: SourceCodeInfo_Location, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { writer.uint32(10).fork(); for (const v of message.path) { @@ -2936,7 +2936,7 @@ function createBaseGeneratedCodeInfo(): GeneratedCodeInfo { return { annotation: [] }; } -export const GeneratedCodeInfo = { +export const GeneratedCodeInfo: MessageFns = { encode(message: GeneratedCodeInfo, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.annotation) { GeneratedCodeInfo_Annotation.encode(v!, writer.uint32(10).fork()).join(); @@ -2972,7 +2972,7 @@ function createBaseGeneratedCodeInfo_Annotation(): GeneratedCodeInfo_Annotation return { path: [], sourceFile: "", begin: 0, end: 0 }; } -export const GeneratedCodeInfo_Annotation = { +export const GeneratedCodeInfo_Annotation: MessageFns = { encode(message: GeneratedCodeInfo_Annotation, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { writer.uint32(10).fork(); for (const v of message.path) { @@ -5886,3 +5886,8 @@ function longToNumber(int64: { toString(): string }): number { } return num; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; +} diff --git a/integration/meta-typings-as-const/simple.ts b/integration/meta-typings-as-const/simple.ts index 52d1d1618..cec0afeae 100644 --- a/integration/meta-typings-as-const/simple.ts +++ b/integration/meta-typings-as-const/simple.ts @@ -23,7 +23,7 @@ function createBaseTest(): Test { return { enum: 0 }; } -export const Test = { +export const Test: MessageFns = { encode(message: Test, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.enum !== 0) { writer.uint32(8).int32(message.enum); @@ -150,3 +150,8 @@ export const protoMetadata = { enums: { "TestEnum": { values: { "VALUE_A": { "string_value": "A" }, "VALUE_B": { "string_value": "B" } } } }, }, } as const satisfies ProtoMetadata; + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; +} diff --git a/integration/meta-typings/google/protobuf/timestamp.ts b/integration/meta-typings/google/protobuf/timestamp.ts index 4a8251498..675be0f11 100644 --- a/integration/meta-typings/google/protobuf/timestamp.ts +++ b/integration/meta-typings/google/protobuf/timestamp.ts @@ -118,7 +118,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -290,3 +290,8 @@ function longToNumber(int64: { toString(): string }): number { } return num; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; +} diff --git a/integration/meta-typings/google/protobuf/wrappers.ts b/integration/meta-typings/google/protobuf/wrappers.ts index 3cc6619b8..3167d51e5 100644 --- a/integration/meta-typings/google/protobuf/wrappers.ts +++ b/integration/meta-typings/google/protobuf/wrappers.ts @@ -101,7 +101,7 @@ function createBaseDoubleValue(): DoubleValue { return { value: 0 }; } -export const DoubleValue = { +export const DoubleValue: MessageFns = { encode(message: DoubleValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(9).double(message.value); @@ -137,7 +137,7 @@ function createBaseFloatValue(): FloatValue { return { value: 0 }; } -export const FloatValue = { +export const FloatValue: MessageFns = { encode(message: FloatValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(13).float(message.value); @@ -173,7 +173,7 @@ function createBaseInt64Value(): Int64Value { return { value: 0 }; } -export const Int64Value = { +export const Int64Value: MessageFns = { encode(message: Int64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int64(message.value); @@ -209,7 +209,7 @@ function createBaseUInt64Value(): UInt64Value { return { value: 0 }; } -export const UInt64Value = { +export const UInt64Value: MessageFns = { encode(message: UInt64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint64(message.value); @@ -245,7 +245,7 @@ function createBaseInt32Value(): Int32Value { return { value: 0 }; } -export const Int32Value = { +export const Int32Value: MessageFns = { encode(message: Int32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int32(message.value); @@ -281,7 +281,7 @@ function createBaseUInt32Value(): UInt32Value { return { value: 0 }; } -export const UInt32Value = { +export const UInt32Value: MessageFns = { encode(message: UInt32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint32(message.value); @@ -317,7 +317,7 @@ function createBaseBoolValue(): BoolValue { return { value: false }; } -export const BoolValue = { +export const BoolValue: MessageFns = { encode(message: BoolValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== false) { writer.uint32(8).bool(message.value); @@ -353,7 +353,7 @@ function createBaseStringValue(): StringValue { return { value: "" }; } -export const StringValue = { +export const StringValue: MessageFns = { encode(message: StringValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "") { writer.uint32(10).string(message.value); @@ -389,7 +389,7 @@ function createBaseBytesValue(): BytesValue { return { value: new Uint8Array(0) }; } -export const BytesValue = { +export const BytesValue: MessageFns = { encode(message: BytesValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value.length !== 0) { writer.uint32(10).bytes(message.value); @@ -829,3 +829,8 @@ function longToNumber(int64: { toString(): string }): number { } return num; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; +} diff --git a/integration/meta-typings/google/type/date.ts b/integration/meta-typings/google/type/date.ts index 8e904f134..3412787e4 100644 --- a/integration/meta-typings/google/type/date.ts +++ b/integration/meta-typings/google/type/date.ts @@ -42,7 +42,7 @@ function createBaseDateMessage(): DateMessage { return { year: 0, month: 0, day: 0 }; } -export const DateMessage = { +export const DateMessage: MessageFns = { encode(message: DateMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.year !== 0) { writer.uint32(8).int32(message.year); @@ -231,3 +231,8 @@ export const protoMetadata: ProtoMetadata = { references: { ".google.type.DateMessage": DateMessage }, dependencies: [], }; + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; +} diff --git a/integration/meta-typings/import_dir/thing.ts b/integration/meta-typings/import_dir/thing.ts index 683a00209..6d57da4d2 100644 --- a/integration/meta-typings/import_dir/thing.ts +++ b/integration/meta-typings/import_dir/thing.ts @@ -16,7 +16,7 @@ function createBaseImportedThing(): ImportedThing { return { createdAt: undefined }; } -export const ImportedThing = { +export const ImportedThing: MessageFns = { encode(message: ImportedThing, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.createdAt !== undefined) { Timestamp.encode(toTimestamp(message.createdAt), writer.uint32(10).fork()).join(); @@ -122,3 +122,8 @@ function fromTimestamp(t: Timestamp): Date { millis += (t.nanos || 0) / 1_000_000; return new globalThis.Date(millis); } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; +} diff --git a/integration/meta-typings/simple.ts b/integration/meta-typings/simple.ts index cacbbb6f2..17a280f4c 100644 --- a/integration/meta-typings/simple.ts +++ b/integration/meta-typings/simple.ts @@ -212,7 +212,7 @@ function createBaseSimple(): Simple { }; } -export const Simple = { +export const Simple: MessageFns = { encode(message: Simple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -392,7 +392,7 @@ function createBaseChild(): Child { return { name: "", type: 0 }; } -export const Child = { +export const Child: MessageFns = { encode(message: Child, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -438,7 +438,7 @@ function createBaseNested(): Nested { return { name: "", message: undefined, state: 0 }; } -export const Nested = { +export const Nested: MessageFns = { encode(message: Nested, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -494,7 +494,7 @@ function createBaseNested_InnerMessage(): Nested_InnerMessage { return { name: "", deep: undefined }; } -export const Nested_InnerMessage = { +export const Nested_InnerMessage: MessageFns = { encode(message: Nested_InnerMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -540,7 +540,7 @@ function createBaseNested_InnerMessage_DeepMessage(): Nested_InnerMessage_DeepMe return { name: "" }; } -export const Nested_InnerMessage_DeepMessage = { +export const Nested_InnerMessage_DeepMessage: MessageFns = { encode(message: Nested_InnerMessage_DeepMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -576,7 +576,7 @@ function createBaseOneOfMessage(): OneOfMessage { return { first: undefined, last: undefined }; } -export const OneOfMessage = { +export const OneOfMessage: MessageFns = { encode(message: OneOfMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.first !== undefined) { writer.uint32(10).string(message.first); @@ -622,7 +622,7 @@ function createBaseSimpleWithWrappers(): SimpleWithWrappers { return { name: undefined, age: undefined, enabled: undefined, coins: [], snacks: [] }; } -export const SimpleWithWrappers = { +export const SimpleWithWrappers: MessageFns = { encode(message: SimpleWithWrappers, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined) { StringValue.encode({ value: message.name! }, writer.uint32(10).fork()).join(); @@ -698,7 +698,7 @@ function createBaseEntity(): Entity { return { id: 0 }; } -export const Entity = { +export const Entity: MessageFns = { encode(message: Entity, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== 0) { writer.uint32(8).int32(message.id); @@ -734,7 +734,7 @@ function createBaseSimpleWithMap(): SimpleWithMap { return { entitiesById: {}, nameLookup: {}, intLookup: {}, mapOfTimestamps: {}, mapOfBytes: {} }; } -export const SimpleWithMap = { +export const SimpleWithMap: MessageFns = { encode(message: SimpleWithMap, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.entitiesById).forEach(([key, value]) => { SimpleWithMap_EntitiesByIdEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).join(); @@ -825,7 +825,7 @@ function createBaseSimpleWithMap_EntitiesByIdEntry(): SimpleWithMap_EntitiesById return { key: 0, value: undefined }; } -export const SimpleWithMap_EntitiesByIdEntry = { +export const SimpleWithMap_EntitiesByIdEntry: MessageFns = { encode(message: SimpleWithMap_EntitiesByIdEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int32(message.key); @@ -871,7 +871,7 @@ function createBaseSimpleWithMap_NameLookupEntry(): SimpleWithMap_NameLookupEntr return { key: "", value: "" }; } -export const SimpleWithMap_NameLookupEntry = { +export const SimpleWithMap_NameLookupEntry: MessageFns = { encode(message: SimpleWithMap_NameLookupEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -917,7 +917,7 @@ function createBaseSimpleWithMap_IntLookupEntry(): SimpleWithMap_IntLookupEntry return { key: 0, value: 0 }; } -export const SimpleWithMap_IntLookupEntry = { +export const SimpleWithMap_IntLookupEntry: MessageFns = { encode(message: SimpleWithMap_IntLookupEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int32(message.key); @@ -963,7 +963,7 @@ function createBaseSimpleWithMap_MapOfTimestampsEntry(): SimpleWithMap_MapOfTime return { key: "", value: undefined }; } -export const SimpleWithMap_MapOfTimestampsEntry = { +export const SimpleWithMap_MapOfTimestampsEntry: MessageFns = { encode(message: SimpleWithMap_MapOfTimestampsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -1009,7 +1009,7 @@ function createBaseSimpleWithMap_MapOfBytesEntry(): SimpleWithMap_MapOfBytesEntr return { key: "", value: new Uint8Array(0) }; } -export const SimpleWithMap_MapOfBytesEntry = { +export const SimpleWithMap_MapOfBytesEntry: MessageFns = { encode(message: SimpleWithMap_MapOfBytesEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -1055,7 +1055,7 @@ function createBaseSimpleWithSnakeCaseMap(): SimpleWithSnakeCaseMap { return { entitiesById: {} }; } -export const SimpleWithSnakeCaseMap = { +export const SimpleWithSnakeCaseMap: MessageFns = { encode(message: SimpleWithSnakeCaseMap, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.entitiesById).forEach(([key, value]) => { SimpleWithSnakeCaseMap_EntitiesByIdEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).join(); @@ -1094,7 +1094,7 @@ function createBaseSimpleWithSnakeCaseMap_EntitiesByIdEntry(): SimpleWithSnakeCa return { key: 0, value: undefined }; } -export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { +export const SimpleWithSnakeCaseMap_EntitiesByIdEntry: MessageFns = { encode(message: SimpleWithSnakeCaseMap_EntitiesByIdEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int32(message.key); @@ -1140,7 +1140,7 @@ function createBaseSimpleWithMapOfEnums(): SimpleWithMapOfEnums { return { enumsById: {} }; } -export const SimpleWithMapOfEnums = { +export const SimpleWithMapOfEnums: MessageFns = { encode(message: SimpleWithMapOfEnums, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.enumsById).forEach(([key, value]) => { SimpleWithMapOfEnums_EnumsByIdEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).join(); @@ -1179,7 +1179,7 @@ function createBaseSimpleWithMapOfEnums_EnumsByIdEntry(): SimpleWithMapOfEnums_E return { key: 0, value: 0 }; } -export const SimpleWithMapOfEnums_EnumsByIdEntry = { +export const SimpleWithMapOfEnums_EnumsByIdEntry: MessageFns = { encode(message: SimpleWithMapOfEnums_EnumsByIdEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int32(message.key); @@ -1225,7 +1225,7 @@ function createBasePingRequest(): PingRequest { return { input: "" }; } -export const PingRequest = { +export const PingRequest: MessageFns = { encode(message: PingRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.input !== "") { writer.uint32(10).string(message.input); @@ -1261,7 +1261,7 @@ function createBasePingResponse(): PingResponse { return { output: "" }; } -export const PingResponse = { +export const PingResponse: MessageFns = { encode(message: PingResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.output !== "") { writer.uint32(10).string(message.output); @@ -1310,7 +1310,7 @@ function createBaseNumbers(): Numbers { }; } -export const Numbers = { +export const Numbers: MessageFns = { encode(message: Numbers, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.double !== 0) { writer.uint32(9).double(message.double); @@ -1464,7 +1464,7 @@ function createBaseSimpleButOptional(): SimpleButOptional { }; } -export const SimpleButOptional = { +export const SimpleButOptional: MessageFns = { encode(message: SimpleButOptional, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined) { writer.uint32(10).string(message.name); @@ -1560,7 +1560,7 @@ function createBaseEmpty(): Empty { return {}; } -export const Empty = { +export const Empty: MessageFns = { encode(_: Empty, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -2974,3 +2974,8 @@ function longToNumber(int64: { toString(): string }): number { } return num; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; +} diff --git a/integration/nestjs-metadata-grpc-js/hero.ts b/integration/nestjs-metadata-grpc-js/hero.ts index c6025bbef..c3fa241d0 100644 --- a/integration/nestjs-metadata-grpc-js/hero.ts +++ b/integration/nestjs-metadata-grpc-js/hero.ts @@ -34,7 +34,7 @@ function createBaseHeroById(): HeroById { return { id: 0 }; } -export const HeroById = { +export const HeroById: MessageFns = { encode(message: HeroById, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== 0) { writer.uint32(8).int32(message.id); @@ -70,7 +70,7 @@ function createBaseVillainById(): VillainById { return { id: 0 }; } -export const VillainById = { +export const VillainById: MessageFns = { encode(message: VillainById, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== 0) { writer.uint32(8).int32(message.id); @@ -106,7 +106,7 @@ function createBaseHero(): Hero { return { id: 0, name: "" }; } -export const Hero = { +export const Hero: MessageFns = { encode(message: Hero, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== 0) { writer.uint32(8).int32(message.id); @@ -152,7 +152,7 @@ function createBaseVillain(): Villain { return { id: 0, name: "" }; } -export const Villain = { +export const Villain: MessageFns = { encode(message: Villain, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== 0) { writer.uint32(8).int32(message.id); @@ -263,3 +263,8 @@ export interface HeroServiceServer extends UntypedServiceImplementation { findOneVillain: handleUnaryCall; findManyVillain: handleBidiStreamingCall; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; +} diff --git a/integration/nestjs-simple/google/protobuf/struct.ts b/integration/nestjs-simple/google/protobuf/struct.ts index 5d837581d..fa5fbe48a 100644 --- a/integration/nestjs-simple/google/protobuf/struct.ts +++ b/integration/nestjs-simple/google/protobuf/struct.ts @@ -87,7 +87,7 @@ function createBaseStruct(): Struct { return { fields: {} }; } -export const Struct = { +export const Struct: MessageFns & StructWrapperFns = { wrap(object: { [key: string]: any } | undefined): Struct { const struct = createBaseStruct(); @@ -114,7 +114,7 @@ function createBaseValue(): Value { return {}; } -export const Value = { +export const Value: MessageFns & AnyValueWrapperFns = { wrap(value: any): Value { const result = {} as any; if (value === null) { @@ -157,7 +157,7 @@ function createBaseListValue(): ListValue { return { values: [] }; } -export const ListValue = { +export const ListValue: MessageFns & ListValueWrapperFns = { wrap(array: Array | undefined): ListValue { const result = createBaseListValue(); result.values = (array ?? []).map(Value.wrap); @@ -193,3 +193,21 @@ const gt: any = (() => { } throw "Unable to locate global object"; })(); + +export interface MessageFns { +} + +export interface StructWrapperFns { + wrap(object: { [key: string]: any } | undefined): Struct; + unwrap(message: Struct): { [key: string]: any }; +} + +export interface AnyValueWrapperFns { + wrap(value: any): Value; + unwrap(message: any): string | number | boolean | Object | null | Array | undefined; +} + +export interface ListValueWrapperFns { + wrap(array: Array | undefined): ListValue; + unwrap(message: ListValue): Array; +} diff --git a/integration/nice-grpc/google/protobuf/empty.ts b/integration/nice-grpc/google/protobuf/empty.ts index cad0bed0f..b1e47c660 100644 --- a/integration/nice-grpc/google/protobuf/empty.ts +++ b/integration/nice-grpc/google/protobuf/empty.ts @@ -24,7 +24,7 @@ function createBaseEmpty(): Empty { return {}; } -export const Empty = { +export const Empty: MessageFns = { encode(_: Empty, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -70,3 +70,12 @@ export type DeepPartial = T extends Builtin ? T : T extends ReadonlyArray ? ReadonlyArray> : T extends {} ? { [K in keyof T]?: DeepPartial } : Partial; + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create(base?: DeepPartial): T; + fromPartial(object: DeepPartial): T; +} diff --git a/integration/nice-grpc/google/protobuf/struct.ts b/integration/nice-grpc/google/protobuf/struct.ts index e151eb658..e28486d69 100644 --- a/integration/nice-grpc/google/protobuf/struct.ts +++ b/integration/nice-grpc/google/protobuf/struct.ts @@ -107,7 +107,7 @@ function createBaseStruct(): Struct { return { fields: {} }; } -export const Struct = { +export const Struct: MessageFns & StructWrapperFns = { encode(message: Struct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.fields).forEach(([key, value]) => { if (value !== undefined) { @@ -211,7 +211,7 @@ function createBaseStruct_FieldsEntry(): Struct_FieldsEntry { return { key: "", value: undefined }; } -export const Struct_FieldsEntry = { +export const Struct_FieldsEntry: MessageFns = { encode(message: Struct_FieldsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -292,7 +292,7 @@ function createBaseValue(): Value { }; } -export const Value = { +export const Value: MessageFns & AnyValueWrapperFns = { encode(message: Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.nullValue !== undefined) { writer.uint32(8).int32(message.nullValue); @@ -463,7 +463,7 @@ function createBaseListValue(): ListValue { return { values: [] }; } -export const ListValue = { +export const ListValue: MessageFns & ListValueWrapperFns = { encode(message: ListValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.values) { Value.encode(Value.wrap(v!), writer.uint32(10).fork()).join(); @@ -545,3 +545,27 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create(base?: DeepPartial): T; + fromPartial(object: DeepPartial): T; +} + +export interface StructWrapperFns { + wrap(object: { [key: string]: any } | undefined): Struct; + unwrap(message: Struct): { [key: string]: any }; +} + +export interface AnyValueWrapperFns { + wrap(value: any): Value; + unwrap(message: any): string | number | boolean | Object | null | Array | undefined; +} + +export interface ListValueWrapperFns { + wrap(array: Array | undefined): ListValue; + unwrap(message: ListValue): Array; +} diff --git a/integration/nice-grpc/google/protobuf/timestamp.ts b/integration/nice-grpc/google/protobuf/timestamp.ts index d32063c0f..e757b0c91 100644 --- a/integration/nice-grpc/google/protobuf/timestamp.ts +++ b/integration/nice-grpc/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -209,3 +209,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create(base?: DeepPartial): T; + fromPartial(object: DeepPartial): T; +} diff --git a/integration/nice-grpc/google/protobuf/wrappers.ts b/integration/nice-grpc/google/protobuf/wrappers.ts index cea0c67d4..2a98e4c7b 100644 --- a/integration/nice-grpc/google/protobuf/wrappers.ts +++ b/integration/nice-grpc/google/protobuf/wrappers.ts @@ -100,7 +100,7 @@ function createBaseDoubleValue(): DoubleValue { return { value: 0 }; } -export const DoubleValue = { +export const DoubleValue: MessageFns = { encode(message: DoubleValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(9).double(message.value); @@ -157,7 +157,7 @@ function createBaseFloatValue(): FloatValue { return { value: 0 }; } -export const FloatValue = { +export const FloatValue: MessageFns = { encode(message: FloatValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(13).float(message.value); @@ -214,7 +214,7 @@ function createBaseInt64Value(): Int64Value { return { value: 0 }; } -export const Int64Value = { +export const Int64Value: MessageFns = { encode(message: Int64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int64(message.value); @@ -271,7 +271,7 @@ function createBaseUInt64Value(): UInt64Value { return { value: 0 }; } -export const UInt64Value = { +export const UInt64Value: MessageFns = { encode(message: UInt64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint64(message.value); @@ -328,7 +328,7 @@ function createBaseInt32Value(): Int32Value { return { value: 0 }; } -export const Int32Value = { +export const Int32Value: MessageFns = { encode(message: Int32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int32(message.value); @@ -385,7 +385,7 @@ function createBaseUInt32Value(): UInt32Value { return { value: 0 }; } -export const UInt32Value = { +export const UInt32Value: MessageFns = { encode(message: UInt32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint32(message.value); @@ -442,7 +442,7 @@ function createBaseBoolValue(): BoolValue { return { value: false }; } -export const BoolValue = { +export const BoolValue: MessageFns = { encode(message: BoolValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== false) { writer.uint32(8).bool(message.value); @@ -499,7 +499,7 @@ function createBaseStringValue(): StringValue { return { value: "" }; } -export const StringValue = { +export const StringValue: MessageFns = { encode(message: StringValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "") { writer.uint32(10).string(message.value); @@ -556,7 +556,7 @@ function createBaseBytesValue(): BytesValue { return { value: new Uint8Array(0) }; } -export const BytesValue = { +export const BytesValue: MessageFns = { encode(message: BytesValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value.length !== 0) { writer.uint32(10).bytes(message.value); @@ -656,3 +656,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create(base?: DeepPartial): T; + fromPartial(object: DeepPartial): T; +} diff --git a/integration/nice-grpc/simple.ts b/integration/nice-grpc/simple.ts index 51f75b2e8..e8c8807d7 100644 --- a/integration/nice-grpc/simple.ts +++ b/integration/nice-grpc/simple.ts @@ -29,7 +29,7 @@ function createBaseTestMessage(): TestMessage { return { timestamp: undefined }; } -export const TestMessage = { +export const TestMessage: MessageFns = { encode(message: TestMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.timestamp !== undefined) { Timestamp.encode(toTimestamp(message.timestamp), writer.uint32(10).fork()).join(); @@ -409,3 +409,12 @@ function isSet(value: any): boolean { } export type ServerStreamingMethodResult = { [Symbol.asyncIterator](): AsyncIterator }; + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create(base?: DeepPartial): T; + fromPartial(object: DeepPartial): T; +} diff --git a/integration/no-comments/simple.ts b/integration/no-comments/simple.ts index 669b77b79..886eb0bec 100644 --- a/integration/no-comments/simple.ts +++ b/integration/no-comments/simple.ts @@ -22,7 +22,7 @@ function createBaseSimple(): Simple { return { name: "", age: 0, child: undefined, testField: "", testNotDeprecated: "" }; } -export const Simple = { +export const Simple: MessageFns = { encode(message: Simple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -141,7 +141,7 @@ function createBaseChild(): Child { return { name: "" }; } -export const Child = { +export const Child: MessageFns = { encode(message: Child, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -209,3 +209,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/no-defaults-for-optionals-with-nulls/proto-2.ts b/integration/no-defaults-for-optionals-with-nulls/proto-2.ts index aee4d1cc0..81baab4ab 100644 --- a/integration/no-defaults-for-optionals-with-nulls/proto-2.ts +++ b/integration/no-defaults-for-optionals-with-nulls/proto-2.ts @@ -22,7 +22,7 @@ function createBaseProto2TestMessage(): Proto2TestMessage { return { boolValue: null, intValue: null, stringValue: null, mapValue: {} }; } -export const Proto2TestMessage = { +export const Proto2TestMessage: MessageFns = { encode(message: Proto2TestMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.boolValue !== undefined && message.boolValue !== null) { writer.uint32(8).bool(message.boolValue); @@ -145,7 +145,7 @@ function createBaseProto2TestMessage_MapValueEntry(): Proto2TestMessage_MapValue return { key: null, value: null }; } -export const Proto2TestMessage_MapValueEntry = { +export const Proto2TestMessage_MapValueEntry: MessageFns = { encode(message: Proto2TestMessage_MapValueEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== undefined && message.key !== null) { writer.uint32(10).string(message.key); @@ -236,3 +236,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/no-defaults-for-optionals-with-nulls/proto-3.ts b/integration/no-defaults-for-optionals-with-nulls/proto-3.ts index 877985e79..195a901bf 100644 --- a/integration/no-defaults-for-optionals-with-nulls/proto-3.ts +++ b/integration/no-defaults-for-optionals-with-nulls/proto-3.ts @@ -33,7 +33,7 @@ function createBaseProto3TestMessage(): Proto3TestMessage { }; } -export const Proto3TestMessage = { +export const Proto3TestMessage: MessageFns = { encode(message: Proto3TestMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.boolValue !== undefined && message.boolValue !== null) { writer.uint32(8).bool(message.boolValue); @@ -201,7 +201,7 @@ function createBaseProto3TestMessage_MapValueEntry(): Proto3TestMessage_MapValue return { key: null, value: null }; } -export const Proto3TestMessage_MapValueEntry = { +export const Proto3TestMessage_MapValueEntry: MessageFns = { encode(message: Proto3TestMessage_MapValueEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== undefined && message.key !== null) { writer.uint32(10).string(message.key); @@ -292,3 +292,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/no-defaults-for-optionals/proto-2.ts b/integration/no-defaults-for-optionals/proto-2.ts index 0fb6b4baa..c2cad450a 100644 --- a/integration/no-defaults-for-optionals/proto-2.ts +++ b/integration/no-defaults-for-optionals/proto-2.ts @@ -22,7 +22,7 @@ function createBaseProto2TestMessage(): Proto2TestMessage { return { boolValue: undefined, intValue: undefined, stringValue: undefined, mapValue: {} }; } -export const Proto2TestMessage = { +export const Proto2TestMessage: MessageFns = { encode(message: Proto2TestMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.boolValue !== undefined) { writer.uint32(8).bool(message.boolValue); @@ -145,7 +145,7 @@ function createBaseProto2TestMessage_MapValueEntry(): Proto2TestMessage_MapValue return { key: undefined, value: undefined }; } -export const Proto2TestMessage_MapValueEntry = { +export const Proto2TestMessage_MapValueEntry: MessageFns = { encode(message: Proto2TestMessage_MapValueEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== undefined) { writer.uint32(10).string(message.key); @@ -236,3 +236,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/no-defaults-for-optionals/proto-3.ts b/integration/no-defaults-for-optionals/proto-3.ts index 232565d6d..0d58085de 100644 --- a/integration/no-defaults-for-optionals/proto-3.ts +++ b/integration/no-defaults-for-optionals/proto-3.ts @@ -33,7 +33,7 @@ function createBaseProto3TestMessage(): Proto3TestMessage { }; } -export const Proto3TestMessage = { +export const Proto3TestMessage: MessageFns = { encode(message: Proto3TestMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.boolValue !== undefined) { writer.uint32(8).bool(message.boolValue); @@ -203,7 +203,7 @@ function createBaseProto3TestMessage_MapValueEntry(): Proto3TestMessage_MapValue return { key: undefined, value: undefined }; } -export const Proto3TestMessage_MapValueEntry = { +export const Proto3TestMessage_MapValueEntry: MessageFns = { encode(message: Proto3TestMessage_MapValueEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== undefined) { writer.uint32(10).string(message.key); @@ -294,3 +294,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/no-proto-package/no-proto-package.ts b/integration/no-proto-package/no-proto-package.ts index 7c2e34259..23af2c48c 100644 --- a/integration/no-proto-package/no-proto-package.ts +++ b/integration/no-proto-package/no-proto-package.ts @@ -19,7 +19,7 @@ function createBaseUser(): User { return { name: "" }; } -export const User = { +export const User: MessageFns = { encode(message: User, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -76,7 +76,7 @@ function createBaseEmpty(): Empty { return {}; } -export const Empty = { +export const Empty: MessageFns = { encode(_: Empty, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -157,3 +157,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/omit-optionals/simple.ts b/integration/omit-optionals/simple.ts index 81930453f..43e4406d3 100644 --- a/integration/omit-optionals/simple.ts +++ b/integration/omit-optionals/simple.ts @@ -15,7 +15,7 @@ function createBaseTestMessage(): TestMessage { return { field1: false }; } -export const TestMessage = { +export const TestMessage: MessageFns = { encode(message: TestMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.field1 !== false) { writer.uint32(8).bool(message.field1); @@ -100,3 +100,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/oneof-properties/oneof.ts b/integration/oneof-properties/oneof.ts index 64ea05a0e..29ae73586 100644 --- a/integration/oneof-properties/oneof.ts +++ b/integration/oneof-properties/oneof.ts @@ -95,7 +95,7 @@ function createBasePleaseChoose(): PleaseChoose { }; } -export const PleaseChoose = { +export const PleaseChoose: MessageFns = { encode(message: PleaseChoose, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -306,7 +306,7 @@ function createBasePleaseChoose_Submessage(): PleaseChoose_Submessage { return { name: "" }; } -export const PleaseChoose_Submessage = { +export const PleaseChoose_Submessage: MessageFns = { encode(message: PleaseChoose_Submessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -399,3 +399,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/oneof-unions-snake/google/protobuf/struct.ts b/integration/oneof-unions-snake/google/protobuf/struct.ts index c9990ed8e..6b4f82446 100644 --- a/integration/oneof-unions-snake/google/protobuf/struct.ts +++ b/integration/oneof-unions-snake/google/protobuf/struct.ts @@ -93,7 +93,7 @@ function createBaseStruct(): Struct { return { fields: {} }; } -export const Struct = { +export const Struct: MessageFns & StructWrapperFns = { encode(message: Struct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.fields).forEach(([key, value]) => { if (value !== undefined) { @@ -197,7 +197,7 @@ function createBaseStruct_FieldsEntry(): Struct_FieldsEntry { return { key: "", value: undefined }; } -export const Struct_FieldsEntry = { +export const Struct_FieldsEntry: MessageFns = { encode(message: Struct_FieldsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -271,7 +271,7 @@ function createBaseValue(): Value { return { kind: undefined }; } -export const Value = { +export const Value: MessageFns & AnyValueWrapperFns = { encode(message: Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { switch (message.kind?.$case) { case "null_value": @@ -485,7 +485,7 @@ function createBaseListValue(): ListValue { return { values: [] }; } -export const ListValue = { +export const ListValue: MessageFns & ListValueWrapperFns = { encode(message: ListValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.values) { Value.encode(Value.wrap(v!), writer.uint32(10).fork()).join(); @@ -572,3 +572,27 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} + +export interface StructWrapperFns { + wrap(object: { [key: string]: any } | undefined): Struct; + unwrap(message: Struct): { [key: string]: any }; +} + +export interface AnyValueWrapperFns { + wrap(value: any): Value; + unwrap(message: any): string | number | boolean | Object | null | Array | undefined; +} + +export interface ListValueWrapperFns { + wrap(array: Array | undefined): ListValue; + unwrap(message: ListValue): Array; +} diff --git a/integration/oneof-unions-snake/simple.ts b/integration/oneof-unions-snake/simple.ts index cd70e728c..4d6dd39d3 100644 --- a/integration/oneof-unions-snake/simple.ts +++ b/integration/oneof-unions-snake/simple.ts @@ -20,7 +20,7 @@ function createBaseSimpleStruct(): SimpleStruct { return { simple_struct: undefined }; } -export const SimpleStruct = { +export const SimpleStruct: MessageFns = { encode(message: SimpleStruct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.simple_struct !== undefined) { Struct.encode(Struct.wrap(message.simple_struct), writer.uint32(10).fork()).join(); @@ -89,3 +89,12 @@ export type Exact = P extends Builtin ? P function isObject(value: any): boolean { return typeof value === "object" && value !== null; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/oneof-unions-value/google/protobuf/struct.ts b/integration/oneof-unions-value/google/protobuf/struct.ts index 2124ab4f9..5a9cfca66 100644 --- a/integration/oneof-unions-value/google/protobuf/struct.ts +++ b/integration/oneof-unions-value/google/protobuf/struct.ts @@ -93,7 +93,7 @@ function createBaseStruct(): Struct { return { fields: {} }; } -export const Struct = { +export const Struct: MessageFns & StructWrapperFns = { encode(message: Struct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.fields).forEach(([key, value]) => { if (value !== undefined) { @@ -197,7 +197,7 @@ function createBaseStruct_FieldsEntry(): Struct_FieldsEntry { return { key: "", value: undefined }; } -export const Struct_FieldsEntry = { +export const Struct_FieldsEntry: MessageFns = { encode(message: Struct_FieldsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -271,7 +271,7 @@ function createBaseValue(): Value { return { kind: undefined }; } -export const Value = { +export const Value: MessageFns & AnyValueWrapperFns = { encode(message: Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { switch (message.kind?.$case) { case "nullValue": @@ -450,7 +450,7 @@ function createBaseListValue(): ListValue { return { values: [] }; } -export const ListValue = { +export const ListValue: MessageFns & ListValueWrapperFns = { encode(message: ListValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.values) { Value.encode(Value.wrap(v!), writer.uint32(10).fork()).join(); @@ -537,3 +537,27 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} + +export interface StructWrapperFns { + wrap(object: { [key: string]: any } | undefined): Struct; + unwrap(message: Struct): { [key: string]: any }; +} + +export interface AnyValueWrapperFns { + wrap(value: any): Value; + unwrap(message: any): string | number | boolean | Object | null | Array | undefined; +} + +export interface ListValueWrapperFns { + wrap(array: Array | undefined): ListValue; + unwrap(message: ListValue): Array; +} diff --git a/integration/oneof-unions-value/oneof.ts b/integration/oneof-unions-value/oneof.ts index af5ce689d..987684e1c 100644 --- a/integration/oneof-unions-value/oneof.ts +++ b/integration/oneof-unions-value/oneof.ts @@ -79,7 +79,7 @@ function createBasePleaseChoose(): PleaseChoose { return { name: "", choice: undefined, age: 0, eitherOr: undefined, signature: new Uint8Array(0), value: undefined }; } -export const PleaseChoose = { +export const PleaseChoose: MessageFns = { encode(message: PleaseChoose, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -357,7 +357,7 @@ function createBasePleaseChoose_Submessage(): PleaseChoose_Submessage { return { name: "" }; } -export const PleaseChoose_Submessage = { +export const PleaseChoose_Submessage: MessageFns = { encode(message: PleaseChoose_Submessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -414,7 +414,7 @@ function createBaseSimpleButOptional(): SimpleButOptional { return { name: undefined, age: undefined }; } -export const SimpleButOptional = { +export const SimpleButOptional: MessageFns = { encode(message: SimpleButOptional, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined) { writer.uint32(10).string(message.name); @@ -525,3 +525,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/oneof-unions/google/protobuf/struct.ts b/integration/oneof-unions/google/protobuf/struct.ts index 6d355596b..21368bcd0 100644 --- a/integration/oneof-unions/google/protobuf/struct.ts +++ b/integration/oneof-unions/google/protobuf/struct.ts @@ -93,7 +93,7 @@ function createBaseStruct(): Struct { return { fields: {} }; } -export const Struct = { +export const Struct: MessageFns & StructWrapperFns = { encode(message: Struct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.fields).forEach(([key, value]) => { if (value !== undefined) { @@ -197,7 +197,7 @@ function createBaseStruct_FieldsEntry(): Struct_FieldsEntry { return { key: "", value: undefined }; } -export const Struct_FieldsEntry = { +export const Struct_FieldsEntry: MessageFns = { encode(message: Struct_FieldsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -271,7 +271,7 @@ function createBaseValue(): Value { return { kind: undefined }; } -export const Value = { +export const Value: MessageFns & AnyValueWrapperFns = { encode(message: Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { switch (message.kind?.$case) { case "nullValue": @@ -476,7 +476,7 @@ function createBaseListValue(): ListValue { return { values: [] }; } -export const ListValue = { +export const ListValue: MessageFns & ListValueWrapperFns = { encode(message: ListValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.values) { Value.encode(Value.wrap(v!), writer.uint32(10).fork()).join(); @@ -563,3 +563,27 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} + +export interface StructWrapperFns { + wrap(object: { [key: string]: any } | undefined): Struct; + unwrap(message: Struct): { [key: string]: any }; +} + +export interface AnyValueWrapperFns { + wrap(value: any): Value; + unwrap(message: any): string | number | boolean | Object | null | Array | undefined; +} + +export interface ListValueWrapperFns { + wrap(array: Array | undefined): ListValue; + unwrap(message: ListValue): Array; +} diff --git a/integration/oneof-unions/oneof.ts b/integration/oneof-unions/oneof.ts index 27b1f9843..5b10eb04c 100644 --- a/integration/oneof-unions/oneof.ts +++ b/integration/oneof-unions/oneof.ts @@ -79,7 +79,7 @@ function createBasePleaseChoose(): PleaseChoose { return { name: "", choice: undefined, age: 0, eitherOr: undefined, signature: new Uint8Array(0), value: undefined }; } -export const PleaseChoose = { +export const PleaseChoose: MessageFns = { encode(message: PleaseChoose, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -363,7 +363,7 @@ function createBasePleaseChoose_Submessage(): PleaseChoose_Submessage { return { name: "" }; } -export const PleaseChoose_Submessage = { +export const PleaseChoose_Submessage: MessageFns = { encode(message: PleaseChoose_Submessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -420,7 +420,7 @@ function createBaseSimpleButOptional(): SimpleButOptional { return { name: undefined, age: undefined }; } -export const SimpleButOptional = { +export const SimpleButOptional: MessageFns = { encode(message: SimpleButOptional, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined) { writer.uint32(10).string(message.name); @@ -531,3 +531,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/optional-long/google/protobuf/timestamp.ts b/integration/optional-long/google/protobuf/timestamp.ts index 0cf701cc3..82f167dda 100644 --- a/integration/optional-long/google/protobuf/timestamp.ts +++ b/integration/optional-long/google/protobuf/timestamp.ts @@ -120,7 +120,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: Long.ZERO, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== undefined && !message.seconds.equals(Long.ZERO)) { writer.uint32(8).int64(message.seconds.toString()); @@ -207,3 +207,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/optional-long/test.ts b/integration/optional-long/test.ts index 3d0123b41..ceef1be53 100644 --- a/integration/optional-long/test.ts +++ b/integration/optional-long/test.ts @@ -16,7 +16,7 @@ function createBaseExample(): Example { return { datetime: undefined }; } -export const Example = { +export const Example: MessageFns = { encode(message: Example, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.datetime !== undefined) { Timestamp.encode(toTimestamp(message.datetime), writer.uint32(10).fork()).join(); @@ -110,3 +110,12 @@ function numberToLong(number: number) { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/optional-type-definitions/simple.ts b/integration/optional-type-definitions/simple.ts index 71d4a80b1..6357e60e2 100644 --- a/integration/optional-type-definitions/simple.ts +++ b/integration/optional-type-definitions/simple.ts @@ -48,7 +48,7 @@ function createBaseSimple(): Simple { return { $type: "simple.Simple", name: "", age: 0, child: undefined, testField: "", testNotDeprecated: "" }; } -export const Simple = { +export const Simple: MessageFns = { $type: "simple.Simple" as const, encode(message: Simple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -170,7 +170,7 @@ function createBaseChild(): Child { return { $type: "simple.Child", name: "" }; } -export const Child = { +export const Child: MessageFns = { $type: "simple.Child" as const, encode(message: Child, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -240,3 +240,13 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + readonly $type: V; + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/options/google/protobuf/descriptor.ts b/integration/options/google/protobuf/descriptor.ts index 2de6c8bf7..682008739 100644 --- a/integration/options/google/protobuf/descriptor.ts +++ b/integration/options/google/protobuf/descriptor.ts @@ -959,7 +959,7 @@ function createBaseFileDescriptorSet(): FileDescriptorSet { return { file: [] }; } -export const FileDescriptorSet = { +export const FileDescriptorSet: MessageFns = { encode(message: FileDescriptorSet, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.file) { FileDescriptorProto.encode(v!, writer.uint32(10).fork()).join(); @@ -1008,7 +1008,7 @@ function createBaseFileDescriptorProto(): FileDescriptorProto { }; } -export const FileDescriptorProto = { +export const FileDescriptorProto: MessageFns = { encode(message: FileDescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -1189,7 +1189,7 @@ function createBaseDescriptorProto(): DescriptorProto { }; } -export const DescriptorProto = { +export const DescriptorProto: MessageFns = { encode(message: DescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -1315,7 +1315,7 @@ function createBaseDescriptorProto_ExtensionRange(): DescriptorProto_ExtensionRa return { start: 0, end: 0, options: undefined }; } -export const DescriptorProto_ExtensionRange = { +export const DescriptorProto_ExtensionRange: MessageFns = { encode(message: DescriptorProto_ExtensionRange, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.start !== undefined && message.start !== 0) { writer.uint32(8).int32(message.start); @@ -1371,7 +1371,7 @@ function createBaseDescriptorProto_ReservedRange(): DescriptorProto_ReservedRang return { start: 0, end: 0 }; } -export const DescriptorProto_ReservedRange = { +export const DescriptorProto_ReservedRange: MessageFns = { encode(message: DescriptorProto_ReservedRange, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.start !== undefined && message.start !== 0) { writer.uint32(8).int32(message.start); @@ -1417,7 +1417,7 @@ function createBaseExtensionRangeOptions(): ExtensionRangeOptions { return { uninterpretedOption: [] }; } -export const ExtensionRangeOptions = { +export const ExtensionRangeOptions: MessageFns = { encode(message: ExtensionRangeOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.uninterpretedOption) { UninterpretedOption.encode(v!, writer.uint32(7994).fork()).join(); @@ -1465,7 +1465,7 @@ function createBaseFieldDescriptorProto(): FieldDescriptorProto { }; } -export const FieldDescriptorProto = { +export const FieldDescriptorProto: MessageFns = { encode(message: FieldDescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -1601,7 +1601,7 @@ function createBaseOneofDescriptorProto(): OneofDescriptorProto { return { name: "", options: undefined }; } -export const OneofDescriptorProto = { +export const OneofDescriptorProto: MessageFns = { encode(message: OneofDescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -1647,7 +1647,7 @@ function createBaseEnumDescriptorProto(): EnumDescriptorProto { return { name: "", value: [], options: undefined, reservedRange: [], reservedName: [] }; } -export const EnumDescriptorProto = { +export const EnumDescriptorProto: MessageFns = { encode(message: EnumDescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -1723,7 +1723,7 @@ function createBaseEnumDescriptorProto_EnumReservedRange(): EnumDescriptorProto_ return { start: 0, end: 0 }; } -export const EnumDescriptorProto_EnumReservedRange = { +export const EnumDescriptorProto_EnumReservedRange: MessageFns = { encode(message: EnumDescriptorProto_EnumReservedRange, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.start !== undefined && message.start !== 0) { writer.uint32(8).int32(message.start); @@ -1769,7 +1769,7 @@ function createBaseEnumValueDescriptorProto(): EnumValueDescriptorProto { return { name: "", number: 0, options: undefined }; } -export const EnumValueDescriptorProto = { +export const EnumValueDescriptorProto: MessageFns = { encode(message: EnumValueDescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -1825,7 +1825,7 @@ function createBaseServiceDescriptorProto(): ServiceDescriptorProto { return { name: "", method: [], options: undefined }; } -export const ServiceDescriptorProto = { +export const ServiceDescriptorProto: MessageFns = { encode(message: ServiceDescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -1888,7 +1888,7 @@ function createBaseMethodDescriptorProto(): MethodDescriptorProto { }; } -export const MethodDescriptorProto = { +export const MethodDescriptorProto: MessageFns = { encode(message: MethodDescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -1996,7 +1996,7 @@ function createBaseFileOptions(): FileOptions { }; } -export const FileOptions = { +export const FileOptions: MessageFns = { encode(message: FileOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.javaPackage !== undefined && message.javaPackage !== "") { writer.uint32(10).string(message.javaPackage); @@ -2238,7 +2238,7 @@ function createBaseMessageOptions(): MessageOptions { }; } -export const MessageOptions = { +export const MessageOptions: MessageFns = { encode(message: MessageOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.messageSetWireFormat !== undefined && message.messageSetWireFormat !== false) { writer.uint32(8).bool(message.messageSetWireFormat); @@ -2314,7 +2314,7 @@ function createBaseFieldOptions(): FieldOptions { return { ctype: 0, packed: false, jstype: 0, lazy: false, deprecated: false, weak: false, uninterpretedOption: [] }; } -export const FieldOptions = { +export const FieldOptions: MessageFns = { encode(message: FieldOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.ctype !== undefined && message.ctype !== 0) { writer.uint32(8).int32(message.ctype); @@ -2410,7 +2410,7 @@ function createBaseOneofOptions(): OneofOptions { return { uninterpretedOption: [] }; } -export const OneofOptions = { +export const OneofOptions: MessageFns = { encode(message: OneofOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.uninterpretedOption) { UninterpretedOption.encode(v!, writer.uint32(7994).fork()).join(); @@ -2446,7 +2446,7 @@ function createBaseEnumOptions(): EnumOptions { return { allowAlias: false, deprecated: false, uninterpretedOption: [] }; } -export const EnumOptions = { +export const EnumOptions: MessageFns = { encode(message: EnumOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.allowAlias !== undefined && message.allowAlias !== false) { writer.uint32(16).bool(message.allowAlias); @@ -2502,7 +2502,7 @@ function createBaseEnumValueOptions(): EnumValueOptions { return { deprecated: false, uninterpretedOption: [] }; } -export const EnumValueOptions = { +export const EnumValueOptions: MessageFns = { encode(message: EnumValueOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.deprecated !== undefined && message.deprecated !== false) { writer.uint32(8).bool(message.deprecated); @@ -2548,7 +2548,7 @@ function createBaseServiceOptions(): ServiceOptions { return { deprecated: false, uninterpretedOption: [] }; } -export const ServiceOptions = { +export const ServiceOptions: MessageFns = { encode(message: ServiceOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.deprecated !== undefined && message.deprecated !== false) { writer.uint32(264).bool(message.deprecated); @@ -2594,7 +2594,7 @@ function createBaseMethodOptions(): MethodOptions { return { deprecated: false, idempotencyLevel: 0, uninterpretedOption: [] }; } -export const MethodOptions = { +export const MethodOptions: MessageFns = { encode(message: MethodOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.deprecated !== undefined && message.deprecated !== false) { writer.uint32(264).bool(message.deprecated); @@ -2658,7 +2658,7 @@ function createBaseUninterpretedOption(): UninterpretedOption { }; } -export const UninterpretedOption = { +export const UninterpretedOption: MessageFns = { encode(message: UninterpretedOption, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.name) { UninterpretedOption_NamePart.encode(v!, writer.uint32(18).fork()).join(); @@ -2754,7 +2754,7 @@ function createBaseUninterpretedOption_NamePart(): UninterpretedOption_NamePart return { namePart: "", isExtension: false }; } -export const UninterpretedOption_NamePart = { +export const UninterpretedOption_NamePart: MessageFns = { encode(message: UninterpretedOption_NamePart, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.namePart !== "") { writer.uint32(10).string(message.namePart); @@ -2800,7 +2800,7 @@ function createBaseSourceCodeInfo(): SourceCodeInfo { return { location: [] }; } -export const SourceCodeInfo = { +export const SourceCodeInfo: MessageFns = { encode(message: SourceCodeInfo, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.location) { SourceCodeInfo_Location.encode(v!, writer.uint32(10).fork()).join(); @@ -2836,7 +2836,7 @@ function createBaseSourceCodeInfo_Location(): SourceCodeInfo_Location { return { path: [], span: [], leadingComments: "", trailingComments: "", leadingDetachedComments: [] }; } -export const SourceCodeInfo_Location = { +export const SourceCodeInfo_Location: MessageFns = { encode(message: SourceCodeInfo_Location, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { writer.uint32(10).fork(); for (const v of message.path) { @@ -2936,7 +2936,7 @@ function createBaseGeneratedCodeInfo(): GeneratedCodeInfo { return { annotation: [] }; } -export const GeneratedCodeInfo = { +export const GeneratedCodeInfo: MessageFns = { encode(message: GeneratedCodeInfo, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.annotation) { GeneratedCodeInfo_Annotation.encode(v!, writer.uint32(10).fork()).join(); @@ -2972,7 +2972,7 @@ function createBaseGeneratedCodeInfo_Annotation(): GeneratedCodeInfo_Annotation return { path: [], sourceFile: "", begin: 0, end: 0 }; } -export const GeneratedCodeInfo_Annotation = { +export const GeneratedCodeInfo_Annotation: MessageFns = { encode(message: GeneratedCodeInfo_Annotation, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { writer.uint32(10).fork(); for (const v of message.path) { @@ -5886,3 +5886,8 @@ function longToNumber(int64: { toString(): string }): number { } return num; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; +} diff --git a/integration/options/options.ts b/integration/options/options.ts index a0ff39fdf..5be7728f4 100644 --- a/integration/options/options.ts +++ b/integration/options/options.ts @@ -32,7 +32,7 @@ function createBaseMyMessage(): MyMessage { return { foo: undefined, foo2: undefined, bar: undefined, quux: undefined }; } -export const MyMessage = { +export const MyMessage: MessageFns = { encode(message: MyMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.foo !== undefined) { writer.uint32(8).int32(message.foo); @@ -98,7 +98,7 @@ function createBaseRequestType(): RequestType { return {}; } -export const RequestType = { +export const RequestType: MessageFns = { encode(_: RequestType, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -124,7 +124,7 @@ function createBaseResponseType(): ResponseType { return {}; } -export const ResponseType = { +export const ResponseType: MessageFns = { encode(_: ResponseType, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -486,3 +486,8 @@ export const protoMetadata: ProtoMetadata = { enums: { "MyEnum": { options: { "my_enum_option": true }, values: { "FOO": { "my_enum_value_option": 321 } } } }, }, }; + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; +} diff --git a/integration/options/something/something.ts b/integration/options/something/something.ts index 72836b46f..29caa3ff5 100644 --- a/integration/options/something/something.ts +++ b/integration/options/something/something.ts @@ -17,7 +17,7 @@ function createBaseSomething(): Something { return { hello: "", foo: [] }; } -export const Something = { +export const Something: MessageFns = { encode(message: Something, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.hello !== "") { writer.uint32(10).string(message.hello); @@ -157,3 +157,8 @@ export const protoMetadata: ProtoMetadata = { references: { ".something.Something": Something }, dependencies: [protoMetadata1], }; + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; +} diff --git a/integration/output-decode-only/encode.ts b/integration/output-decode-only/encode.ts index 558be1743..dbee4b13d 100644 --- a/integration/output-decode-only/encode.ts +++ b/integration/output-decode-only/encode.ts @@ -14,7 +14,7 @@ function createBaseEncode(): Encode { return { encode: "" }; } -export const Encode = { +export const Encode: MessageFns = { decode(input: BinaryReader | Uint8Array, length?: number): Encode { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; @@ -38,3 +38,7 @@ export const Encode = { return message; }, }; + +export interface MessageFns { + decode(input: BinaryReader | Uint8Array, length?: number): T; +} diff --git a/integration/output-decode-only/google/protobuf/wrappers.ts b/integration/output-decode-only/google/protobuf/wrappers.ts index 866c31029..a2079eb19 100644 --- a/integration/output-decode-only/google/protobuf/wrappers.ts +++ b/integration/output-decode-only/google/protobuf/wrappers.ts @@ -100,7 +100,7 @@ function createBaseDoubleValue(): DoubleValue { return { value: 0 }; } -export const DoubleValue = { +export const DoubleValue: MessageFns = { decode(input: BinaryReader | Uint8Array, length?: number): DoubleValue { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; @@ -129,7 +129,7 @@ function createBaseFloatValue(): FloatValue { return { value: 0 }; } -export const FloatValue = { +export const FloatValue: MessageFns = { decode(input: BinaryReader | Uint8Array, length?: number): FloatValue { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; @@ -158,7 +158,7 @@ function createBaseInt64Value(): Int64Value { return { value: 0 }; } -export const Int64Value = { +export const Int64Value: MessageFns = { decode(input: BinaryReader | Uint8Array, length?: number): Int64Value { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; @@ -187,7 +187,7 @@ function createBaseUInt64Value(): UInt64Value { return { value: 0 }; } -export const UInt64Value = { +export const UInt64Value: MessageFns = { decode(input: BinaryReader | Uint8Array, length?: number): UInt64Value { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; @@ -216,7 +216,7 @@ function createBaseInt32Value(): Int32Value { return { value: 0 }; } -export const Int32Value = { +export const Int32Value: MessageFns = { decode(input: BinaryReader | Uint8Array, length?: number): Int32Value { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; @@ -245,7 +245,7 @@ function createBaseUInt32Value(): UInt32Value { return { value: 0 }; } -export const UInt32Value = { +export const UInt32Value: MessageFns = { decode(input: BinaryReader | Uint8Array, length?: number): UInt32Value { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; @@ -274,7 +274,7 @@ function createBaseBoolValue(): BoolValue { return { value: false }; } -export const BoolValue = { +export const BoolValue: MessageFns = { decode(input: BinaryReader | Uint8Array, length?: number): BoolValue { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; @@ -303,7 +303,7 @@ function createBaseStringValue(): StringValue { return { value: "" }; } -export const StringValue = { +export const StringValue: MessageFns = { decode(input: BinaryReader | Uint8Array, length?: number): StringValue { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; @@ -332,7 +332,7 @@ function createBaseBytesValue(): BytesValue { return { value: new Uint8Array(0) }; } -export const BytesValue = { +export const BytesValue: MessageFns = { decode(input: BinaryReader | Uint8Array, length?: number): BytesValue { const reader = input instanceof BinaryReader ? input : new BinaryReader(input); let end = length === undefined ? reader.len : reader.pos + length; @@ -367,3 +367,7 @@ function longToNumber(int64: { toString(): string }): number { } return num; } + +export interface MessageFns { + decode(input: BinaryReader | Uint8Array, length?: number): T; +} diff --git a/integration/output-encode-no-creation-methods/encode.ts b/integration/output-encode-no-creation-methods/encode.ts index 4765821d7..c5127560f 100644 --- a/integration/output-encode-no-creation-methods/encode.ts +++ b/integration/output-encode-no-creation-methods/encode.ts @@ -10,7 +10,7 @@ export interface Encode { encode: string; } -export const Encode = { +export const Encode: MessageFns = { encode(message: Encode, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.encode !== "") { writer.uint32(10).string(message.encode); @@ -18,3 +18,7 @@ export const Encode = { return writer; }, }; + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; +} diff --git a/integration/output-encode-no-creation-methods/google/protobuf/wrappers.ts b/integration/output-encode-no-creation-methods/google/protobuf/wrappers.ts index 89d450660..033edf610 100644 --- a/integration/output-encode-no-creation-methods/google/protobuf/wrappers.ts +++ b/integration/output-encode-no-creation-methods/google/protobuf/wrappers.ts @@ -96,7 +96,7 @@ export interface BytesValue { value: Uint8Array; } -export const DoubleValue = { +export const DoubleValue: MessageFns = { encode(message: DoubleValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(9).double(message.value); @@ -105,7 +105,7 @@ export const DoubleValue = { }, }; -export const FloatValue = { +export const FloatValue: MessageFns = { encode(message: FloatValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(13).float(message.value); @@ -114,7 +114,7 @@ export const FloatValue = { }, }; -export const Int64Value = { +export const Int64Value: MessageFns = { encode(message: Int64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int64(message.value); @@ -123,7 +123,7 @@ export const Int64Value = { }, }; -export const UInt64Value = { +export const UInt64Value: MessageFns = { encode(message: UInt64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint64(message.value); @@ -132,7 +132,7 @@ export const UInt64Value = { }, }; -export const Int32Value = { +export const Int32Value: MessageFns = { encode(message: Int32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int32(message.value); @@ -141,7 +141,7 @@ export const Int32Value = { }, }; -export const UInt32Value = { +export const UInt32Value: MessageFns = { encode(message: UInt32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint32(message.value); @@ -150,7 +150,7 @@ export const UInt32Value = { }, }; -export const BoolValue = { +export const BoolValue: MessageFns = { encode(message: BoolValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== false) { writer.uint32(8).bool(message.value); @@ -159,7 +159,7 @@ export const BoolValue = { }, }; -export const StringValue = { +export const StringValue: MessageFns = { encode(message: StringValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "") { writer.uint32(10).string(message.value); @@ -168,7 +168,7 @@ export const StringValue = { }, }; -export const BytesValue = { +export const BytesValue: MessageFns = { encode(message: BytesValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value.length !== 0) { writer.uint32(10).bytes(message.value); @@ -176,3 +176,7 @@ export const BytesValue = { return writer; }, }; + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; +} diff --git a/integration/output-encode-only/encode.ts b/integration/output-encode-only/encode.ts index 6f0691e12..76c271b10 100644 --- a/integration/output-encode-only/encode.ts +++ b/integration/output-encode-only/encode.ts @@ -14,7 +14,7 @@ function createBaseEncode(): Encode { return { encode: "" }; } -export const Encode = { +export const Encode: MessageFns = { encode(message: Encode, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.encode !== "") { writer.uint32(10).string(message.encode); @@ -22,3 +22,7 @@ export const Encode = { return writer; }, }; + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; +} diff --git a/integration/output-encode-only/google/protobuf/wrappers.ts b/integration/output-encode-only/google/protobuf/wrappers.ts index 243f150cd..06356c050 100644 --- a/integration/output-encode-only/google/protobuf/wrappers.ts +++ b/integration/output-encode-only/google/protobuf/wrappers.ts @@ -100,7 +100,7 @@ function createBaseDoubleValue(): DoubleValue { return { value: 0 }; } -export const DoubleValue = { +export const DoubleValue: MessageFns = { encode(message: DoubleValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(9).double(message.value); @@ -113,7 +113,7 @@ function createBaseFloatValue(): FloatValue { return { value: 0 }; } -export const FloatValue = { +export const FloatValue: MessageFns = { encode(message: FloatValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(13).float(message.value); @@ -126,7 +126,7 @@ function createBaseInt64Value(): Int64Value { return { value: 0 }; } -export const Int64Value = { +export const Int64Value: MessageFns = { encode(message: Int64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int64(message.value); @@ -139,7 +139,7 @@ function createBaseUInt64Value(): UInt64Value { return { value: 0 }; } -export const UInt64Value = { +export const UInt64Value: MessageFns = { encode(message: UInt64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint64(message.value); @@ -152,7 +152,7 @@ function createBaseInt32Value(): Int32Value { return { value: 0 }; } -export const Int32Value = { +export const Int32Value: MessageFns = { encode(message: Int32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int32(message.value); @@ -165,7 +165,7 @@ function createBaseUInt32Value(): UInt32Value { return { value: 0 }; } -export const UInt32Value = { +export const UInt32Value: MessageFns = { encode(message: UInt32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint32(message.value); @@ -178,7 +178,7 @@ function createBaseBoolValue(): BoolValue { return { value: false }; } -export const BoolValue = { +export const BoolValue: MessageFns = { encode(message: BoolValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== false) { writer.uint32(8).bool(message.value); @@ -191,7 +191,7 @@ function createBaseStringValue(): StringValue { return { value: "" }; } -export const StringValue = { +export const StringValue: MessageFns = { encode(message: StringValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "") { writer.uint32(10).string(message.value); @@ -204,7 +204,7 @@ function createBaseBytesValue(): BytesValue { return { value: new Uint8Array(0) }; } -export const BytesValue = { +export const BytesValue: MessageFns = { encode(message: BytesValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value.length !== 0) { writer.uint32(10).bytes(message.value); @@ -212,3 +212,7 @@ export const BytesValue = { return writer; }, }; + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; +} diff --git a/integration/output-fromJSON-only/decode.ts b/integration/output-fromJSON-only/decode.ts index cd2b88023..a306bea2f 100644 --- a/integration/output-fromJSON-only/decode.ts +++ b/integration/output-fromJSON-only/decode.ts @@ -9,7 +9,7 @@ export interface Encode { encode: string; } -export const Encode = { +export const Encode: MessageFns = { fromJSON(object: any): Encode { return { encode: isSet(object.encode) ? globalThis.String(object.encode) : "" }; }, @@ -18,3 +18,7 @@ export const Encode = { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + fromJSON(object: any): T; +} diff --git a/integration/output-fromJSON-only/google/protobuf/wrappers.ts b/integration/output-fromJSON-only/google/protobuf/wrappers.ts index d79ede9b6..0da99a802 100644 --- a/integration/output-fromJSON-only/google/protobuf/wrappers.ts +++ b/integration/output-fromJSON-only/google/protobuf/wrappers.ts @@ -95,55 +95,55 @@ export interface BytesValue { value: Uint8Array; } -export const DoubleValue = { +export const DoubleValue: MessageFns = { fromJSON(object: any): DoubleValue { return { value: isSet(object.value) ? globalThis.Number(object.value) : 0 }; }, }; -export const FloatValue = { +export const FloatValue: MessageFns = { fromJSON(object: any): FloatValue { return { value: isSet(object.value) ? globalThis.Number(object.value) : 0 }; }, }; -export const Int64Value = { +export const Int64Value: MessageFns = { fromJSON(object: any): Int64Value { return { value: isSet(object.value) ? globalThis.Number(object.value) : 0 }; }, }; -export const UInt64Value = { +export const UInt64Value: MessageFns = { fromJSON(object: any): UInt64Value { return { value: isSet(object.value) ? globalThis.Number(object.value) : 0 }; }, }; -export const Int32Value = { +export const Int32Value: MessageFns = { fromJSON(object: any): Int32Value { return { value: isSet(object.value) ? globalThis.Number(object.value) : 0 }; }, }; -export const UInt32Value = { +export const UInt32Value: MessageFns = { fromJSON(object: any): UInt32Value { return { value: isSet(object.value) ? globalThis.Number(object.value) : 0 }; }, }; -export const BoolValue = { +export const BoolValue: MessageFns = { fromJSON(object: any): BoolValue { return { value: isSet(object.value) ? globalThis.Boolean(object.value) : false }; }, }; -export const StringValue = { +export const StringValue: MessageFns = { fromJSON(object: any): StringValue { return { value: isSet(object.value) ? globalThis.String(object.value) : "" }; }, }; -export const BytesValue = { +export const BytesValue: MessageFns = { fromJSON(object: any): BytesValue { return { value: isSet(object.value) ? bytesFromBase64(object.value) : new Uint8Array(0) }; }, @@ -165,3 +165,7 @@ function bytesFromBase64(b64: string): Uint8Array { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + fromJSON(object: any): T; +} diff --git a/integration/output-index/a.ts b/integration/output-index/a.ts index d8b9b6f48..133c1124b 100644 --- a/integration/output-index/a.ts +++ b/integration/output-index/a.ts @@ -12,7 +12,7 @@ function createBaseA(): A { return { a: "" }; } -export const A = { +export const A: MessageFns = { encode(message: A, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.a !== "") { writer.uint32(10).string(message.a); @@ -80,3 +80,12 @@ type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/output-toJSON-only/encode.ts b/integration/output-toJSON-only/encode.ts index e2c5342f6..71f81cdc4 100644 --- a/integration/output-toJSON-only/encode.ts +++ b/integration/output-toJSON-only/encode.ts @@ -9,7 +9,7 @@ export interface Encode { encode: string; } -export const Encode = { +export const Encode: MessageFns = { toJSON(message: Encode): unknown { const obj: any = {}; if (message.encode !== "") { @@ -18,3 +18,7 @@ export const Encode = { return obj; }, }; + +export interface MessageFns { + toJSON(message: T): unknown; +} diff --git a/integration/output-toJSON-only/google/protobuf/wrappers.ts b/integration/output-toJSON-only/google/protobuf/wrappers.ts index dc314bc8b..c75f31ecf 100644 --- a/integration/output-toJSON-only/google/protobuf/wrappers.ts +++ b/integration/output-toJSON-only/google/protobuf/wrappers.ts @@ -95,7 +95,7 @@ export interface BytesValue { value: Uint8Array; } -export const DoubleValue = { +export const DoubleValue: MessageFns = { toJSON(message: DoubleValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -105,7 +105,7 @@ export const DoubleValue = { }, }; -export const FloatValue = { +export const FloatValue: MessageFns = { toJSON(message: FloatValue): unknown { const obj: any = {}; if (message.value !== 0) { @@ -115,7 +115,7 @@ export const FloatValue = { }, }; -export const Int64Value = { +export const Int64Value: MessageFns = { toJSON(message: Int64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -125,7 +125,7 @@ export const Int64Value = { }, }; -export const UInt64Value = { +export const UInt64Value: MessageFns = { toJSON(message: UInt64Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -135,7 +135,7 @@ export const UInt64Value = { }, }; -export const Int32Value = { +export const Int32Value: MessageFns = { toJSON(message: Int32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -145,7 +145,7 @@ export const Int32Value = { }, }; -export const UInt32Value = { +export const UInt32Value: MessageFns = { toJSON(message: UInt32Value): unknown { const obj: any = {}; if (message.value !== 0) { @@ -155,7 +155,7 @@ export const UInt32Value = { }, }; -export const BoolValue = { +export const BoolValue: MessageFns = { toJSON(message: BoolValue): unknown { const obj: any = {}; if (message.value !== false) { @@ -165,7 +165,7 @@ export const BoolValue = { }, }; -export const StringValue = { +export const StringValue: MessageFns = { toJSON(message: StringValue): unknown { const obj: any = {}; if (message.value !== "") { @@ -175,7 +175,7 @@ export const StringValue = { }, }; -export const BytesValue = { +export const BytesValue: MessageFns = { toJSON(message: BytesValue): unknown { const obj: any = {}; if (message.value.length !== 0) { @@ -196,3 +196,7 @@ function base64FromBytes(arr: Uint8Array): string { return globalThis.btoa(bin.join("")); } } + +export interface MessageFns { + toJSON(message: T): unknown; +} diff --git a/integration/point/point.ts b/integration/point/point.ts index d9559a554..3218f414c 100644 --- a/integration/point/point.ts +++ b/integration/point/point.ts @@ -20,7 +20,7 @@ function createBasePoint(): Point { return { lat: 0, lng: 0 }; } -export const Point = { +export const Point: MessageFns = { encode(message: Point, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.lat !== 0) { writer.uint32(9).double(message.lat); @@ -94,7 +94,7 @@ function createBaseArea(): Area { return { nw: undefined, se: undefined }; } -export const Area = { +export const Area: MessageFns = { encode(message: Area, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.nw !== undefined) { Point.encode(message.nw, writer.uint32(10).fork()).join(); @@ -179,3 +179,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/proto2-long/simple.ts b/integration/proto2-long/simple.ts index 13cfa1cbe..ef49ea95f 100644 --- a/integration/proto2-long/simple.ts +++ b/integration/proto2-long/simple.ts @@ -140,7 +140,7 @@ function createBaseOptionalsTest(): OptionalsTest { }; } -export const OptionalsTest = { +export const OptionalsTest: MessageFns = { encode(message: OptionalsTest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { writer.uint32(10).fork(); for (const v of message.repId) { @@ -871,7 +871,7 @@ function createBaseOptionalsTest_TranslationsEntry(): OptionalsTest_Translations return { key: "", value: "" }; } -export const OptionalsTest_TranslationsEntry = { +export const OptionalsTest_TranslationsEntry: MessageFns = { encode(message: OptionalsTest_TranslationsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -947,7 +947,7 @@ function createBaseChild(): Child { return {}; } -export const Child = { +export const Child: MessageFns = { encode(_: Child, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -1030,3 +1030,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/proto2-no-default-vals/simple.ts b/integration/proto2-no-default-vals/simple.ts index e129151f4..38dfb4d80 100644 --- a/integration/proto2-no-default-vals/simple.ts +++ b/integration/proto2-no-default-vals/simple.ts @@ -139,7 +139,7 @@ function createBaseOptionalsTest(): OptionalsTest { }; } -export const OptionalsTest = { +export const OptionalsTest: MessageFns = { encode(message: OptionalsTest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { writer.uint32(10).fork(); for (const v of message.repId) { @@ -858,7 +858,7 @@ function createBaseOptionalsTest_TranslationsEntry(): OptionalsTest_Translations return { key: "", value: "" }; } -export const OptionalsTest_TranslationsEntry = { +export const OptionalsTest_TranslationsEntry: MessageFns = { encode(message: OptionalsTest_TranslationsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -934,7 +934,7 @@ function createBaseChild(): Child { return {}; } -export const Child = { +export const Child: MessageFns = { encode(_: Child, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -1028,3 +1028,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/proto2-no-optionals/simple.ts b/integration/proto2-no-optionals/simple.ts index 5b3b7bfa4..7c566da9c 100644 --- a/integration/proto2-no-optionals/simple.ts +++ b/integration/proto2-no-optionals/simple.ts @@ -139,7 +139,7 @@ function createBaseOptionalsTest(): OptionalsTest { }; } -export const OptionalsTest = { +export const OptionalsTest: MessageFns = { encode(message: OptionalsTest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { writer.uint32(10).fork(); for (const v of message.repId) { @@ -862,7 +862,7 @@ function createBaseOptionalsTest_TranslationsEntry(): OptionalsTest_Translations return { key: "", value: "" }; } -export const OptionalsTest_TranslationsEntry = { +export const OptionalsTest_TranslationsEntry: MessageFns = { encode(message: OptionalsTest_TranslationsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -938,7 +938,7 @@ function createBaseChild(): Child { return {}; } -export const Child = { +export const Child: MessageFns = { encode(_: Child, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -1032,3 +1032,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/proto2/simple.ts b/integration/proto2/simple.ts index 91275db93..00708203b 100644 --- a/integration/proto2/simple.ts +++ b/integration/proto2/simple.ts @@ -139,7 +139,7 @@ function createBaseOptionalsTest(): OptionalsTest { }; } -export const OptionalsTest = { +export const OptionalsTest: MessageFns = { encode(message: OptionalsTest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { writer.uint32(10).fork(); for (const v of message.repId) { @@ -862,7 +862,7 @@ function createBaseOptionalsTest_TranslationsEntry(): OptionalsTest_Translations return { key: "", value: "" }; } -export const OptionalsTest_TranslationsEntry = { +export const OptionalsTest_TranslationsEntry: MessageFns = { encode(message: OptionalsTest_TranslationsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -938,7 +938,7 @@ function createBaseChild(): Child { return {}; } -export const Child = { +export const Child: MessageFns = { encode(_: Child, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -1032,3 +1032,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/remove-enum-prefix-string-enums/remove-enum-prefix-string-enums.ts b/integration/remove-enum-prefix-string-enums/remove-enum-prefix-string-enums.ts index b9e096434..2472b0b55 100644 --- a/integration/remove-enum-prefix-string-enums/remove-enum-prefix-string-enums.ts +++ b/integration/remove-enum-prefix-string-enums/remove-enum-prefix-string-enums.ts @@ -214,7 +214,7 @@ function createBaseWithNestedEnum(): WithNestedEnum { }; } -export const WithNestedEnum = { +export const WithNestedEnum: MessageFns = { encode(message: WithNestedEnum, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.foo !== Foo.UNSPECIFIED) { writer.uint32(8).int32(fooToNumber(message.foo)); @@ -329,3 +329,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/remove-enum-prefix-unrecognized-enum-value/remove-enum-prefix-unrecognized-enum-value.ts b/integration/remove-enum-prefix-unrecognized-enum-value/remove-enum-prefix-unrecognized-enum-value.ts index 5aad9786d..20c7dbb03 100644 --- a/integration/remove-enum-prefix-unrecognized-enum-value/remove-enum-prefix-unrecognized-enum-value.ts +++ b/integration/remove-enum-prefix-unrecognized-enum-value/remove-enum-prefix-unrecognized-enum-value.ts @@ -157,7 +157,7 @@ function createBaseWithNestedEnum(): WithNestedEnum { return { foo: 0, Bar: 0, baz: 0, qux: 0 }; } -export const WithNestedEnum = { +export const WithNestedEnum: MessageFns = { encode(message: WithNestedEnum, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.foo !== 0) { writer.uint32(8).int32(message.foo); @@ -272,3 +272,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/remove-enum-prefix/remove-enum-prefix.ts b/integration/remove-enum-prefix/remove-enum-prefix.ts index e0e4676f2..96f0e7008 100644 --- a/integration/remove-enum-prefix/remove-enum-prefix.ts +++ b/integration/remove-enum-prefix/remove-enum-prefix.ts @@ -157,7 +157,7 @@ function createBaseWithNestedEnum(): WithNestedEnum { return { foo: 0, Bar: 0, baz: 0, qux: 0 }; } -export const WithNestedEnum = { +export const WithNestedEnum: MessageFns = { encode(message: WithNestedEnum, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.foo !== 0) { writer.uint32(8).int32(message.foo); @@ -272,3 +272,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/reserved-words/reserved-words.ts b/integration/reserved-words/reserved-words.ts index 14365461d..b4f3e8d99 100644 --- a/integration/reserved-words/reserved-words.ts +++ b/integration/reserved-words/reserved-words.ts @@ -13,7 +13,7 @@ function createBaseRecord(): Record { return {}; } -export const Record = { +export const Record: MessageFns = { encode(_: Record, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -63,3 +63,12 @@ export type DeepPartial = T extends Builtin ? T type KeysOfUnion = T extends T ? keyof T : never; export type Exact = P extends Builtin ? P : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/return-observable/observable.ts b/integration/return-observable/observable.ts index b0780e9f0..ff72c5667 100644 --- a/integration/return-observable/observable.ts +++ b/integration/return-observable/observable.ts @@ -19,7 +19,7 @@ function createBaseProduceRequest(): ProduceRequest { return { ingredients: "" }; } -export const ProduceRequest = { +export const ProduceRequest: MessageFns = { encode(message: ProduceRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.ingredients !== "") { writer.uint32(10).string(message.ingredients); @@ -76,7 +76,7 @@ function createBaseProduceReply(): ProduceReply { return { result: "" }; } -export const ProduceReply = { +export const ProduceReply: MessageFns = { encode(message: ProduceReply, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.result !== "") { writer.uint32(10).string(message.result); @@ -148,3 +148,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/schema-no-file-descriptor/const-enum.ts b/integration/schema-no-file-descriptor/const-enum.ts index b83b91558..b00e8d208 100644 --- a/integration/schema-no-file-descriptor/const-enum.ts +++ b/integration/schema-no-file-descriptor/const-enum.ts @@ -65,7 +65,7 @@ function createBaseDividerData(): DividerData { return { type: 0, typeMap: {} }; } -export const DividerData = { +export const DividerData: MessageFns = { encode(message: DividerData, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.type !== 0) { writer.uint32(8).int32(message.type); @@ -161,7 +161,7 @@ function createBaseDividerData_TypeMapEntry(): DividerData_TypeMapEntry { return { key: "", value: 0 }; } -export const DividerData_TypeMapEntry = { +export const DividerData_TypeMapEntry: MessageFns = { encode(message: DividerData_TypeMapEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -279,3 +279,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-deprecated-fields/simple.ts b/integration/simple-deprecated-fields/simple.ts index d0f68d984..69dc8018b 100644 --- a/integration/simple-deprecated-fields/simple.ts +++ b/integration/simple-deprecated-fields/simple.ts @@ -40,7 +40,7 @@ function createBaseSimple(): Simple { return { name: "", age: 0, child: undefined, testField: "", testNotDeprecated: "" }; } -export const Simple = { +export const Simple: MessageFns = { encode(message: Simple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -159,7 +159,7 @@ function createBaseChild(): Child { return { name: "" }; } -export const Child = { +export const Child: MessageFns = { encode(message: Child, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -227,3 +227,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-esmodule-interop/simple.ts b/integration/simple-esmodule-interop/simple.ts index 9001088f3..0fd863613 100644 --- a/integration/simple-esmodule-interop/simple.ts +++ b/integration/simple-esmodule-interop/simple.ts @@ -30,7 +30,7 @@ function createBaseSimple(): Simple { return { name: "", age: 0 }; } -export const Simple = { +export const Simple: MessageFns = { encode(message: Simple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -117,7 +117,7 @@ function createBaseNumbers(): Numbers { }; } -export const Numbers = { +export const Numbers: MessageFns = { encode(message: Numbers, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.double !== 0) { writer.uint32(9).double(message.double); @@ -363,3 +363,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-json-name/google/protobuf/timestamp.ts b/integration/simple-json-name/google/protobuf/timestamp.ts index a4ccaeb2e..f4a29a6af 100644 --- a/integration/simple-json-name/google/protobuf/timestamp.ts +++ b/integration/simple-json-name/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -213,3 +213,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-json-name/simple.ts b/integration/simple-json-name/simple.ts index 5aef01ed0..b754ba83c 100644 --- a/integration/simple-json-name/simple.ts +++ b/integration/simple-json-name/simple.ts @@ -31,7 +31,7 @@ function createBaseSimple(): Simple { }; } -export const Simple = { +export const Simple: MessageFns = { encode(message: Simple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -230,3 +230,12 @@ function fromJsonTimestamp(o: any): Date { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-long-bigint-noliteral/google/protobuf/timestamp.ts b/integration/simple-long-bigint-noliteral/google/protobuf/timestamp.ts index a7af674e1..34079580a 100644 --- a/integration/simple-long-bigint-noliteral/google/protobuf/timestamp.ts +++ b/integration/simple-long-bigint-noliteral/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: BigInt("0"), nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== BigInt("0")) { if (BigInt.asIntN(64, message.seconds) !== message.seconds) { @@ -205,3 +205,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-long-bigint-noliteral/google/protobuf/wrappers.ts b/integration/simple-long-bigint-noliteral/google/protobuf/wrappers.ts index b6e2746c0..a3255d2cd 100644 --- a/integration/simple-long-bigint-noliteral/google/protobuf/wrappers.ts +++ b/integration/simple-long-bigint-noliteral/google/protobuf/wrappers.ts @@ -100,7 +100,7 @@ function createBaseDoubleValue(): DoubleValue { return { value: 0 }; } -export const DoubleValue = { +export const DoubleValue: MessageFns = { encode(message: DoubleValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(9).double(message.value); @@ -157,7 +157,7 @@ function createBaseFloatValue(): FloatValue { return { value: 0 }; } -export const FloatValue = { +export const FloatValue: MessageFns = { encode(message: FloatValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(13).float(message.value); @@ -214,7 +214,7 @@ function createBaseInt64Value(): Int64Value { return { value: BigInt("0") }; } -export const Int64Value = { +export const Int64Value: MessageFns = { encode(message: Int64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== BigInt("0")) { if (BigInt.asIntN(64, message.value) !== message.value) { @@ -274,7 +274,7 @@ function createBaseUInt64Value(): UInt64Value { return { value: BigInt("0") }; } -export const UInt64Value = { +export const UInt64Value: MessageFns = { encode(message: UInt64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== BigInt("0")) { if (BigInt.asUintN(64, message.value) !== message.value) { @@ -334,7 +334,7 @@ function createBaseInt32Value(): Int32Value { return { value: 0 }; } -export const Int32Value = { +export const Int32Value: MessageFns = { encode(message: Int32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int32(message.value); @@ -391,7 +391,7 @@ function createBaseUInt32Value(): UInt32Value { return { value: 0 }; } -export const UInt32Value = { +export const UInt32Value: MessageFns = { encode(message: UInt32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint32(message.value); @@ -448,7 +448,7 @@ function createBaseBoolValue(): BoolValue { return { value: false }; } -export const BoolValue = { +export const BoolValue: MessageFns = { encode(message: BoolValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== false) { writer.uint32(8).bool(message.value); @@ -505,7 +505,7 @@ function createBaseStringValue(): StringValue { return { value: "" }; } -export const StringValue = { +export const StringValue: MessageFns = { encode(message: StringValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "") { writer.uint32(10).string(message.value); @@ -562,7 +562,7 @@ function createBaseBytesValue(): BytesValue { return { value: new Uint8Array(0) }; } -export const BytesValue = { +export const BytesValue: MessageFns = { encode(message: BytesValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value.length !== 0) { writer.uint32(10).bytes(message.value); @@ -655,3 +655,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-long-bigint-noliteral/simple.ts b/integration/simple-long-bigint-noliteral/simple.ts index df8d4e9d3..135394846 100644 --- a/integration/simple-long-bigint-noliteral/simple.ts +++ b/integration/simple-long-bigint-noliteral/simple.ts @@ -46,7 +46,7 @@ function createBaseNumbers(): Numbers { }; } -export const Numbers = { +export const Numbers: MessageFns = { encode(message: Numbers, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.double !== 0) { writer.uint32(9).double(message.double); @@ -378,3 +378,12 @@ function fromJsonTimestamp(o: any): Date { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-long-bigint/google/protobuf/timestamp.ts b/integration/simple-long-bigint/google/protobuf/timestamp.ts index 3e7efc0fe..15c9cea7f 100644 --- a/integration/simple-long-bigint/google/protobuf/timestamp.ts +++ b/integration/simple-long-bigint/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0n, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0n) { if (BigInt.asIntN(64, message.seconds) !== message.seconds) { @@ -205,3 +205,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-long-bigint/google/protobuf/wrappers.ts b/integration/simple-long-bigint/google/protobuf/wrappers.ts index efc4e9323..766fe3245 100644 --- a/integration/simple-long-bigint/google/protobuf/wrappers.ts +++ b/integration/simple-long-bigint/google/protobuf/wrappers.ts @@ -100,7 +100,7 @@ function createBaseDoubleValue(): DoubleValue { return { value: 0 }; } -export const DoubleValue = { +export const DoubleValue: MessageFns = { encode(message: DoubleValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(9).double(message.value); @@ -157,7 +157,7 @@ function createBaseFloatValue(): FloatValue { return { value: 0 }; } -export const FloatValue = { +export const FloatValue: MessageFns = { encode(message: FloatValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(13).float(message.value); @@ -214,7 +214,7 @@ function createBaseInt64Value(): Int64Value { return { value: 0n }; } -export const Int64Value = { +export const Int64Value: MessageFns = { encode(message: Int64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0n) { if (BigInt.asIntN(64, message.value) !== message.value) { @@ -274,7 +274,7 @@ function createBaseUInt64Value(): UInt64Value { return { value: 0n }; } -export const UInt64Value = { +export const UInt64Value: MessageFns = { encode(message: UInt64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0n) { if (BigInt.asUintN(64, message.value) !== message.value) { @@ -334,7 +334,7 @@ function createBaseInt32Value(): Int32Value { return { value: 0 }; } -export const Int32Value = { +export const Int32Value: MessageFns = { encode(message: Int32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int32(message.value); @@ -391,7 +391,7 @@ function createBaseUInt32Value(): UInt32Value { return { value: 0 }; } -export const UInt32Value = { +export const UInt32Value: MessageFns = { encode(message: UInt32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint32(message.value); @@ -448,7 +448,7 @@ function createBaseBoolValue(): BoolValue { return { value: false }; } -export const BoolValue = { +export const BoolValue: MessageFns = { encode(message: BoolValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== false) { writer.uint32(8).bool(message.value); @@ -505,7 +505,7 @@ function createBaseStringValue(): StringValue { return { value: "" }; } -export const StringValue = { +export const StringValue: MessageFns = { encode(message: StringValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "") { writer.uint32(10).string(message.value); @@ -562,7 +562,7 @@ function createBaseBytesValue(): BytesValue { return { value: new Uint8Array(0) }; } -export const BytesValue = { +export const BytesValue: MessageFns = { encode(message: BytesValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value.length !== 0) { writer.uint32(10).bytes(message.value); @@ -655,3 +655,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-long-bigint/simple.ts b/integration/simple-long-bigint/simple.ts index 819c144d5..37e80741f 100644 --- a/integration/simple-long-bigint/simple.ts +++ b/integration/simple-long-bigint/simple.ts @@ -46,7 +46,7 @@ function createBaseNumbers(): Numbers { }; } -export const Numbers = { +export const Numbers: MessageFns = { encode(message: Numbers, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.double !== 0) { writer.uint32(9).double(message.double); @@ -378,3 +378,12 @@ function fromJsonTimestamp(o: any): Date { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-long-string/google/protobuf/timestamp.ts b/integration/simple-long-string/google/protobuf/timestamp.ts index a56d4f75a..dbda8525d 100644 --- a/integration/simple-long-string/google/protobuf/timestamp.ts +++ b/integration/simple-long-string/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: "0", nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== "0") { writer.uint32(8).int64(message.seconds); @@ -202,3 +202,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-long-string/google/protobuf/wrappers.ts b/integration/simple-long-string/google/protobuf/wrappers.ts index 178013812..1c188c5f6 100644 --- a/integration/simple-long-string/google/protobuf/wrappers.ts +++ b/integration/simple-long-string/google/protobuf/wrappers.ts @@ -100,7 +100,7 @@ function createBaseDoubleValue(): DoubleValue { return { value: 0 }; } -export const DoubleValue = { +export const DoubleValue: MessageFns = { encode(message: DoubleValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(9).double(message.value); @@ -157,7 +157,7 @@ function createBaseFloatValue(): FloatValue { return { value: 0 }; } -export const FloatValue = { +export const FloatValue: MessageFns = { encode(message: FloatValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(13).float(message.value); @@ -214,7 +214,7 @@ function createBaseInt64Value(): Int64Value { return { value: "0" }; } -export const Int64Value = { +export const Int64Value: MessageFns = { encode(message: Int64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "0") { writer.uint32(8).int64(message.value); @@ -271,7 +271,7 @@ function createBaseUInt64Value(): UInt64Value { return { value: "0" }; } -export const UInt64Value = { +export const UInt64Value: MessageFns = { encode(message: UInt64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "0") { writer.uint32(8).uint64(message.value); @@ -328,7 +328,7 @@ function createBaseInt32Value(): Int32Value { return { value: 0 }; } -export const Int32Value = { +export const Int32Value: MessageFns = { encode(message: Int32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int32(message.value); @@ -385,7 +385,7 @@ function createBaseUInt32Value(): UInt32Value { return { value: 0 }; } -export const UInt32Value = { +export const UInt32Value: MessageFns = { encode(message: UInt32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint32(message.value); @@ -442,7 +442,7 @@ function createBaseBoolValue(): BoolValue { return { value: false }; } -export const BoolValue = { +export const BoolValue: MessageFns = { encode(message: BoolValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== false) { writer.uint32(8).bool(message.value); @@ -499,7 +499,7 @@ function createBaseStringValue(): StringValue { return { value: "" }; } -export const StringValue = { +export const StringValue: MessageFns = { encode(message: StringValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "") { writer.uint32(10).string(message.value); @@ -556,7 +556,7 @@ function createBaseBytesValue(): BytesValue { return { value: new Uint8Array(0) }; } -export const BytesValue = { +export const BytesValue: MessageFns = { encode(message: BytesValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value.length !== 0) { writer.uint32(10).bytes(message.value); @@ -649,3 +649,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-long-string/simple.ts b/integration/simple-long-string/simple.ts index ec6bbae32..c36d060b8 100644 --- a/integration/simple-long-string/simple.ts +++ b/integration/simple-long-string/simple.ts @@ -44,7 +44,7 @@ function createBaseNumbers(): Numbers { }; } -export const Numbers = { +export const Numbers: MessageFns = { encode(message: Numbers, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.double !== 0) { writer.uint32(9).double(message.double); @@ -331,3 +331,12 @@ function fromJsonTimestamp(o: any): Date { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-long/google/protobuf/wrappers.ts b/integration/simple-long/google/protobuf/wrappers.ts index 47ccddc95..de3f1c270 100644 --- a/integration/simple-long/google/protobuf/wrappers.ts +++ b/integration/simple-long/google/protobuf/wrappers.ts @@ -101,7 +101,7 @@ function createBaseDoubleValue(): DoubleValue { return { value: 0 }; } -export const DoubleValue = { +export const DoubleValue: MessageFns = { encode(message: DoubleValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(9).double(message.value); @@ -158,7 +158,7 @@ function createBaseFloatValue(): FloatValue { return { value: 0 }; } -export const FloatValue = { +export const FloatValue: MessageFns = { encode(message: FloatValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(13).float(message.value); @@ -215,7 +215,7 @@ function createBaseInt64Value(): Int64Value { return { value: Long.ZERO }; } -export const Int64Value = { +export const Int64Value: MessageFns = { encode(message: Int64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (!message.value.equals(Long.ZERO)) { writer.uint32(8).int64(message.value.toString()); @@ -272,7 +272,7 @@ function createBaseUInt64Value(): UInt64Value { return { value: Long.UZERO }; } -export const UInt64Value = { +export const UInt64Value: MessageFns = { encode(message: UInt64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (!message.value.equals(Long.UZERO)) { writer.uint32(8).uint64(message.value.toString()); @@ -329,7 +329,7 @@ function createBaseInt32Value(): Int32Value { return { value: 0 }; } -export const Int32Value = { +export const Int32Value: MessageFns = { encode(message: Int32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int32(message.value); @@ -386,7 +386,7 @@ function createBaseUInt32Value(): UInt32Value { return { value: 0 }; } -export const UInt32Value = { +export const UInt32Value: MessageFns = { encode(message: UInt32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint32(message.value); @@ -443,7 +443,7 @@ function createBaseBoolValue(): BoolValue { return { value: false }; } -export const BoolValue = { +export const BoolValue: MessageFns = { encode(message: BoolValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== false) { writer.uint32(8).bool(message.value); @@ -500,7 +500,7 @@ function createBaseStringValue(): StringValue { return { value: "" }; } -export const StringValue = { +export const StringValue: MessageFns = { encode(message: StringValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "") { writer.uint32(10).string(message.value); @@ -557,7 +557,7 @@ function createBaseBytesValue(): BytesValue { return { value: new Uint8Array(0) }; } -export const BytesValue = { +export const BytesValue: MessageFns = { encode(message: BytesValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value.length !== 0) { writer.uint32(10).bytes(message.value); @@ -650,3 +650,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-long/simple.ts b/integration/simple-long/simple.ts index aea21e4ad..261f2bb4f 100644 --- a/integration/simple-long/simple.ts +++ b/integration/simple-long/simple.ts @@ -59,7 +59,7 @@ function createBaseSimpleWithWrappers(): SimpleWithWrappers { return { name: undefined, age: undefined, enabled: undefined, bananas: undefined, coins: [], snacks: [] }; } -export const SimpleWithWrappers = { +export const SimpleWithWrappers: MessageFns = { encode(message: SimpleWithWrappers, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined) { StringValue.encode({ value: message.name! }, writer.uint32(10).fork()).join(); @@ -195,7 +195,7 @@ function createBaseSimpleWithMap(): SimpleWithMap { return { nameLookup: {}, intLookup: {}, longLookup: new Map() }; } -export const SimpleWithMap = { +export const SimpleWithMap: MessageFns = { encode(message: SimpleWithMap, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.nameLookup).forEach(([key, value]) => { SimpleWithMap_NameLookupEntry.encode({ key: key as any, value }, writer.uint32(18).fork()).join(); @@ -347,7 +347,7 @@ function createBaseSimpleWithMap_NameLookupEntry(): SimpleWithMap_NameLookupEntr return { key: "", value: "" }; } -export const SimpleWithMap_NameLookupEntry = { +export const SimpleWithMap_NameLookupEntry: MessageFns = { encode(message: SimpleWithMap_NameLookupEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -423,7 +423,7 @@ function createBaseSimpleWithMap_IntLookupEntry(): SimpleWithMap_IntLookupEntry return { key: 0, value: 0 }; } -export const SimpleWithMap_IntLookupEntry = { +export const SimpleWithMap_IntLookupEntry: MessageFns = { encode(message: SimpleWithMap_IntLookupEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int32(message.key); @@ -497,7 +497,7 @@ function createBaseSimpleWithMap_LongLookupEntry(): SimpleWithMap_LongLookupEntr return { key: Long.ZERO, value: Long.ZERO }; } -export const SimpleWithMap_LongLookupEntry = { +export const SimpleWithMap_LongLookupEntry: MessageFns = { encode(message: SimpleWithMap_LongLookupEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (!message.key.equals(Long.ZERO)) { writer.uint32(8).int64(message.key.toString()); @@ -587,7 +587,7 @@ function createBaseNumbers(): Numbers { }; } -export const Numbers = { +export const Numbers: MessageFns = { encode(message: Numbers, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.double !== 0) { writer.uint32(9).double(message.double); @@ -874,3 +874,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-optionals/google/protobuf/timestamp.ts b/integration/simple-optionals/google/protobuf/timestamp.ts index a4ccaeb2e..f4a29a6af 100644 --- a/integration/simple-optionals/google/protobuf/timestamp.ts +++ b/integration/simple-optionals/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -213,3 +213,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-optionals/google/protobuf/wrappers.ts b/integration/simple-optionals/google/protobuf/wrappers.ts index 52a93ce56..fd5825f88 100644 --- a/integration/simple-optionals/google/protobuf/wrappers.ts +++ b/integration/simple-optionals/google/protobuf/wrappers.ts @@ -100,7 +100,7 @@ function createBaseDoubleValue(): DoubleValue { return { value: 0 }; } -export const DoubleValue = { +export const DoubleValue: MessageFns = { encode(message: DoubleValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(9).double(message.value); @@ -157,7 +157,7 @@ function createBaseFloatValue(): FloatValue { return { value: 0 }; } -export const FloatValue = { +export const FloatValue: MessageFns = { encode(message: FloatValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(13).float(message.value); @@ -214,7 +214,7 @@ function createBaseInt64Value(): Int64Value { return { value: 0 }; } -export const Int64Value = { +export const Int64Value: MessageFns = { encode(message: Int64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int64(message.value); @@ -271,7 +271,7 @@ function createBaseUInt64Value(): UInt64Value { return { value: 0 }; } -export const UInt64Value = { +export const UInt64Value: MessageFns = { encode(message: UInt64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint64(message.value); @@ -328,7 +328,7 @@ function createBaseInt32Value(): Int32Value { return { value: 0 }; } -export const Int32Value = { +export const Int32Value: MessageFns = { encode(message: Int32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int32(message.value); @@ -385,7 +385,7 @@ function createBaseUInt32Value(): UInt32Value { return { value: 0 }; } -export const UInt32Value = { +export const UInt32Value: MessageFns = { encode(message: UInt32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint32(message.value); @@ -442,7 +442,7 @@ function createBaseBoolValue(): BoolValue { return { value: false }; } -export const BoolValue = { +export const BoolValue: MessageFns = { encode(message: BoolValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== false) { writer.uint32(8).bool(message.value); @@ -499,7 +499,7 @@ function createBaseStringValue(): StringValue { return { value: "" }; } -export const StringValue = { +export const StringValue: MessageFns = { encode(message: StringValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "") { writer.uint32(10).string(message.value); @@ -556,7 +556,7 @@ function createBaseBytesValue(): BytesValue { return { value: new Uint8Array(0) }; } -export const BytesValue = { +export const BytesValue: MessageFns = { encode(message: BytesValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value.length !== 0) { writer.uint32(10).bytes(message.value); @@ -660,3 +660,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-optionals/import_dir/thing.ts b/integration/simple-optionals/import_dir/thing.ts index 19939c872..00e8615cc 100644 --- a/integration/simple-optionals/import_dir/thing.ts +++ b/integration/simple-optionals/import_dir/thing.ts @@ -15,7 +15,7 @@ function createBaseImportedThing(): ImportedThing { return { createdAt: undefined }; } -export const ImportedThing = { +export const ImportedThing: MessageFns = { encode(message: ImportedThing, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.createdAt !== undefined) { Timestamp.encode(toTimestamp(message.createdAt), writer.uint32(10).fork()).join(); @@ -105,3 +105,12 @@ function fromJsonTimestamp(o: any): Date { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-optionals/simple.ts b/integration/simple-optionals/simple.ts index a6b119b18..2d31305fb 100644 --- a/integration/simple-optionals/simple.ts +++ b/integration/simple-optionals/simple.ts @@ -255,7 +255,7 @@ function createBaseSimple(): Simple { }; } -export const Simple = { +export const Simple: MessageFns = { encode(message: Simple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -479,7 +479,7 @@ function createBaseChild(): Child { return { name: "", type: 0 }; } -export const Child = { +export const Child: MessageFns = { encode(message: Child, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -553,7 +553,7 @@ function createBaseNested(): Nested { return { name: "", message: undefined, state: 0 }; } -export const Nested = { +export const Nested: MessageFns = { encode(message: Nested, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -644,7 +644,7 @@ function createBaseNested_InnerMessage(): Nested_InnerMessage { return { name: "", deep: undefined }; } -export const Nested_InnerMessage = { +export const Nested_InnerMessage: MessageFns = { encode(message: Nested_InnerMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -720,7 +720,7 @@ function createBaseNested_InnerMessage_DeepMessage(): Nested_InnerMessage_DeepMe return { name: "" }; } -export const Nested_InnerMessage_DeepMessage = { +export const Nested_InnerMessage_DeepMessage: MessageFns = { encode(message: Nested_InnerMessage_DeepMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -779,7 +779,7 @@ function createBaseOneOfMessage(): OneOfMessage { return { first: undefined, last: undefined }; } -export const OneOfMessage = { +export const OneOfMessage: MessageFns = { encode(message: OneOfMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.first !== undefined) { writer.uint32(10).string(message.first); @@ -853,7 +853,7 @@ function createBaseSimpleWithWrappers(): SimpleWithWrappers { return { name: undefined, age: undefined, enabled: undefined, coins: [], snacks: [] }; } -export const SimpleWithWrappers = { +export const SimpleWithWrappers: MessageFns = { encode(message: SimpleWithWrappers, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined) { StringValue.encode({ value: message.name! }, writer.uint32(10).fork()).join(); @@ -972,7 +972,7 @@ function createBaseEntity(): Entity { return { id: 0 }; } -export const Entity = { +export const Entity: MessageFns = { encode(message: Entity, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== 0) { writer.uint32(8).int32(message.id); @@ -1029,7 +1029,7 @@ function createBaseSimpleWithMap(): SimpleWithMap { return { entitiesById: {}, nameLookup: {}, intLookup: {} }; } -export const SimpleWithMap = { +export const SimpleWithMap: MessageFns = { encode(message: SimpleWithMap, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.entitiesById).forEach(([key, value]) => { SimpleWithMap_EntitiesByIdEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).join(); @@ -1184,7 +1184,7 @@ function createBaseSimpleWithMap_EntitiesByIdEntry(): SimpleWithMap_EntitiesById return { key: 0, value: undefined }; } -export const SimpleWithMap_EntitiesByIdEntry = { +export const SimpleWithMap_EntitiesByIdEntry: MessageFns = { encode(message: SimpleWithMap_EntitiesByIdEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int32(message.key); @@ -1262,7 +1262,7 @@ function createBaseSimpleWithMap_NameLookupEntry(): SimpleWithMap_NameLookupEntr return { key: "", value: "" }; } -export const SimpleWithMap_NameLookupEntry = { +export const SimpleWithMap_NameLookupEntry: MessageFns = { encode(message: SimpleWithMap_NameLookupEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -1338,7 +1338,7 @@ function createBaseSimpleWithMap_IntLookupEntry(): SimpleWithMap_IntLookupEntry return { key: 0, value: 0 }; } -export const SimpleWithMap_IntLookupEntry = { +export const SimpleWithMap_IntLookupEntry: MessageFns = { encode(message: SimpleWithMap_IntLookupEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int32(message.key); @@ -1412,7 +1412,7 @@ function createBaseSimpleWithSnakeCaseMap(): SimpleWithSnakeCaseMap { return { entitiesById: {} }; } -export const SimpleWithSnakeCaseMap = { +export const SimpleWithSnakeCaseMap: MessageFns = { encode(message: SimpleWithSnakeCaseMap, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.entitiesById).forEach(([key, value]) => { SimpleWithSnakeCaseMap_EntitiesByIdEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).join(); @@ -1493,7 +1493,7 @@ function createBaseSimpleWithSnakeCaseMap_EntitiesByIdEntry(): SimpleWithSnakeCa return { key: 0, value: undefined }; } -export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { +export const SimpleWithSnakeCaseMap_EntitiesByIdEntry: MessageFns = { encode(message: SimpleWithSnakeCaseMap_EntitiesByIdEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int32(message.key); @@ -1573,7 +1573,7 @@ function createBasePingRequest(): PingRequest { return { input: "" }; } -export const PingRequest = { +export const PingRequest: MessageFns = { encode(message: PingRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.input !== "") { writer.uint32(10).string(message.input); @@ -1630,7 +1630,7 @@ function createBasePingResponse(): PingResponse { return { output: "" }; } -export const PingResponse = { +export const PingResponse: MessageFns = { encode(message: PingResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.output !== "") { writer.uint32(10).string(message.output); @@ -1700,7 +1700,7 @@ function createBaseNumbers(): Numbers { }; } -export const Numbers = { +export const Numbers: MessageFns = { encode(message: Numbers, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.double !== 0) { writer.uint32(9).double(message.double); @@ -1996,3 +1996,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-proto2/simple.ts b/integration/simple-proto2/simple.ts index a050f4137..c7a0c8d72 100644 --- a/integration/simple-proto2/simple.ts +++ b/integration/simple-proto2/simple.ts @@ -47,7 +47,7 @@ function createBaseIssue56(): Issue56 { return { test: 1 }; } -export const Issue56 = { +export const Issue56: MessageFns = { encode(message: Issue56, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.test !== 1) { writer.uint32(8).int32(message.test); @@ -115,3 +115,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-prototype-defaults/google/protobuf/timestamp.ts b/integration/simple-prototype-defaults/google/protobuf/timestamp.ts index d6af1ece7..713da424e 100644 --- a/integration/simple-prototype-defaults/google/protobuf/timestamp.ts +++ b/integration/simple-prototype-defaults/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -213,3 +213,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-prototype-defaults/google/protobuf/wrappers.ts b/integration/simple-prototype-defaults/google/protobuf/wrappers.ts index 9bfc24833..6aab3c19c 100644 --- a/integration/simple-prototype-defaults/google/protobuf/wrappers.ts +++ b/integration/simple-prototype-defaults/google/protobuf/wrappers.ts @@ -100,7 +100,7 @@ function createBaseDoubleValue(): DoubleValue { return { value: 0 }; } -export const DoubleValue = { +export const DoubleValue: MessageFns = { encode(message: DoubleValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(9).double(message.value); @@ -157,7 +157,7 @@ function createBaseFloatValue(): FloatValue { return { value: 0 }; } -export const FloatValue = { +export const FloatValue: MessageFns = { encode(message: FloatValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(13).float(message.value); @@ -214,7 +214,7 @@ function createBaseInt64Value(): Int64Value { return { value: 0 }; } -export const Int64Value = { +export const Int64Value: MessageFns = { encode(message: Int64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int64(message.value); @@ -271,7 +271,7 @@ function createBaseUInt64Value(): UInt64Value { return { value: 0 }; } -export const UInt64Value = { +export const UInt64Value: MessageFns = { encode(message: UInt64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint64(message.value); @@ -328,7 +328,7 @@ function createBaseInt32Value(): Int32Value { return { value: 0 }; } -export const Int32Value = { +export const Int32Value: MessageFns = { encode(message: Int32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int32(message.value); @@ -385,7 +385,7 @@ function createBaseUInt32Value(): UInt32Value { return { value: 0 }; } -export const UInt32Value = { +export const UInt32Value: MessageFns = { encode(message: UInt32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint32(message.value); @@ -442,7 +442,7 @@ function createBaseBoolValue(): BoolValue { return { value: false }; } -export const BoolValue = { +export const BoolValue: MessageFns = { encode(message: BoolValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== false) { writer.uint32(8).bool(message.value); @@ -499,7 +499,7 @@ function createBaseStringValue(): StringValue { return { value: "" }; } -export const StringValue = { +export const StringValue: MessageFns = { encode(message: StringValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "") { writer.uint32(10).string(message.value); @@ -556,7 +556,7 @@ function createBaseBytesValue(): BytesValue { return { value: new Uint8Array(0) }; } -export const BytesValue = { +export const BytesValue: MessageFns = { encode(message: BytesValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value.length !== 0) { writer.uint32(10).bytes(message.value); @@ -660,3 +660,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-prototype-defaults/google/type/date.ts b/integration/simple-prototype-defaults/google/type/date.ts index 0302a1fc9..9cff9e966 100644 --- a/integration/simple-prototype-defaults/google/type/date.ts +++ b/integration/simple-prototype-defaults/google/type/date.ts @@ -41,7 +41,7 @@ function createBaseDateMessage(): DateMessage { return { year: 0, month: 0, day: 0 }; } -export const DateMessage = { +export const DateMessage: MessageFns = { encode(message: DateMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.year !== 0) { writer.uint32(8).int32(message.year); @@ -141,3 +141,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-prototype-defaults/import_dir/thing.ts b/integration/simple-prototype-defaults/import_dir/thing.ts index 770b124be..902e67bfd 100644 --- a/integration/simple-prototype-defaults/import_dir/thing.ts +++ b/integration/simple-prototype-defaults/import_dir/thing.ts @@ -15,7 +15,7 @@ function createBaseImportedThing(): ImportedThing { return { createdAt: undefined }; } -export const ImportedThing = { +export const ImportedThing: MessageFns = { encode(message: ImportedThing, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.createdAt !== undefined) { Timestamp.encode(toTimestamp(message.createdAt), writer.uint32(10).fork()).join(); @@ -105,3 +105,12 @@ function fromJsonTimestamp(o: any): Date { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-prototype-defaults/simple.ts b/integration/simple-prototype-defaults/simple.ts index 405c5ef62..bcc2d8e06 100644 --- a/integration/simple-prototype-defaults/simple.ts +++ b/integration/simple-prototype-defaults/simple.ts @@ -320,7 +320,7 @@ function createBaseSimple(): Simple { }; } -export const Simple = { +export const Simple: MessageFns = { encode(message: Simple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -591,7 +591,7 @@ function createBaseChild(): Child { return { name: "", type: 0 }; } -export const Child = { +export const Child: MessageFns = { encode(message: Child, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -665,7 +665,7 @@ function createBaseNested(): Nested { return { name: "", message: undefined, state: 0 }; } -export const Nested = { +export const Nested: MessageFns = { encode(message: Nested, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -756,7 +756,7 @@ function createBaseNested_InnerMessage(): Nested_InnerMessage { return { name: "", deep: undefined }; } -export const Nested_InnerMessage = { +export const Nested_InnerMessage: MessageFns = { encode(message: Nested_InnerMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -832,7 +832,7 @@ function createBaseNested_InnerMessage_DeepMessage(): Nested_InnerMessage_DeepMe return { name: "" }; } -export const Nested_InnerMessage_DeepMessage = { +export const Nested_InnerMessage_DeepMessage: MessageFns = { encode(message: Nested_InnerMessage_DeepMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -891,7 +891,7 @@ function createBaseOneOfMessage(): OneOfMessage { return { first: undefined, last: undefined }; } -export const OneOfMessage = { +export const OneOfMessage: MessageFns = { encode(message: OneOfMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.first !== undefined) { writer.uint32(10).string(message.first); @@ -965,7 +965,7 @@ function createBaseSimpleWithWrappers(): SimpleWithWrappers { return { name: undefined, age: undefined, enabled: undefined, coins: [], snacks: [], id: undefined }; } -export const SimpleWithWrappers = { +export const SimpleWithWrappers: MessageFns = { encode(message: SimpleWithWrappers, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined) { StringValue.encode({ value: message.name! }, writer.uint32(10).fork()).join(); @@ -1099,7 +1099,7 @@ function createBaseEntity(): Entity { return { id: 0 }; } -export const Entity = { +export const Entity: MessageFns = { encode(message: Entity, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== 0) { writer.uint32(8).int32(message.id); @@ -1164,7 +1164,7 @@ function createBaseSimpleWithMap(): SimpleWithMap { }; } -export const SimpleWithMap = { +export const SimpleWithMap: MessageFns = { encode(message: SimpleWithMap, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.entitiesById).forEach(([key, value]) => { SimpleWithMap_EntitiesByIdEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).join(); @@ -1471,7 +1471,7 @@ function createBaseSimpleWithMap_EntitiesByIdEntry(): SimpleWithMap_EntitiesById return { key: 0, value: undefined }; } -export const SimpleWithMap_EntitiesByIdEntry = { +export const SimpleWithMap_EntitiesByIdEntry: MessageFns = { encode(message: SimpleWithMap_EntitiesByIdEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int32(message.key); @@ -1549,7 +1549,7 @@ function createBaseSimpleWithMap_NameLookupEntry(): SimpleWithMap_NameLookupEntr return { key: "", value: "" }; } -export const SimpleWithMap_NameLookupEntry = { +export const SimpleWithMap_NameLookupEntry: MessageFns = { encode(message: SimpleWithMap_NameLookupEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -1625,7 +1625,7 @@ function createBaseSimpleWithMap_IntLookupEntry(): SimpleWithMap_IntLookupEntry return { key: 0, value: 0 }; } -export const SimpleWithMap_IntLookupEntry = { +export const SimpleWithMap_IntLookupEntry: MessageFns = { encode(message: SimpleWithMap_IntLookupEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int32(message.key); @@ -1699,7 +1699,7 @@ function createBaseSimpleWithMap_MapOfTimestampsEntry(): SimpleWithMap_MapOfTime return { key: "", value: undefined }; } -export const SimpleWithMap_MapOfTimestampsEntry = { +export const SimpleWithMap_MapOfTimestampsEntry: MessageFns = { encode(message: SimpleWithMap_MapOfTimestampsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -1777,7 +1777,7 @@ function createBaseSimpleWithMap_MapOfBytesEntry(): SimpleWithMap_MapOfBytesEntr return { key: "", value: new Uint8Array(0) }; } -export const SimpleWithMap_MapOfBytesEntry = { +export const SimpleWithMap_MapOfBytesEntry: MessageFns = { encode(message: SimpleWithMap_MapOfBytesEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -1853,7 +1853,7 @@ function createBaseSimpleWithMap_MapOfStringValuesEntry(): SimpleWithMap_MapOfSt return { key: "", value: undefined }; } -export const SimpleWithMap_MapOfStringValuesEntry = { +export const SimpleWithMap_MapOfStringValuesEntry: MessageFns = { encode(message: SimpleWithMap_MapOfStringValuesEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -1935,7 +1935,7 @@ function createBaseSimpleWithMap_LongLookupEntry(): SimpleWithMap_LongLookupEntr return { key: 0, value: 0 }; } -export const SimpleWithMap_LongLookupEntry = { +export const SimpleWithMap_LongLookupEntry: MessageFns = { encode(message: SimpleWithMap_LongLookupEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int64(message.key); @@ -2011,7 +2011,7 @@ function createBaseSimpleWithSnakeCaseMap(): SimpleWithSnakeCaseMap { return { entitiesById: {} }; } -export const SimpleWithSnakeCaseMap = { +export const SimpleWithSnakeCaseMap: MessageFns = { encode(message: SimpleWithSnakeCaseMap, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.entitiesById).forEach(([key, value]) => { SimpleWithSnakeCaseMap_EntitiesByIdEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).join(); @@ -2092,7 +2092,7 @@ function createBaseSimpleWithSnakeCaseMap_EntitiesByIdEntry(): SimpleWithSnakeCa return { key: 0, value: undefined }; } -export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { +export const SimpleWithSnakeCaseMap_EntitiesByIdEntry: MessageFns = { encode(message: SimpleWithSnakeCaseMap_EntitiesByIdEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int32(message.key); @@ -2176,7 +2176,7 @@ function createBaseSimpleWithMapOfEnums(): SimpleWithMapOfEnums { return { enumsById: {} }; } -export const SimpleWithMapOfEnums = { +export const SimpleWithMapOfEnums: MessageFns = { encode(message: SimpleWithMapOfEnums, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.enumsById).forEach(([key, value]) => { SimpleWithMapOfEnums_EnumsByIdEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).join(); @@ -2257,7 +2257,7 @@ function createBaseSimpleWithMapOfEnums_EnumsByIdEntry(): SimpleWithMapOfEnums_E return { key: 0, value: 0 }; } -export const SimpleWithMapOfEnums_EnumsByIdEntry = { +export const SimpleWithMapOfEnums_EnumsByIdEntry: MessageFns = { encode(message: SimpleWithMapOfEnums_EnumsByIdEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int32(message.key); @@ -2339,7 +2339,7 @@ function createBasePingRequest(): PingRequest { return { input: "" }; } -export const PingRequest = { +export const PingRequest: MessageFns = { encode(message: PingRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.input !== "") { writer.uint32(10).string(message.input); @@ -2396,7 +2396,7 @@ function createBasePingResponse(): PingResponse { return { output: "" }; } -export const PingResponse = { +export const PingResponse: MessageFns = { encode(message: PingResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.output !== "") { writer.uint32(10).string(message.output); @@ -2466,7 +2466,7 @@ function createBaseNumbers(): Numbers { }; } -export const Numbers = { +export const Numbers: MessageFns = { encode(message: Numbers, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.double !== 0) { writer.uint32(9).double(message.double); @@ -2698,7 +2698,7 @@ function createBaseSimpleButOptional(): SimpleButOptional { }; } -export const SimpleButOptional = { +export const SimpleButOptional: MessageFns = { encode(message: SimpleButOptional, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined) { writer.uint32(10).string(message.name); @@ -2851,7 +2851,7 @@ function createBaseEmpty(): Empty { return {}; } -export const Empty = { +export const Empty: MessageFns = { encode(_: Empty, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -2991,3 +2991,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-snake/google/protobuf/struct.ts b/integration/simple-snake/google/protobuf/struct.ts index adf822f6e..6e925f666 100644 --- a/integration/simple-snake/google/protobuf/struct.ts +++ b/integration/simple-snake/google/protobuf/struct.ts @@ -107,7 +107,7 @@ function createBaseStruct(): Struct { return { fields: {} }; } -export const Struct = { +export const Struct: MessageFns & StructWrapperFns = { encode(message: Struct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.fields).forEach(([key, value]) => { if (value !== undefined) { @@ -211,7 +211,7 @@ function createBaseStruct_FieldsEntry(): Struct_FieldsEntry { return { key: "", value: undefined }; } -export const Struct_FieldsEntry = { +export const Struct_FieldsEntry: MessageFns = { encode(message: Struct_FieldsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -292,7 +292,7 @@ function createBaseValue(): Value { }; } -export const Value = { +export const Value: MessageFns & AnyValueWrapperFns = { encode(message: Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.null_value !== undefined) { writer.uint32(8).int32(message.null_value); @@ -463,7 +463,7 @@ function createBaseListValue(): ListValue { return { values: [] }; } -export const ListValue = { +export const ListValue: MessageFns & ListValueWrapperFns = { encode(message: ListValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.values) { Value.encode(Value.wrap(v!), writer.uint32(10).fork()).join(); @@ -549,3 +549,27 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} + +export interface StructWrapperFns { + wrap(object: { [key: string]: any } | undefined): Struct; + unwrap(message: Struct): { [key: string]: any }; +} + +export interface AnyValueWrapperFns { + wrap(value: any): Value; + unwrap(message: any): string | number | boolean | Object | null | Array | undefined; +} + +export interface ListValueWrapperFns { + wrap(array: Array | undefined): ListValue; + unwrap(message: ListValue): Array; +} diff --git a/integration/simple-snake/google/protobuf/timestamp.ts b/integration/simple-snake/google/protobuf/timestamp.ts index a4ccaeb2e..f4a29a6af 100644 --- a/integration/simple-snake/google/protobuf/timestamp.ts +++ b/integration/simple-snake/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -213,3 +213,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-snake/google/protobuf/wrappers.ts b/integration/simple-snake/google/protobuf/wrappers.ts index 52a93ce56..fd5825f88 100644 --- a/integration/simple-snake/google/protobuf/wrappers.ts +++ b/integration/simple-snake/google/protobuf/wrappers.ts @@ -100,7 +100,7 @@ function createBaseDoubleValue(): DoubleValue { return { value: 0 }; } -export const DoubleValue = { +export const DoubleValue: MessageFns = { encode(message: DoubleValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(9).double(message.value); @@ -157,7 +157,7 @@ function createBaseFloatValue(): FloatValue { return { value: 0 }; } -export const FloatValue = { +export const FloatValue: MessageFns = { encode(message: FloatValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(13).float(message.value); @@ -214,7 +214,7 @@ function createBaseInt64Value(): Int64Value { return { value: 0 }; } -export const Int64Value = { +export const Int64Value: MessageFns = { encode(message: Int64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int64(message.value); @@ -271,7 +271,7 @@ function createBaseUInt64Value(): UInt64Value { return { value: 0 }; } -export const UInt64Value = { +export const UInt64Value: MessageFns = { encode(message: UInt64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint64(message.value); @@ -328,7 +328,7 @@ function createBaseInt32Value(): Int32Value { return { value: 0 }; } -export const Int32Value = { +export const Int32Value: MessageFns = { encode(message: Int32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int32(message.value); @@ -385,7 +385,7 @@ function createBaseUInt32Value(): UInt32Value { return { value: 0 }; } -export const UInt32Value = { +export const UInt32Value: MessageFns = { encode(message: UInt32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint32(message.value); @@ -442,7 +442,7 @@ function createBaseBoolValue(): BoolValue { return { value: false }; } -export const BoolValue = { +export const BoolValue: MessageFns = { encode(message: BoolValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== false) { writer.uint32(8).bool(message.value); @@ -499,7 +499,7 @@ function createBaseStringValue(): StringValue { return { value: "" }; } -export const StringValue = { +export const StringValue: MessageFns = { encode(message: StringValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "") { writer.uint32(10).string(message.value); @@ -556,7 +556,7 @@ function createBaseBytesValue(): BytesValue { return { value: new Uint8Array(0) }; } -export const BytesValue = { +export const BytesValue: MessageFns = { encode(message: BytesValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value.length !== 0) { writer.uint32(10).bytes(message.value); @@ -660,3 +660,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-snake/import_dir/thing.ts b/integration/simple-snake/import_dir/thing.ts index eebe6a7f5..0e34cd1e9 100644 --- a/integration/simple-snake/import_dir/thing.ts +++ b/integration/simple-snake/import_dir/thing.ts @@ -15,7 +15,7 @@ function createBaseImportedThing(): ImportedThing { return { created_at: undefined }; } -export const ImportedThing = { +export const ImportedThing: MessageFns = { encode(message: ImportedThing, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.created_at !== undefined) { Timestamp.encode(toTimestamp(message.created_at), writer.uint32(10).fork()).join(); @@ -105,3 +105,12 @@ function fromJsonTimestamp(o: any): Date { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-snake/simple.ts b/integration/simple-snake/simple.ts index d41d4b100..ee819ff2c 100644 --- a/integration/simple-snake/simple.ts +++ b/integration/simple-snake/simple.ts @@ -260,7 +260,7 @@ function createBaseSimple(): Simple { }; } -export const Simple = { +export const Simple: MessageFns = { encode(message: Simple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -484,7 +484,7 @@ function createBaseChild(): Child { return { name: "", type: 0 }; } -export const Child = { +export const Child: MessageFns = { encode(message: Child, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -558,7 +558,7 @@ function createBaseNested(): Nested { return { name: "", message: undefined, state: 0 }; } -export const Nested = { +export const Nested: MessageFns = { encode(message: Nested, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -649,7 +649,7 @@ function createBaseNested_InnerMessage(): Nested_InnerMessage { return { name: "", deep: undefined }; } -export const Nested_InnerMessage = { +export const Nested_InnerMessage: MessageFns = { encode(message: Nested_InnerMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -725,7 +725,7 @@ function createBaseNested_InnerMessage_DeepMessage(): Nested_InnerMessage_DeepMe return { name: "" }; } -export const Nested_InnerMessage_DeepMessage = { +export const Nested_InnerMessage_DeepMessage: MessageFns = { encode(message: Nested_InnerMessage_DeepMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -784,7 +784,7 @@ function createBaseOneOfMessage(): OneOfMessage { return { first: undefined, last: undefined }; } -export const OneOfMessage = { +export const OneOfMessage: MessageFns = { encode(message: OneOfMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.first !== undefined) { writer.uint32(10).string(message.first); @@ -858,7 +858,7 @@ function createBaseSimpleWithWrappers(): SimpleWithWrappers { return { name: undefined, age: undefined, enabled: undefined, coins: [], snacks: [] }; } -export const SimpleWithWrappers = { +export const SimpleWithWrappers: MessageFns = { encode(message: SimpleWithWrappers, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined) { StringValue.encode({ value: message.name! }, writer.uint32(10).fork()).join(); @@ -977,7 +977,7 @@ function createBaseEntity(): Entity { return { id: 0 }; } -export const Entity = { +export const Entity: MessageFns = { encode(message: Entity, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== 0) { writer.uint32(8).int32(message.id); @@ -1034,7 +1034,7 @@ function createBaseSimpleWithMap(): SimpleWithMap { return { entitiesById: {}, nameLookup: {}, intLookup: {} }; } -export const SimpleWithMap = { +export const SimpleWithMap: MessageFns = { encode(message: SimpleWithMap, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.entitiesById).forEach(([key, value]) => { SimpleWithMap_EntitiesByIdEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).join(); @@ -1189,7 +1189,7 @@ function createBaseSimpleWithMap_EntitiesByIdEntry(): SimpleWithMap_EntitiesById return { key: 0, value: undefined }; } -export const SimpleWithMap_EntitiesByIdEntry = { +export const SimpleWithMap_EntitiesByIdEntry: MessageFns = { encode(message: SimpleWithMap_EntitiesByIdEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int32(message.key); @@ -1267,7 +1267,7 @@ function createBaseSimpleWithMap_NameLookupEntry(): SimpleWithMap_NameLookupEntr return { key: "", value: "" }; } -export const SimpleWithMap_NameLookupEntry = { +export const SimpleWithMap_NameLookupEntry: MessageFns = { encode(message: SimpleWithMap_NameLookupEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -1343,7 +1343,7 @@ function createBaseSimpleWithMap_IntLookupEntry(): SimpleWithMap_IntLookupEntry return { key: 0, value: 0 }; } -export const SimpleWithMap_IntLookupEntry = { +export const SimpleWithMap_IntLookupEntry: MessageFns = { encode(message: SimpleWithMap_IntLookupEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int32(message.key); @@ -1417,7 +1417,7 @@ function createBaseSimpleWithSnakeCaseMap(): SimpleWithSnakeCaseMap { return { entities_by_id: {} }; } -export const SimpleWithSnakeCaseMap = { +export const SimpleWithSnakeCaseMap: MessageFns = { encode(message: SimpleWithSnakeCaseMap, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.entities_by_id).forEach(([key, value]) => { SimpleWithSnakeCaseMap_EntitiesByIdEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).join(); @@ -1498,7 +1498,7 @@ function createBaseSimpleWithSnakeCaseMap_EntitiesByIdEntry(): SimpleWithSnakeCa return { key: 0, value: undefined }; } -export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { +export const SimpleWithSnakeCaseMap_EntitiesByIdEntry: MessageFns = { encode(message: SimpleWithSnakeCaseMap_EntitiesByIdEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int32(message.key); @@ -1578,7 +1578,7 @@ function createBasePingRequest(): PingRequest { return { input: "" }; } -export const PingRequest = { +export const PingRequest: MessageFns = { encode(message: PingRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.input !== "") { writer.uint32(10).string(message.input); @@ -1635,7 +1635,7 @@ function createBasePingResponse(): PingResponse { return { output: "" }; } -export const PingResponse = { +export const PingResponse: MessageFns = { encode(message: PingResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.output !== "") { writer.uint32(10).string(message.output); @@ -1705,7 +1705,7 @@ function createBaseNumbers(): Numbers { }; } -export const Numbers = { +export const Numbers: MessageFns = { encode(message: Numbers, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.double !== 0) { writer.uint32(9).double(message.double); @@ -1929,7 +1929,7 @@ function createBaseSimpleStruct(): SimpleStruct { return { simple_struct: undefined }; } -export const SimpleStruct = { +export const SimpleStruct: MessageFns = { encode(message: SimpleStruct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.simple_struct !== undefined) { Struct.encode(Struct.wrap(message.simple_struct), writer.uint32(10).fork()).join(); @@ -2058,3 +2058,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-string-enums/google/protobuf/struct.ts b/integration/simple-string-enums/google/protobuf/struct.ts index 667acfe87..7683b3ef9 100644 --- a/integration/simple-string-enums/google/protobuf/struct.ts +++ b/integration/simple-string-enums/google/protobuf/struct.ts @@ -117,7 +117,7 @@ function createBaseStruct(): Struct { return { fields: {} }; } -export const Struct = { +export const Struct: MessageFns & StructWrapperFns = { encode(message: Struct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.fields).forEach(([key, value]) => { if (value !== undefined) { @@ -221,7 +221,7 @@ function createBaseStruct_FieldsEntry(): Struct_FieldsEntry { return { key: "", value: undefined }; } -export const Struct_FieldsEntry = { +export const Struct_FieldsEntry: MessageFns = { encode(message: Struct_FieldsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -302,7 +302,7 @@ function createBaseValue(): Value { }; } -export const Value = { +export const Value: MessageFns & AnyValueWrapperFns = { encode(message: Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.nullValue !== undefined) { writer.uint32(8).int32(nullValueToNumber(message.nullValue)); @@ -473,7 +473,7 @@ function createBaseListValue(): ListValue { return { values: [] }; } -export const ListValue = { +export const ListValue: MessageFns & ListValueWrapperFns = { encode(message: ListValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.values) { Value.encode(Value.wrap(v!), writer.uint32(10).fork()).join(); @@ -559,3 +559,27 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} + +export interface StructWrapperFns { + wrap(object: { [key: string]: any } | undefined): Struct; + unwrap(message: Struct): { [key: string]: any }; +} + +export interface AnyValueWrapperFns { + wrap(value: any): Value; + unwrap(message: any): string | number | boolean | Object | null | Array | undefined; +} + +export interface ListValueWrapperFns { + wrap(array: Array | undefined): ListValue; + unwrap(message: ListValue): Array; +} diff --git a/integration/simple-string-enums/simple.ts b/integration/simple-string-enums/simple.ts index 7375d8cd0..1e3bead83 100644 --- a/integration/simple-string-enums/simple.ts +++ b/integration/simple-string-enums/simple.ts @@ -77,7 +77,7 @@ function createBaseSimple(): Simple { return { name: "", state: StateEnum.UNKNOWN, states: [], nullValue: NullValue.NULL_VALUE, stateMap: {} }; } -export const Simple = { +export const Simple: MessageFns = { encode(message: Simple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -230,7 +230,7 @@ function createBaseSimple_StateMapEntry(): Simple_StateMapEntry { return { key: "", value: StateEnum.UNKNOWN }; } -export const Simple_StateMapEntry = { +export const Simple_StateMapEntry: MessageFns = { encode(message: Simple_StateMapEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -319,3 +319,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-unrecognized-enum/google/protobuf/timestamp.ts b/integration/simple-unrecognized-enum/google/protobuf/timestamp.ts index a4ccaeb2e..f4a29a6af 100644 --- a/integration/simple-unrecognized-enum/google/protobuf/timestamp.ts +++ b/integration/simple-unrecognized-enum/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -213,3 +213,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-unrecognized-enum/google/protobuf/wrappers.ts b/integration/simple-unrecognized-enum/google/protobuf/wrappers.ts index 52a93ce56..fd5825f88 100644 --- a/integration/simple-unrecognized-enum/google/protobuf/wrappers.ts +++ b/integration/simple-unrecognized-enum/google/protobuf/wrappers.ts @@ -100,7 +100,7 @@ function createBaseDoubleValue(): DoubleValue { return { value: 0 }; } -export const DoubleValue = { +export const DoubleValue: MessageFns = { encode(message: DoubleValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(9).double(message.value); @@ -157,7 +157,7 @@ function createBaseFloatValue(): FloatValue { return { value: 0 }; } -export const FloatValue = { +export const FloatValue: MessageFns = { encode(message: FloatValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(13).float(message.value); @@ -214,7 +214,7 @@ function createBaseInt64Value(): Int64Value { return { value: 0 }; } -export const Int64Value = { +export const Int64Value: MessageFns = { encode(message: Int64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int64(message.value); @@ -271,7 +271,7 @@ function createBaseUInt64Value(): UInt64Value { return { value: 0 }; } -export const UInt64Value = { +export const UInt64Value: MessageFns = { encode(message: UInt64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint64(message.value); @@ -328,7 +328,7 @@ function createBaseInt32Value(): Int32Value { return { value: 0 }; } -export const Int32Value = { +export const Int32Value: MessageFns = { encode(message: Int32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int32(message.value); @@ -385,7 +385,7 @@ function createBaseUInt32Value(): UInt32Value { return { value: 0 }; } -export const UInt32Value = { +export const UInt32Value: MessageFns = { encode(message: UInt32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint32(message.value); @@ -442,7 +442,7 @@ function createBaseBoolValue(): BoolValue { return { value: false }; } -export const BoolValue = { +export const BoolValue: MessageFns = { encode(message: BoolValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== false) { writer.uint32(8).bool(message.value); @@ -499,7 +499,7 @@ function createBaseStringValue(): StringValue { return { value: "" }; } -export const StringValue = { +export const StringValue: MessageFns = { encode(message: StringValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "") { writer.uint32(10).string(message.value); @@ -556,7 +556,7 @@ function createBaseBytesValue(): BytesValue { return { value: new Uint8Array(0) }; } -export const BytesValue = { +export const BytesValue: MessageFns = { encode(message: BytesValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value.length !== 0) { writer.uint32(10).bytes(message.value); @@ -660,3 +660,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-unrecognized-enum/import_dir/thing.ts b/integration/simple-unrecognized-enum/import_dir/thing.ts index 33650773b..2faa361c0 100644 --- a/integration/simple-unrecognized-enum/import_dir/thing.ts +++ b/integration/simple-unrecognized-enum/import_dir/thing.ts @@ -15,7 +15,7 @@ function createBaseImportedThing(): ImportedThing { return { createdAt: undefined }; } -export const ImportedThing = { +export const ImportedThing: MessageFns = { encode(message: ImportedThing, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.createdAt !== undefined) { Timestamp.encode(toTimestamp(message.createdAt), writer.uint32(10).fork()).join(); @@ -105,3 +105,12 @@ function fromJsonTimestamp(o: any): Date { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple-unrecognized-enum/simple.ts b/integration/simple-unrecognized-enum/simple.ts index 9464a7464..4f05c297c 100644 --- a/integration/simple-unrecognized-enum/simple.ts +++ b/integration/simple-unrecognized-enum/simple.ts @@ -243,7 +243,7 @@ function createBaseSimple(): Simple { }; } -export const Simple = { +export const Simple: MessageFns = { encode(message: Simple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -467,7 +467,7 @@ function createBaseChild(): Child { return { name: "", type: 0 }; } -export const Child = { +export const Child: MessageFns = { encode(message: Child, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -541,7 +541,7 @@ function createBaseNested(): Nested { return { name: "", message: undefined, state: 0 }; } -export const Nested = { +export const Nested: MessageFns = { encode(message: Nested, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -632,7 +632,7 @@ function createBaseNested_InnerMessage(): Nested_InnerMessage { return { name: "", deep: undefined }; } -export const Nested_InnerMessage = { +export const Nested_InnerMessage: MessageFns = { encode(message: Nested_InnerMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -708,7 +708,7 @@ function createBaseNested_InnerMessage_DeepMessage(): Nested_InnerMessage_DeepMe return { name: "" }; } -export const Nested_InnerMessage_DeepMessage = { +export const Nested_InnerMessage_DeepMessage: MessageFns = { encode(message: Nested_InnerMessage_DeepMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -767,7 +767,7 @@ function createBaseOneOfMessage(): OneOfMessage { return { first: undefined, last: undefined }; } -export const OneOfMessage = { +export const OneOfMessage: MessageFns = { encode(message: OneOfMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.first !== undefined) { writer.uint32(10).string(message.first); @@ -841,7 +841,7 @@ function createBaseSimpleWithWrappers(): SimpleWithWrappers { return { name: undefined, age: undefined, enabled: undefined, coins: [], snacks: [] }; } -export const SimpleWithWrappers = { +export const SimpleWithWrappers: MessageFns = { encode(message: SimpleWithWrappers, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined) { StringValue.encode({ value: message.name! }, writer.uint32(10).fork()).join(); @@ -960,7 +960,7 @@ function createBaseEntity(): Entity { return { id: 0 }; } -export const Entity = { +export const Entity: MessageFns = { encode(message: Entity, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== 0) { writer.uint32(8).int32(message.id); @@ -1017,7 +1017,7 @@ function createBaseSimpleWithMap(): SimpleWithMap { return { entitiesById: {}, nameLookup: {}, intLookup: {} }; } -export const SimpleWithMap = { +export const SimpleWithMap: MessageFns = { encode(message: SimpleWithMap, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.entitiesById).forEach(([key, value]) => { SimpleWithMap_EntitiesByIdEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).join(); @@ -1172,7 +1172,7 @@ function createBaseSimpleWithMap_EntitiesByIdEntry(): SimpleWithMap_EntitiesById return { key: 0, value: undefined }; } -export const SimpleWithMap_EntitiesByIdEntry = { +export const SimpleWithMap_EntitiesByIdEntry: MessageFns = { encode(message: SimpleWithMap_EntitiesByIdEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int32(message.key); @@ -1250,7 +1250,7 @@ function createBaseSimpleWithMap_NameLookupEntry(): SimpleWithMap_NameLookupEntr return { key: "", value: "" }; } -export const SimpleWithMap_NameLookupEntry = { +export const SimpleWithMap_NameLookupEntry: MessageFns = { encode(message: SimpleWithMap_NameLookupEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -1326,7 +1326,7 @@ function createBaseSimpleWithMap_IntLookupEntry(): SimpleWithMap_IntLookupEntry return { key: 0, value: 0 }; } -export const SimpleWithMap_IntLookupEntry = { +export const SimpleWithMap_IntLookupEntry: MessageFns = { encode(message: SimpleWithMap_IntLookupEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int32(message.key); @@ -1400,7 +1400,7 @@ function createBaseSimpleWithSnakeCaseMap(): SimpleWithSnakeCaseMap { return { entitiesById: {} }; } -export const SimpleWithSnakeCaseMap = { +export const SimpleWithSnakeCaseMap: MessageFns = { encode(message: SimpleWithSnakeCaseMap, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.entitiesById).forEach(([key, value]) => { SimpleWithSnakeCaseMap_EntitiesByIdEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).join(); @@ -1481,7 +1481,7 @@ function createBaseSimpleWithSnakeCaseMap_EntitiesByIdEntry(): SimpleWithSnakeCa return { key: 0, value: undefined }; } -export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { +export const SimpleWithSnakeCaseMap_EntitiesByIdEntry: MessageFns = { encode(message: SimpleWithSnakeCaseMap_EntitiesByIdEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int32(message.key); @@ -1561,7 +1561,7 @@ function createBasePingRequest(): PingRequest { return { input: "" }; } -export const PingRequest = { +export const PingRequest: MessageFns = { encode(message: PingRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.input !== "") { writer.uint32(10).string(message.input); @@ -1618,7 +1618,7 @@ function createBasePingResponse(): PingResponse { return { output: "" }; } -export const PingResponse = { +export const PingResponse: MessageFns = { encode(message: PingResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.output !== "") { writer.uint32(10).string(message.output); @@ -1688,7 +1688,7 @@ function createBaseNumbers(): Numbers { }; } -export const Numbers = { +export const Numbers: MessageFns = { encode(message: Numbers, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.double !== 0) { writer.uint32(9).double(message.double); @@ -1984,3 +1984,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple/google/protobuf/timestamp.ts b/integration/simple/google/protobuf/timestamp.ts index a4ccaeb2e..f4a29a6af 100644 --- a/integration/simple/google/protobuf/timestamp.ts +++ b/integration/simple/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -213,3 +213,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple/google/protobuf/wrappers.ts b/integration/simple/google/protobuf/wrappers.ts index 52a93ce56..fd5825f88 100644 --- a/integration/simple/google/protobuf/wrappers.ts +++ b/integration/simple/google/protobuf/wrappers.ts @@ -100,7 +100,7 @@ function createBaseDoubleValue(): DoubleValue { return { value: 0 }; } -export const DoubleValue = { +export const DoubleValue: MessageFns = { encode(message: DoubleValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(9).double(message.value); @@ -157,7 +157,7 @@ function createBaseFloatValue(): FloatValue { return { value: 0 }; } -export const FloatValue = { +export const FloatValue: MessageFns = { encode(message: FloatValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(13).float(message.value); @@ -214,7 +214,7 @@ function createBaseInt64Value(): Int64Value { return { value: 0 }; } -export const Int64Value = { +export const Int64Value: MessageFns = { encode(message: Int64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int64(message.value); @@ -271,7 +271,7 @@ function createBaseUInt64Value(): UInt64Value { return { value: 0 }; } -export const UInt64Value = { +export const UInt64Value: MessageFns = { encode(message: UInt64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint64(message.value); @@ -328,7 +328,7 @@ function createBaseInt32Value(): Int32Value { return { value: 0 }; } -export const Int32Value = { +export const Int32Value: MessageFns = { encode(message: Int32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int32(message.value); @@ -385,7 +385,7 @@ function createBaseUInt32Value(): UInt32Value { return { value: 0 }; } -export const UInt32Value = { +export const UInt32Value: MessageFns = { encode(message: UInt32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint32(message.value); @@ -442,7 +442,7 @@ function createBaseBoolValue(): BoolValue { return { value: false }; } -export const BoolValue = { +export const BoolValue: MessageFns = { encode(message: BoolValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== false) { writer.uint32(8).bool(message.value); @@ -499,7 +499,7 @@ function createBaseStringValue(): StringValue { return { value: "" }; } -export const StringValue = { +export const StringValue: MessageFns = { encode(message: StringValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "") { writer.uint32(10).string(message.value); @@ -556,7 +556,7 @@ function createBaseBytesValue(): BytesValue { return { value: new Uint8Array(0) }; } -export const BytesValue = { +export const BytesValue: MessageFns = { encode(message: BytesValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value.length !== 0) { writer.uint32(10).bytes(message.value); @@ -660,3 +660,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple/google/type/date.ts b/integration/simple/google/type/date.ts index cda73fc78..6e731211f 100644 --- a/integration/simple/google/type/date.ts +++ b/integration/simple/google/type/date.ts @@ -41,7 +41,7 @@ function createBaseDateMessage(): DateMessage { return { year: 0, month: 0, day: 0 }; } -export const DateMessage = { +export const DateMessage: MessageFns = { encode(message: DateMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.year !== 0) { writer.uint32(8).int32(message.year); @@ -141,3 +141,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple/import_dir/thing.ts b/integration/simple/import_dir/thing.ts index 33650773b..2faa361c0 100644 --- a/integration/simple/import_dir/thing.ts +++ b/integration/simple/import_dir/thing.ts @@ -15,7 +15,7 @@ function createBaseImportedThing(): ImportedThing { return { createdAt: undefined }; } -export const ImportedThing = { +export const ImportedThing: MessageFns = { encode(message: ImportedThing, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.createdAt !== undefined) { Timestamp.encode(toTimestamp(message.createdAt), writer.uint32(10).fork()).join(); @@ -105,3 +105,12 @@ function fromJsonTimestamp(o: any): Date { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/simple/simple.ts b/integration/simple/simple.ts index 751b111aa..8a1f0f7fd 100644 --- a/integration/simple/simple.ts +++ b/integration/simple/simple.ts @@ -328,7 +328,7 @@ function createBaseSimple(): Simple { }; } -export const Simple = { +export const Simple: MessageFns = { encode(message: Simple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -614,7 +614,7 @@ function createBaseChild(): Child { return { name: "", type: 0 }; } -export const Child = { +export const Child: MessageFns = { encode(message: Child, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -688,7 +688,7 @@ function createBaseNested(): Nested { return { name: "", message: undefined, state: 0 }; } -export const Nested = { +export const Nested: MessageFns = { encode(message: Nested, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -779,7 +779,7 @@ function createBaseNested_InnerMessage(): Nested_InnerMessage { return { name: "", deep: undefined }; } -export const Nested_InnerMessage = { +export const Nested_InnerMessage: MessageFns = { encode(message: Nested_InnerMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -855,7 +855,7 @@ function createBaseNested_InnerMessage_DeepMessage(): Nested_InnerMessage_DeepMe return { name: "" }; } -export const Nested_InnerMessage_DeepMessage = { +export const Nested_InnerMessage_DeepMessage: MessageFns = { encode(message: Nested_InnerMessage_DeepMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -914,7 +914,7 @@ function createBaseOneOfMessage(): OneOfMessage { return { first: undefined, last: undefined }; } -export const OneOfMessage = { +export const OneOfMessage: MessageFns = { encode(message: OneOfMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.first !== undefined) { writer.uint32(10).string(message.first); @@ -988,7 +988,7 @@ function createBaseSimpleWithWrappers(): SimpleWithWrappers { return { name: undefined, age: undefined, enabled: undefined, coins: [], snacks: [], id: undefined }; } -export const SimpleWithWrappers = { +export const SimpleWithWrappers: MessageFns = { encode(message: SimpleWithWrappers, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined) { StringValue.encode({ value: message.name! }, writer.uint32(10).fork()).join(); @@ -1122,7 +1122,7 @@ function createBaseEntity(): Entity { return { id: 0 }; } -export const Entity = { +export const Entity: MessageFns = { encode(message: Entity, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== 0) { writer.uint32(8).int32(message.id); @@ -1188,7 +1188,7 @@ function createBaseSimpleWithMap(): SimpleWithMap { }; } -export const SimpleWithMap = { +export const SimpleWithMap: MessageFns = { encode(message: SimpleWithMap, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.entitiesById).forEach(([key, value]) => { SimpleWithMap_EntitiesByIdEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).join(); @@ -1529,7 +1529,7 @@ function createBaseSimpleWithMap_EntitiesByIdEntry(): SimpleWithMap_EntitiesById return { key: 0, value: undefined }; } -export const SimpleWithMap_EntitiesByIdEntry = { +export const SimpleWithMap_EntitiesByIdEntry: MessageFns = { encode(message: SimpleWithMap_EntitiesByIdEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int32(message.key); @@ -1607,7 +1607,7 @@ function createBaseSimpleWithMap_NameLookupEntry(): SimpleWithMap_NameLookupEntr return { key: "", value: "" }; } -export const SimpleWithMap_NameLookupEntry = { +export const SimpleWithMap_NameLookupEntry: MessageFns = { encode(message: SimpleWithMap_NameLookupEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -1683,7 +1683,7 @@ function createBaseSimpleWithMap_IntLookupEntry(): SimpleWithMap_IntLookupEntry return { key: 0, value: 0 }; } -export const SimpleWithMap_IntLookupEntry = { +export const SimpleWithMap_IntLookupEntry: MessageFns = { encode(message: SimpleWithMap_IntLookupEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int32(message.key); @@ -1757,7 +1757,7 @@ function createBaseSimpleWithMap_MapOfTimestampsEntry(): SimpleWithMap_MapOfTime return { key: "", value: undefined }; } -export const SimpleWithMap_MapOfTimestampsEntry = { +export const SimpleWithMap_MapOfTimestampsEntry: MessageFns = { encode(message: SimpleWithMap_MapOfTimestampsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -1835,7 +1835,7 @@ function createBaseSimpleWithMap_MapOfBytesEntry(): SimpleWithMap_MapOfBytesEntr return { key: "", value: new Uint8Array(0) }; } -export const SimpleWithMap_MapOfBytesEntry = { +export const SimpleWithMap_MapOfBytesEntry: MessageFns = { encode(message: SimpleWithMap_MapOfBytesEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -1911,7 +1911,7 @@ function createBaseSimpleWithMap_MapOfStringValuesEntry(): SimpleWithMap_MapOfSt return { key: "", value: undefined }; } -export const SimpleWithMap_MapOfStringValuesEntry = { +export const SimpleWithMap_MapOfStringValuesEntry: MessageFns = { encode(message: SimpleWithMap_MapOfStringValuesEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -1989,7 +1989,7 @@ function createBaseSimpleWithMap_LongLookupEntry(): SimpleWithMap_LongLookupEntr return { key: 0, value: 0 }; } -export const SimpleWithMap_LongLookupEntry = { +export const SimpleWithMap_LongLookupEntry: MessageFns = { encode(message: SimpleWithMap_LongLookupEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int64(message.key); @@ -2065,7 +2065,7 @@ function createBaseSimpleWithMap_BoolLookupEntry(): SimpleWithMap_BoolLookupEntr return { key: false, value: 0 }; } -export const SimpleWithMap_BoolLookupEntry = { +export const SimpleWithMap_BoolLookupEntry: MessageFns = { encode(message: SimpleWithMap_BoolLookupEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== false) { writer.uint32(8).bool(message.key); @@ -2141,7 +2141,7 @@ function createBaseSimpleWithSnakeCaseMap(): SimpleWithSnakeCaseMap { return { entitiesById: {} }; } -export const SimpleWithSnakeCaseMap = { +export const SimpleWithSnakeCaseMap: MessageFns = { encode(message: SimpleWithSnakeCaseMap, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.entitiesById).forEach(([key, value]) => { SimpleWithSnakeCaseMap_EntitiesByIdEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).join(); @@ -2222,7 +2222,7 @@ function createBaseSimpleWithSnakeCaseMap_EntitiesByIdEntry(): SimpleWithSnakeCa return { key: 0, value: undefined }; } -export const SimpleWithSnakeCaseMap_EntitiesByIdEntry = { +export const SimpleWithSnakeCaseMap_EntitiesByIdEntry: MessageFns = { encode(message: SimpleWithSnakeCaseMap_EntitiesByIdEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int32(message.key); @@ -2302,7 +2302,7 @@ function createBaseSimpleWithMapOfEnums(): SimpleWithMapOfEnums { return { enumsById: {} }; } -export const SimpleWithMapOfEnums = { +export const SimpleWithMapOfEnums: MessageFns = { encode(message: SimpleWithMapOfEnums, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.enumsById).forEach(([key, value]) => { SimpleWithMapOfEnums_EnumsByIdEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).join(); @@ -2383,7 +2383,7 @@ function createBaseSimpleWithMapOfEnums_EnumsByIdEntry(): SimpleWithMapOfEnums_E return { key: 0, value: 0 }; } -export const SimpleWithMapOfEnums_EnumsByIdEntry = { +export const SimpleWithMapOfEnums_EnumsByIdEntry: MessageFns = { encode(message: SimpleWithMapOfEnums_EnumsByIdEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int32(message.key); @@ -2461,7 +2461,7 @@ function createBasePingRequest(): PingRequest { return { input: "" }; } -export const PingRequest = { +export const PingRequest: MessageFns = { encode(message: PingRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.input !== "") { writer.uint32(10).string(message.input); @@ -2518,7 +2518,7 @@ function createBasePingResponse(): PingResponse { return { output: "" }; } -export const PingResponse = { +export const PingResponse: MessageFns = { encode(message: PingResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.output !== "") { writer.uint32(10).string(message.output); @@ -2588,7 +2588,7 @@ function createBaseNumbers(): Numbers { }; } -export const Numbers = { +export const Numbers: MessageFns = { encode(message: Numbers, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.double !== 0) { writer.uint32(9).double(message.double); @@ -2820,7 +2820,7 @@ function createBaseSimpleButOptional(): SimpleButOptional { }; } -export const SimpleButOptional = { +export const SimpleButOptional: MessageFns = { encode(message: SimpleButOptional, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined) { writer.uint32(10).string(message.name); @@ -2973,7 +2973,7 @@ function createBaseEmpty(): Empty { return {}; } -export const Empty = { +export const Empty: MessageFns = { encode(_: Empty, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -3113,3 +3113,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/static-only-type-registry/bar/bar.ts b/integration/static-only-type-registry/bar/bar.ts index fd2798d7a..fca190af2 100644 --- a/integration/static-only-type-registry/bar/bar.ts +++ b/integration/static-only-type-registry/bar/bar.ts @@ -16,7 +16,7 @@ function createBaseBar(): Bar { return { foo: undefined }; } -export const Bar = { +export const Bar: MessageFns = { $type: "foo.bar.Bar" as const, encode(message: Bar, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -88,3 +88,13 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + readonly $type: V; + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/static-only-type-registry/foo.ts b/integration/static-only-type-registry/foo.ts index 6c6bf5c86..d8be8b203 100644 --- a/integration/static-only-type-registry/foo.ts +++ b/integration/static-only-type-registry/foo.ts @@ -25,7 +25,7 @@ function createBaseFoo(): Foo { return { timestamp: undefined }; } -export const Foo = { +export const Foo: MessageFns = { $type: "foo.Foo" as const, encode(message: Foo, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -86,7 +86,7 @@ function createBaseFoo2(): Foo2 { return { timestamp: undefined }; } -export const Foo2 = { +export const Foo2: MessageFns = { $type: "foo.Foo2" as const, encode(message: Foo2, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -147,7 +147,7 @@ function createBaseWithStruct(): WithStruct { return { struct: undefined }; } -export const WithStruct = { +export const WithStruct: MessageFns = { $type: "foo.WithStruct" as const, encode(message: WithStruct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -245,3 +245,13 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + readonly $type: V; + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/static-only-type-registry/google/protobuf/struct.ts b/integration/static-only-type-registry/google/protobuf/struct.ts index 1dac23881..8fa7fbfe2 100644 --- a/integration/static-only-type-registry/google/protobuf/struct.ts +++ b/integration/static-only-type-registry/google/protobuf/struct.ts @@ -108,7 +108,7 @@ function createBaseStruct(): Struct { return { fields: {} }; } -export const Struct = { +export const Struct: MessageFns & StructWrapperFns = { $type: "google.protobuf.Struct" as const, encode(message: Struct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -216,7 +216,7 @@ function createBaseStruct_FieldsEntry(): Struct_FieldsEntry { return { key: "", value: undefined }; } -export const Struct_FieldsEntry = { +export const Struct_FieldsEntry: MessageFns = { $type: "google.protobuf.Struct.FieldsEntry" as const, encode(message: Struct_FieldsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -301,7 +301,7 @@ function createBaseValue(): Value { }; } -export const Value = { +export const Value: MessageFns & AnyValueWrapperFns = { $type: "google.protobuf.Value" as const, encode(message: Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -476,7 +476,7 @@ function createBaseListValue(): ListValue { return { values: [] }; } -export const ListValue = { +export const ListValue: MessageFns & ListValueWrapperFns = { $type: "google.protobuf.ListValue" as const, encode(message: ListValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -566,3 +566,28 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + readonly $type: V; + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} + +export interface StructWrapperFns { + wrap(object: { [key: string]: any } | undefined): Struct; + unwrap(message: Struct): { [key: string]: any }; +} + +export interface AnyValueWrapperFns { + wrap(value: any): Value; + unwrap(message: any): string | number | boolean | Object | null | Array | undefined; +} + +export interface ListValueWrapperFns { + wrap(array: Array | undefined): ListValue; + unwrap(message: ListValue): Array; +} diff --git a/integration/static-only-type-registry/google/protobuf/timestamp.ts b/integration/static-only-type-registry/google/protobuf/timestamp.ts index 78d2fcc30..0db2fd41f 100644 --- a/integration/static-only-type-registry/google/protobuf/timestamp.ts +++ b/integration/static-only-type-registry/google/protobuf/timestamp.ts @@ -118,7 +118,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { $type: "google.protobuf.Timestamp" as const, encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -218,3 +218,13 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + readonly $type: V; + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/static-only/bar/bar.ts b/integration/static-only/bar/bar.ts index f5df50a3f..cc8708f08 100644 --- a/integration/static-only/bar/bar.ts +++ b/integration/static-only/bar/bar.ts @@ -15,7 +15,7 @@ function createBaseBar(): Bar { return { foo: undefined }; } -export const Bar = { +export const Bar: MessageFns = { $type: "foo.bar.Bar" as const, encode(message: Bar, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -85,3 +85,13 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + readonly $type: V; + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/static-only/foo.ts b/integration/static-only/foo.ts index 91b1473dd..4eb3adfc8 100644 --- a/integration/static-only/foo.ts +++ b/integration/static-only/foo.ts @@ -24,7 +24,7 @@ function createBaseFoo(): Foo { return { timestamp: undefined }; } -export const Foo = { +export const Foo: MessageFns = { $type: "foo.Foo" as const, encode(message: Foo, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -83,7 +83,7 @@ function createBaseFoo2(): Foo2 { return { timestamp: undefined }; } -export const Foo2 = { +export const Foo2: MessageFns = { $type: "foo.Foo2" as const, encode(message: Foo2, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -142,7 +142,7 @@ function createBaseWithStruct(): WithStruct { return { struct: undefined }; } -export const WithStruct = { +export const WithStruct: MessageFns = { $type: "foo.WithStruct" as const, encode(message: WithStruct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -238,3 +238,13 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + readonly $type: V; + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/static-only/google/protobuf/struct.ts b/integration/static-only/google/protobuf/struct.ts index d44d6db76..4177185b8 100644 --- a/integration/static-only/google/protobuf/struct.ts +++ b/integration/static-only/google/protobuf/struct.ts @@ -107,7 +107,7 @@ function createBaseStruct(): Struct { return { fields: {} }; } -export const Struct = { +export const Struct: MessageFns & StructWrapperFns = { $type: "google.protobuf.Struct" as const, encode(message: Struct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -213,7 +213,7 @@ function createBaseStruct_FieldsEntry(): Struct_FieldsEntry { return { key: "", value: undefined }; } -export const Struct_FieldsEntry = { +export const Struct_FieldsEntry: MessageFns = { $type: "google.protobuf.Struct.FieldsEntry" as const, encode(message: Struct_FieldsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -296,7 +296,7 @@ function createBaseValue(): Value { }; } -export const Value = { +export const Value: MessageFns & AnyValueWrapperFns = { $type: "google.protobuf.Value" as const, encode(message: Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -469,7 +469,7 @@ function createBaseListValue(): ListValue { return { values: [] }; } -export const ListValue = { +export const ListValue: MessageFns & ListValueWrapperFns = { $type: "google.protobuf.ListValue" as const, encode(message: ListValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -557,3 +557,28 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + readonly $type: V; + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} + +export interface StructWrapperFns { + wrap(object: { [key: string]: any } | undefined): Struct; + unwrap(message: Struct): { [key: string]: any }; +} + +export interface AnyValueWrapperFns { + wrap(value: any): Value; + unwrap(message: any): string | number | boolean | Object | null | Array | undefined; +} + +export interface ListValueWrapperFns { + wrap(array: Array | undefined): ListValue; + unwrap(message: ListValue): Array; +} diff --git a/integration/static-only/google/protobuf/timestamp.ts b/integration/static-only/google/protobuf/timestamp.ts index 54548483f..34746f66d 100644 --- a/integration/static-only/google/protobuf/timestamp.ts +++ b/integration/static-only/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { $type: "google.protobuf.Timestamp" as const, encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -215,3 +215,13 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + readonly $type: V; + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/struct/google/protobuf/struct.ts b/integration/struct/google/protobuf/struct.ts index 5172cf05f..c89463b36 100644 --- a/integration/struct/google/protobuf/struct.ts +++ b/integration/struct/google/protobuf/struct.ts @@ -107,7 +107,7 @@ function createBaseStruct(): Struct { return { fields: {} }; } -export const Struct = { +export const Struct: MessageFns & StructWrapperFns = { encode(message: Struct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.fields).forEach(([key, value]) => { if (value !== undefined) { @@ -211,7 +211,7 @@ function createBaseStruct_FieldsEntry(): Struct_FieldsEntry { return { key: "", value: undefined }; } -export const Struct_FieldsEntry = { +export const Struct_FieldsEntry: MessageFns = { encode(message: Struct_FieldsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -292,7 +292,7 @@ function createBaseValue(): Value { }; } -export const Value = { +export const Value: MessageFns & AnyValueWrapperFns = { encode(message: Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.nullValue !== undefined) { writer.uint32(8).int32(message.nullValue); @@ -463,7 +463,7 @@ function createBaseListValue(): ListValue { return { values: [] }; } -export const ListValue = { +export const ListValue: MessageFns & ListValueWrapperFns = { encode(message: ListValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.values) { Value.encode(Value.wrap(v!), writer.uint32(10).fork()).join(); @@ -549,3 +549,27 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} + +export interface StructWrapperFns { + wrap(object: { [key: string]: any } | undefined): Struct; + unwrap(message: Struct): { [key: string]: any }; +} + +export interface AnyValueWrapperFns { + wrap(value: any): Value; + unwrap(message: any): string | number | boolean | Object | null | Array | undefined; +} + +export interface ListValueWrapperFns { + wrap(array: Array | undefined): ListValue; + unwrap(message: ListValue): Array; +} diff --git a/integration/struct/struct.ts b/integration/struct/struct.ts index d4bba1475..55046a068 100644 --- a/integration/struct/struct.ts +++ b/integration/struct/struct.ts @@ -15,7 +15,7 @@ function createBaseStructMessage(): StructMessage { return { value: undefined }; } -export const StructMessage = { +export const StructMessage: MessageFns = { encode(message: StructMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== undefined) { Struct.encode(Struct.wrap(message.value), writer.uint32(10).fork()).join(); @@ -83,3 +83,12 @@ export type Exact = P extends Builtin ? P function isObject(value: any): boolean { return typeof value === "object" && value !== null; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/type-annotations/bar/bar.ts b/integration/type-annotations/bar/bar.ts index 02680a321..f88714c73 100644 --- a/integration/type-annotations/bar/bar.ts +++ b/integration/type-annotations/bar/bar.ts @@ -16,7 +16,7 @@ function createBaseBar(): Bar { return { $type: "foo.bar.Bar", foo: undefined }; } -export const Bar = { +export const Bar: MessageFns = { $type: "foo.bar.Bar" as const, encode(message: Bar, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -86,3 +86,13 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + readonly $type: V; + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/type-annotations/foo.ts b/integration/type-annotations/foo.ts index 757a45c1b..d77b61bfe 100644 --- a/integration/type-annotations/foo.ts +++ b/integration/type-annotations/foo.ts @@ -27,7 +27,7 @@ function createBaseFoo(): Foo { return { $type: "foo.Foo", timestamp: undefined }; } -export const Foo = { +export const Foo: MessageFns = { $type: "foo.Foo" as const, encode(message: Foo, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -86,7 +86,7 @@ function createBaseFoo2(): Foo2 { return { $type: "foo.Foo2", timestamp: undefined }; } -export const Foo2 = { +export const Foo2: MessageFns = { $type: "foo.Foo2" as const, encode(message: Foo2, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -145,7 +145,7 @@ function createBaseWithStruct(): WithStruct { return { $type: "foo.WithStruct", struct: undefined }; } -export const WithStruct = { +export const WithStruct: MessageFns = { $type: "foo.WithStruct" as const, encode(message: WithStruct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -241,3 +241,13 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + readonly $type: V; + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/type-annotations/google/protobuf/struct.ts b/integration/type-annotations/google/protobuf/struct.ts index 9aeb2ed9b..4560eaed4 100644 --- a/integration/type-annotations/google/protobuf/struct.ts +++ b/integration/type-annotations/google/protobuf/struct.ts @@ -111,7 +111,7 @@ function createBaseStruct(): Struct { return { $type: "google.protobuf.Struct", fields: {} }; } -export const Struct = { +export const Struct: MessageFns & StructWrapperFns = { $type: "google.protobuf.Struct" as const, encode(message: Struct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -221,7 +221,7 @@ function createBaseStruct_FieldsEntry(): Struct_FieldsEntry { return { $type: "google.protobuf.Struct.FieldsEntry", key: "", value: undefined }; } -export const Struct_FieldsEntry = { +export const Struct_FieldsEntry: MessageFns = { $type: "google.protobuf.Struct.FieldsEntry" as const, encode(message: Struct_FieldsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -306,7 +306,7 @@ function createBaseValue(): Value { }; } -export const Value = { +export const Value: MessageFns & AnyValueWrapperFns = { $type: "google.protobuf.Value" as const, encode(message: Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -480,7 +480,7 @@ function createBaseListValue(): ListValue { return { $type: "google.protobuf.ListValue", values: [] }; } -export const ListValue = { +export const ListValue: MessageFns & ListValueWrapperFns = { $type: "google.protobuf.ListValue" as const, encode(message: ListValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -568,3 +568,28 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + readonly $type: V; + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} + +export interface StructWrapperFns { + wrap(object: { [key: string]: any } | undefined): Struct; + unwrap(message: Struct): { [key: string]: any }; +} + +export interface AnyValueWrapperFns { + wrap(value: any): Value; + unwrap(message: any): string | number | boolean | Object | null | Array | undefined; +} + +export interface ListValueWrapperFns { + wrap(array: Array | undefined): ListValue; + unwrap(message: ListValue): Array; +} diff --git a/integration/type-annotations/google/protobuf/timestamp.ts b/integration/type-annotations/google/protobuf/timestamp.ts index cdb008a5e..1cff93aa0 100644 --- a/integration/type-annotations/google/protobuf/timestamp.ts +++ b/integration/type-annotations/google/protobuf/timestamp.ts @@ -118,7 +118,7 @@ function createBaseTimestamp(): Timestamp { return { $type: "google.protobuf.Timestamp", seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { $type: "google.protobuf.Timestamp" as const, encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -217,3 +217,13 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + readonly $type: V; + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/type-registry/bar/bar.ts b/integration/type-registry/bar/bar.ts index 2585869e9..91ec6175a 100644 --- a/integration/type-registry/bar/bar.ts +++ b/integration/type-registry/bar/bar.ts @@ -17,7 +17,7 @@ function createBaseBar(): Bar { return { $type: "foo.bar.Bar", foo: undefined }; } -export const Bar = { +export const Bar: MessageFns = { $type: "foo.bar.Bar" as const, encode(message: Bar, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -89,3 +89,13 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + readonly $type: V; + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/type-registry/foo.ts b/integration/type-registry/foo.ts index a529cb12a..c36443460 100644 --- a/integration/type-registry/foo.ts +++ b/integration/type-registry/foo.ts @@ -28,7 +28,7 @@ function createBaseFoo(): Foo { return { $type: "foo.Foo", timestamp: undefined }; } -export const Foo = { +export const Foo: MessageFns = { $type: "foo.Foo" as const, encode(message: Foo, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -89,7 +89,7 @@ function createBaseFoo2(): Foo2 { return { $type: "foo.Foo2", timestamp: undefined }; } -export const Foo2 = { +export const Foo2: MessageFns = { $type: "foo.Foo2" as const, encode(message: Foo2, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -150,7 +150,7 @@ function createBaseWithStruct(): WithStruct { return { $type: "foo.WithStruct", struct: undefined }; } -export const WithStruct = { +export const WithStruct: MessageFns = { $type: "foo.WithStruct" as const, encode(message: WithStruct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -248,3 +248,13 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + readonly $type: V; + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/type-registry/google/protobuf/struct.ts b/integration/type-registry/google/protobuf/struct.ts index e02d4072f..d940a85c6 100644 --- a/integration/type-registry/google/protobuf/struct.ts +++ b/integration/type-registry/google/protobuf/struct.ts @@ -112,7 +112,7 @@ function createBaseStruct(): Struct { return { $type: "google.protobuf.Struct", fields: {} }; } -export const Struct = { +export const Struct: MessageFns & StructWrapperFns = { $type: "google.protobuf.Struct" as const, encode(message: Struct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -224,7 +224,7 @@ function createBaseStruct_FieldsEntry(): Struct_FieldsEntry { return { $type: "google.protobuf.Struct.FieldsEntry", key: "", value: undefined }; } -export const Struct_FieldsEntry = { +export const Struct_FieldsEntry: MessageFns = { $type: "google.protobuf.Struct.FieldsEntry" as const, encode(message: Struct_FieldsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -311,7 +311,7 @@ function createBaseValue(): Value { }; } -export const Value = { +export const Value: MessageFns & AnyValueWrapperFns = { $type: "google.protobuf.Value" as const, encode(message: Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -487,7 +487,7 @@ function createBaseListValue(): ListValue { return { $type: "google.protobuf.ListValue", values: [] }; } -export const ListValue = { +export const ListValue: MessageFns & ListValueWrapperFns = { $type: "google.protobuf.ListValue" as const, encode(message: ListValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -577,3 +577,28 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + readonly $type: V; + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} + +export interface StructWrapperFns { + wrap(object: { [key: string]: any } | undefined): Struct; + unwrap(message: Struct): { [key: string]: any }; +} + +export interface AnyValueWrapperFns { + wrap(value: any): Value; + unwrap(message: any): string | number | boolean | Object | null | Array | undefined; +} + +export interface ListValueWrapperFns { + wrap(array: Array | undefined): ListValue; + unwrap(message: ListValue): Array; +} diff --git a/integration/type-registry/google/protobuf/timestamp.ts b/integration/type-registry/google/protobuf/timestamp.ts index dc395acfa..ae84eff12 100644 --- a/integration/type-registry/google/protobuf/timestamp.ts +++ b/integration/type-registry/google/protobuf/timestamp.ts @@ -119,7 +119,7 @@ function createBaseTimestamp(): Timestamp { return { $type: "google.protobuf.Timestamp", seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { $type: "google.protobuf.Timestamp" as const, encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { @@ -220,3 +220,13 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + readonly $type: V; + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/types-with-underscores/file.ts b/integration/types-with-underscores/file.ts index 90aed0659..3c6555761 100644 --- a/integration/types-with-underscores/file.ts +++ b/integration/types-with-underscores/file.ts @@ -17,7 +17,7 @@ function createBaseBaz(): Baz { return { foo: undefined }; } -export const Baz = { +export const Baz: MessageFns = { encode(message: Baz, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.foo !== undefined) { FooBar.encode(message.foo, writer.uint32(10).fork()).join(); @@ -74,7 +74,7 @@ function createBaseFooBar(): FooBar { return {}; } -export const FooBar = { +export const FooBar: MessageFns = { encode(_: FooBar, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -128,3 +128,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/unknown-fields/google/protobuf/compiler/plugin.ts b/integration/unknown-fields/google/protobuf/compiler/plugin.ts index c7cb76b78..cef123c63 100644 --- a/integration/unknown-fields/google/protobuf/compiler/plugin.ts +++ b/integration/unknown-fields/google/protobuf/compiler/plugin.ts @@ -164,7 +164,7 @@ function createBaseVersion(): Version { return { major: 0, minor: 0, patch: 0, suffix: "", _unknownFields: {} }; } -export const Version = { +export const Version: MessageFns = { encode(message: Version, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.major !== undefined && message.major !== 0) { writer.uint32(8).int32(message.major); @@ -246,7 +246,7 @@ function createBaseCodeGeneratorRequest(): CodeGeneratorRequest { return { fileToGenerate: [], parameter: "", protoFile: [], compilerVersion: undefined, _unknownFields: {} }; } -export const CodeGeneratorRequest = { +export const CodeGeneratorRequest: MessageFns = { encode(message: CodeGeneratorRequest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.fileToGenerate) { writer.uint32(10).string(v!); @@ -328,7 +328,7 @@ function createBaseCodeGeneratorResponse(): CodeGeneratorResponse { return { error: "", supportedFeatures: 0, file: [], _unknownFields: {} }; } -export const CodeGeneratorResponse = { +export const CodeGeneratorResponse: MessageFns = { encode(message: CodeGeneratorResponse, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.error !== undefined && message.error !== "") { writer.uint32(10).string(message.error); @@ -400,7 +400,7 @@ function createBaseCodeGeneratorResponse_File(): CodeGeneratorResponse_File { return { name: "", insertionPoint: "", content: "", generatedCodeInfo: undefined, _unknownFields: {} }; } -export const CodeGeneratorResponse_File = { +export const CodeGeneratorResponse_File: MessageFns = { encode(message: CodeGeneratorResponse_File, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -488,3 +488,8 @@ function longToNumber(int64: { toString(): string }): number { } return num; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; +} diff --git a/integration/unknown-fields/google/protobuf/descriptor.ts b/integration/unknown-fields/google/protobuf/descriptor.ts index a4ba784c0..7274ef2e5 100644 --- a/integration/unknown-fields/google/protobuf/descriptor.ts +++ b/integration/unknown-fields/google/protobuf/descriptor.ts @@ -985,7 +985,7 @@ function createBaseFileDescriptorSet(): FileDescriptorSet { return { file: [], _unknownFields: {} }; } -export const FileDescriptorSet = { +export const FileDescriptorSet: MessageFns = { encode(message: FileDescriptorSet, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.file) { FileDescriptorProto.encode(v!, writer.uint32(10).fork()).join(); @@ -1051,7 +1051,7 @@ function createBaseFileDescriptorProto(): FileDescriptorProto { }; } -export const FileDescriptorProto = { +export const FileDescriptorProto: MessageFns = { encode(message: FileDescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -1249,7 +1249,7 @@ function createBaseDescriptorProto(): DescriptorProto { }; } -export const DescriptorProto = { +export const DescriptorProto: MessageFns = { encode(message: DescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -1391,7 +1391,7 @@ function createBaseDescriptorProto_ExtensionRange(): DescriptorProto_ExtensionRa return { start: 0, end: 0, options: undefined, _unknownFields: {} }; } -export const DescriptorProto_ExtensionRange = { +export const DescriptorProto_ExtensionRange: MessageFns = { encode(message: DescriptorProto_ExtensionRange, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.start !== undefined && message.start !== 0) { writer.uint32(8).int32(message.start); @@ -1463,7 +1463,7 @@ function createBaseDescriptorProto_ReservedRange(): DescriptorProto_ReservedRang return { start: 0, end: 0, _unknownFields: {} }; } -export const DescriptorProto_ReservedRange = { +export const DescriptorProto_ReservedRange: MessageFns = { encode(message: DescriptorProto_ReservedRange, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.start !== undefined && message.start !== 0) { writer.uint32(8).int32(message.start); @@ -1525,7 +1525,7 @@ function createBaseExtensionRangeOptions(): ExtensionRangeOptions { return { uninterpretedOption: [], _unknownFields: {} }; } -export const ExtensionRangeOptions = { +export const ExtensionRangeOptions: MessageFns = { encode(message: ExtensionRangeOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.uninterpretedOption) { UninterpretedOption.encode(v!, writer.uint32(7994).fork()).join(); @@ -1590,7 +1590,7 @@ function createBaseFieldDescriptorProto(): FieldDescriptorProto { }; } -export const FieldDescriptorProto = { +export const FieldDescriptorProto: MessageFns = { encode(message: FieldDescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -1742,7 +1742,7 @@ function createBaseOneofDescriptorProto(): OneofDescriptorProto { return { name: "", options: undefined, _unknownFields: {} }; } -export const OneofDescriptorProto = { +export const OneofDescriptorProto: MessageFns = { encode(message: OneofDescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -1804,7 +1804,7 @@ function createBaseEnumDescriptorProto(): EnumDescriptorProto { return { name: "", value: [], options: undefined, reservedRange: [], reservedName: [], _unknownFields: {} }; } -export const EnumDescriptorProto = { +export const EnumDescriptorProto: MessageFns = { encode(message: EnumDescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -1896,7 +1896,7 @@ function createBaseEnumDescriptorProto_EnumReservedRange(): EnumDescriptorProto_ return { start: 0, end: 0, _unknownFields: {} }; } -export const EnumDescriptorProto_EnumReservedRange = { +export const EnumDescriptorProto_EnumReservedRange: MessageFns = { encode(message: EnumDescriptorProto_EnumReservedRange, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.start !== undefined && message.start !== 0) { writer.uint32(8).int32(message.start); @@ -1958,7 +1958,7 @@ function createBaseEnumValueDescriptorProto(): EnumValueDescriptorProto { return { name: "", number: 0, options: undefined, _unknownFields: {} }; } -export const EnumValueDescriptorProto = { +export const EnumValueDescriptorProto: MessageFns = { encode(message: EnumValueDescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -2030,7 +2030,7 @@ function createBaseServiceDescriptorProto(): ServiceDescriptorProto { return { name: "", method: [], options: undefined, _unknownFields: {} }; } -export const ServiceDescriptorProto = { +export const ServiceDescriptorProto: MessageFns = { encode(message: ServiceDescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -2110,7 +2110,7 @@ function createBaseMethodDescriptorProto(): MethodDescriptorProto { }; } -export const MethodDescriptorProto = { +export const MethodDescriptorProto: MessageFns = { encode(message: MethodDescriptorProto, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== undefined && message.name !== "") { writer.uint32(10).string(message.name); @@ -2235,7 +2235,7 @@ function createBaseFileOptions(): FileOptions { }; } -export const FileOptions = { +export const FileOptions: MessageFns = { encode(message: FileOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.javaPackage !== undefined && message.javaPackage !== "") { writer.uint32(10).string(message.javaPackage); @@ -2494,7 +2494,7 @@ function createBaseMessageOptions(): MessageOptions { }; } -export const MessageOptions = { +export const MessageOptions: MessageFns = { encode(message: MessageOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.messageSetWireFormat !== undefined && message.messageSetWireFormat !== false) { writer.uint32(8).bool(message.messageSetWireFormat); @@ -2595,7 +2595,7 @@ function createBaseFieldOptions(): FieldOptions { }; } -export const FieldOptions = { +export const FieldOptions: MessageFns = { encode(message: FieldOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.ctype !== undefined && message.ctype !== 0) { writer.uint32(8).int32(message.ctype); @@ -2707,7 +2707,7 @@ function createBaseOneofOptions(): OneofOptions { return { uninterpretedOption: [], _unknownFields: {} }; } -export const OneofOptions = { +export const OneofOptions: MessageFns = { encode(message: OneofOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.uninterpretedOption) { UninterpretedOption.encode(v!, writer.uint32(7994).fork()).join(); @@ -2759,7 +2759,7 @@ function createBaseEnumOptions(): EnumOptions { return { allowAlias: false, deprecated: false, uninterpretedOption: [], _unknownFields: {} }; } -export const EnumOptions = { +export const EnumOptions: MessageFns = { encode(message: EnumOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.allowAlias !== undefined && message.allowAlias !== false) { writer.uint32(16).bool(message.allowAlias); @@ -2831,7 +2831,7 @@ function createBaseEnumValueOptions(): EnumValueOptions { return { deprecated: false, uninterpretedOption: [], _unknownFields: {} }; } -export const EnumValueOptions = { +export const EnumValueOptions: MessageFns = { encode(message: EnumValueOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.deprecated !== undefined && message.deprecated !== false) { writer.uint32(8).bool(message.deprecated); @@ -2893,7 +2893,7 @@ function createBaseServiceOptions(): ServiceOptions { return { deprecated: false, uninterpretedOption: [], _unknownFields: {} }; } -export const ServiceOptions = { +export const ServiceOptions: MessageFns = { encode(message: ServiceOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.deprecated !== undefined && message.deprecated !== false) { writer.uint32(264).bool(message.deprecated); @@ -2955,7 +2955,7 @@ function createBaseMethodOptions(): MethodOptions { return { deprecated: false, idempotencyLevel: 0, uninterpretedOption: [], _unknownFields: {} }; } -export const MethodOptions = { +export const MethodOptions: MessageFns = { encode(message: MethodOptions, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.deprecated !== undefined && message.deprecated !== false) { writer.uint32(264).bool(message.deprecated); @@ -3036,7 +3036,7 @@ function createBaseUninterpretedOption(): UninterpretedOption { }; } -export const UninterpretedOption = { +export const UninterpretedOption: MessageFns = { encode(message: UninterpretedOption, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.name) { UninterpretedOption_NamePart.encode(v!, writer.uint32(18).fork()).join(); @@ -3148,7 +3148,7 @@ function createBaseUninterpretedOption_NamePart(): UninterpretedOption_NamePart return { namePart: "", isExtension: false, _unknownFields: {} }; } -export const UninterpretedOption_NamePart = { +export const UninterpretedOption_NamePart: MessageFns = { encode(message: UninterpretedOption_NamePart, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.namePart !== "") { writer.uint32(10).string(message.namePart); @@ -3210,7 +3210,7 @@ function createBaseSourceCodeInfo(): SourceCodeInfo { return { location: [], _unknownFields: {} }; } -export const SourceCodeInfo = { +export const SourceCodeInfo: MessageFns = { encode(message: SourceCodeInfo, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.location) { SourceCodeInfo_Location.encode(v!, writer.uint32(10).fork()).join(); @@ -3269,7 +3269,7 @@ function createBaseSourceCodeInfo_Location(): SourceCodeInfo_Location { }; } -export const SourceCodeInfo_Location = { +export const SourceCodeInfo_Location: MessageFns = { encode(message: SourceCodeInfo_Location, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { writer.uint32(10).fork(); for (const v of message.path) { @@ -3385,7 +3385,7 @@ function createBaseGeneratedCodeInfo(): GeneratedCodeInfo { return { annotation: [], _unknownFields: {} }; } -export const GeneratedCodeInfo = { +export const GeneratedCodeInfo: MessageFns = { encode(message: GeneratedCodeInfo, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.annotation) { GeneratedCodeInfo_Annotation.encode(v!, writer.uint32(10).fork()).join(); @@ -3437,7 +3437,7 @@ function createBaseGeneratedCodeInfo_Annotation(): GeneratedCodeInfo_Annotation return { path: [], sourceFile: "", begin: 0, end: 0, _unknownFields: {} }; } -export const GeneratedCodeInfo_Annotation = { +export const GeneratedCodeInfo_Annotation: MessageFns = { encode(message: GeneratedCodeInfo_Annotation, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { writer.uint32(10).fork(); for (const v of message.path) { @@ -3537,3 +3537,8 @@ function longToNumber(int64: { toString(): string }): number { } return num; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; +} diff --git a/integration/unknown-fields/options.ts b/integration/unknown-fields/options.ts index 1240a6b13..06a1f4c9b 100644 --- a/integration/unknown-fields/options.ts +++ b/integration/unknown-fields/options.ts @@ -32,7 +32,7 @@ function createBaseMyMessage(): MyMessage { return { foo: undefined, foo2: undefined, bar: undefined, quux: undefined, _unknownFields: {} }; } -export const MyMessage = { +export const MyMessage: MessageFns = { encode(message: MyMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.foo !== undefined) { writer.uint32(8).int32(message.foo); @@ -114,7 +114,7 @@ function createBaseRequestType(): RequestType { return { _unknownFields: {} }; } -export const RequestType = { +export const RequestType: MessageFns = { encode(message: RequestType, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message._unknownFields !== undefined) { for (const [key, values] of Object.entries(message._unknownFields)) { @@ -156,7 +156,7 @@ function createBaseResponseType(): ResponseType { return { _unknownFields: {} }; } -export const ResponseType = { +export const ResponseType: MessageFns = { encode(message: ResponseType, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message._unknownFields !== undefined) { for (const [key, values] of Object.entries(message._unknownFields)) { @@ -217,3 +217,8 @@ export class MyServiceClientImpl implements MyService { interface Rpc { request(service: string, method: string, data: Uint8Array): Promise; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; +} diff --git a/integration/unknown-fields/something/something.ts b/integration/unknown-fields/something/something.ts index 5e2ada6ee..a9bf9eac6 100644 --- a/integration/unknown-fields/something/something.ts +++ b/integration/unknown-fields/something/something.ts @@ -16,7 +16,7 @@ function createBaseSomething(): Something { return { hello: "", foo: [], _unknownFields: {} }; } -export const Something = { +export const Something: MessageFns = { encode(message: Something, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.hello !== "") { writer.uint32(10).string(message.hello); @@ -85,3 +85,8 @@ export const Something = { return message; }, }; + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; +} diff --git a/integration/use-date-false/google/protobuf/timestamp.ts b/integration/use-date-false/google/protobuf/timestamp.ts index a4ccaeb2e..f4a29a6af 100644 --- a/integration/use-date-false/google/protobuf/timestamp.ts +++ b/integration/use-date-false/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -213,3 +213,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/use-date-false/metadata.ts b/integration/use-date-false/metadata.ts index 992134d57..827655391 100644 --- a/integration/use-date-false/metadata.ts +++ b/integration/use-date-false/metadata.ts @@ -15,7 +15,7 @@ function createBaseMetadata(): Metadata { return { lastEdited: undefined }; } -export const Metadata = { +export const Metadata: MessageFns = { encode(message: Metadata, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.lastEdited !== undefined) { Timestamp.encode(message.lastEdited, writer.uint32(10).fork()).join(); @@ -107,3 +107,12 @@ function fromJsonTimestamp(o: any): Timestamp { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/use-date-string/google/protobuf/timestamp.ts b/integration/use-date-string/google/protobuf/timestamp.ts index a4ccaeb2e..f4a29a6af 100644 --- a/integration/use-date-string/google/protobuf/timestamp.ts +++ b/integration/use-date-string/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -213,3 +213,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/use-date-string/use-date-string.ts b/integration/use-date-string/use-date-string.ts index 1cda2d5c9..4238a92f5 100644 --- a/integration/use-date-string/use-date-string.ts +++ b/integration/use-date-string/use-date-string.ts @@ -24,7 +24,7 @@ function createBaseTodo(): Todo { return { id: "", timestamp: undefined, repeatedTimestamp: [], optionalTimestamp: undefined, mapOfTimestamps: {} }; } -export const Todo = { +export const Todo: MessageFns = { encode(message: Todo, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== "") { writer.uint32(10).string(message.id); @@ -167,7 +167,7 @@ function createBaseTodo_MapOfTimestampsEntry(): Todo_MapOfTimestampsEntry { return { key: "", value: undefined }; } -export const Todo_MapOfTimestampsEntry = { +export const Todo_MapOfTimestampsEntry: MessageFns = { encode(message: Todo_MapOfTimestampsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -269,3 +269,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/use-date-true/google/protobuf/empty.ts b/integration/use-date-true/google/protobuf/empty.ts index 0cb5ae54e..f2d153f47 100644 --- a/integration/use-date-true/google/protobuf/empty.ts +++ b/integration/use-date-true/google/protobuf/empty.ts @@ -24,7 +24,7 @@ function createBaseEmpty(): Empty { return {}; } -export const Empty = { +export const Empty: MessageFns = { encode(_: Empty, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -74,3 +74,12 @@ export type DeepPartial = T extends Builtin ? T type KeysOfUnion = T extends T ? keyof T : never; export type Exact = P extends Builtin ? P : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/use-date-true/google/protobuf/timestamp.ts b/integration/use-date-true/google/protobuf/timestamp.ts index a4ccaeb2e..f4a29a6af 100644 --- a/integration/use-date-true/google/protobuf/timestamp.ts +++ b/integration/use-date-true/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -213,3 +213,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/use-date-true/use-date-true.ts b/integration/use-date-true/use-date-true.ts index f647692cb..496547cef 100644 --- a/integration/use-date-true/use-date-true.ts +++ b/integration/use-date-true/use-date-true.ts @@ -25,7 +25,7 @@ function createBaseTodo(): Todo { return { id: "", timestamp: undefined, repeatedTimestamp: [], optionalTimestamp: undefined, mapOfTimestamps: {} }; } -export const Todo = { +export const Todo: MessageFns = { encode(message: Todo, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== "") { writer.uint32(10).string(message.id); @@ -168,7 +168,7 @@ function createBaseTodo_MapOfTimestampsEntry(): Todo_MapOfTimestampsEntry { return { key: "", value: undefined }; } -export const Todo_MapOfTimestampsEntry = { +export const Todo_MapOfTimestampsEntry: MessageFns = { encode(message: Todo_MapOfTimestampsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -319,3 +319,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/use-exact-types-false/foo.ts b/integration/use-exact-types-false/foo.ts index 1bea4ca92..bde9b73ea 100644 --- a/integration/use-exact-types-false/foo.ts +++ b/integration/use-exact-types-false/foo.ts @@ -15,7 +15,7 @@ function createBaseFoo(): Foo { return { bar: "", baz: "" }; } -export const Foo = { +export const Foo: MessageFns = { encode(message: Foo, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.bar !== "") { writer.uint32(10).string(message.bar); @@ -96,3 +96,12 @@ export type DeepPartial = T extends Builtin ? T function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create(base?: DeepPartial): T; + fromPartial(object: DeepPartial): T; +} diff --git a/integration/use-json-name/google/protobuf/timestamp.ts b/integration/use-json-name/google/protobuf/timestamp.ts index a4ccaeb2e..f4a29a6af 100644 --- a/integration/use-json-name/google/protobuf/timestamp.ts +++ b/integration/use-json-name/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -213,3 +213,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/use-json-name/use-json-name.ts b/integration/use-json-name/use-json-name.ts index 9d9ca5b89..9f1af7a6f 100644 --- a/integration/use-json-name/use-json-name.ts +++ b/integration/use-json-name/use-json-name.ts @@ -45,7 +45,7 @@ function createBaseJsonName(): JsonName { }; } -export const JsonName = { +export const JsonName: MessageFns = { encode(message: JsonName, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.other_name !== "") { writer.uint32(10).string(message.other_name); @@ -286,7 +286,7 @@ function createBaseNstedOneOf(): NstedOneOf { return { nestedOneOfField: undefined }; } -export const NstedOneOf = { +export const NstedOneOf: MessageFns = { encode(message: NstedOneOf, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.nestedOneOfField !== undefined) { writer.uint32(10).string(message.nestedOneOfField); @@ -378,3 +378,12 @@ function fromJsonTimestamp(o: any): Date { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/use-json-timestamp-raw/google/protobuf/timestamp.ts b/integration/use-json-timestamp-raw/google/protobuf/timestamp.ts index a4ccaeb2e..f4a29a6af 100644 --- a/integration/use-json-timestamp-raw/google/protobuf/timestamp.ts +++ b/integration/use-json-timestamp-raw/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -213,3 +213,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/use-json-timestamp-raw/metadata.ts b/integration/use-json-timestamp-raw/metadata.ts index f12d460f0..a6012b44e 100644 --- a/integration/use-json-timestamp-raw/metadata.ts +++ b/integration/use-json-timestamp-raw/metadata.ts @@ -15,7 +15,7 @@ function createBaseMetadata(): Metadata { return { lastEdited: undefined }; } -export const Metadata = { +export const Metadata: MessageFns = { encode(message: Metadata, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.lastEdited !== undefined) { Timestamp.encode(message.lastEdited, writer.uint32(10).fork()).join(); @@ -85,3 +85,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/use-map-type/google/protobuf/struct.ts b/integration/use-map-type/google/protobuf/struct.ts index 95fb0ee22..cd174e841 100644 --- a/integration/use-map-type/google/protobuf/struct.ts +++ b/integration/use-map-type/google/protobuf/struct.ts @@ -107,7 +107,7 @@ function createBaseStruct(): Struct { return { fields: new Map() }; } -export const Struct = { +export const Struct: MessageFns & StructWrapperFns = { encode(message: Struct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { message.fields.forEach((value, key) => { if (value !== undefined) { @@ -208,7 +208,7 @@ function createBaseStruct_FieldsEntry(): Struct_FieldsEntry { return { key: "", value: undefined }; } -export const Struct_FieldsEntry = { +export const Struct_FieldsEntry: MessageFns = { encode(message: Struct_FieldsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -289,7 +289,7 @@ function createBaseValue(): Value { }; } -export const Value = { +export const Value: MessageFns & AnyValueWrapperFns = { encode(message: Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.nullValue !== undefined) { writer.uint32(8).int32(message.nullValue); @@ -460,7 +460,7 @@ function createBaseListValue(): ListValue { return { values: [] }; } -export const ListValue = { +export const ListValue: MessageFns & ListValueWrapperFns = { encode(message: ListValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.values) { Value.encode(Value.wrap(v!), writer.uint32(10).fork()).join(); @@ -546,3 +546,27 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} + +export interface StructWrapperFns { + wrap(object: { [key: string]: any } | undefined): Struct; + unwrap(message: Struct): { [key: string]: any }; +} + +export interface AnyValueWrapperFns { + wrap(value: any): Value; + unwrap(message: any): string | number | boolean | Object | null | Array | undefined; +} + +export interface ListValueWrapperFns { + wrap(array: Array | undefined): ListValue; + unwrap(message: ListValue): Array; +} diff --git a/integration/use-map-type/google/protobuf/timestamp.ts b/integration/use-map-type/google/protobuf/timestamp.ts index a4ccaeb2e..f4a29a6af 100644 --- a/integration/use-map-type/google/protobuf/timestamp.ts +++ b/integration/use-map-type/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -213,3 +213,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/use-map-type/use-map-type.ts b/integration/use-map-type/use-map-type.ts index 2e119f345..fedf0ebeb 100644 --- a/integration/use-map-type/use-map-type.ts +++ b/integration/use-map-type/use-map-type.ts @@ -50,7 +50,7 @@ function createBaseEntity(): Entity { return { id: 0 }; } -export const Entity = { +export const Entity: MessageFns = { encode(message: Entity, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== 0) { writer.uint32(8).int32(message.id); @@ -114,7 +114,7 @@ function createBaseMaps(): Maps { }; } -export const Maps = { +export const Maps: MessageFns = { encode(message: Maps, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { message.strToEntity.forEach((value, key) => { Maps_StrToEntityEntry.encode({ key: key as any, value }, writer.uint32(10).fork()).join(); @@ -343,7 +343,7 @@ function createBaseMaps_StrToEntityEntry(): Maps_StrToEntityEntry { return { key: "", value: undefined }; } -export const Maps_StrToEntityEntry = { +export const Maps_StrToEntityEntry: MessageFns = { encode(message: Maps_StrToEntityEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -419,7 +419,7 @@ function createBaseMaps_Int32ToInt32Entry(): Maps_Int32ToInt32Entry { return { key: 0, value: 0 }; } -export const Maps_Int32ToInt32Entry = { +export const Maps_Int32ToInt32Entry: MessageFns = { encode(message: Maps_Int32ToInt32Entry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int32(message.key); @@ -493,7 +493,7 @@ function createBaseMaps_StringToBytesEntry(): Maps_StringToBytesEntry { return { key: "", value: new Uint8Array(0) }; } -export const Maps_StringToBytesEntry = { +export const Maps_StringToBytesEntry: MessageFns = { encode(message: Maps_StringToBytesEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -567,7 +567,7 @@ function createBaseMaps_Int64ToInt64Entry(): Maps_Int64ToInt64Entry { return { key: 0, value: 0 }; } -export const Maps_Int64ToInt64Entry = { +export const Maps_Int64ToInt64Entry: MessageFns = { encode(message: Maps_Int64ToInt64Entry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== 0) { writer.uint32(8).int64(message.key); @@ -641,7 +641,7 @@ function createBaseMaps_MapOfTimestampsEntry(): Maps_MapOfTimestampsEntry { return { key: "", value: undefined }; } -export const Maps_MapOfTimestampsEntry = { +export const Maps_MapOfTimestampsEntry: MessageFns = { encode(message: Maps_MapOfTimestampsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -788,3 +788,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/use-null-as-optional/use-null-as-optional.ts b/integration/use-null-as-optional/use-null-as-optional.ts index 31d23fded..3ebb3c861 100644 --- a/integration/use-null-as-optional/use-null-as-optional.ts +++ b/integration/use-null-as-optional/use-null-as-optional.ts @@ -26,7 +26,7 @@ function createBaseProfileInfo(): ProfileInfo { return { id: 0, bio: "", phone: "" }; } -export const ProfileInfo = { +export const ProfileInfo: MessageFns = { encode(message: ProfileInfo, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== 0) { writer.uint32(8).int32(message.id); @@ -115,7 +115,7 @@ function createBaseUser(): User { return { id: 0, username: "", profile: null }; } -export const User = { +export const User: MessageFns = { encode(message: User, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== 0) { writer.uint32(8).int32(message.id); @@ -206,7 +206,7 @@ function createBaseUserById(): UserById { return { id: 0 }; } -export const UserById = { +export const UserById: MessageFns = { encode(message: UserById, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== 0) { writer.uint32(8).int32(message.id); @@ -298,3 +298,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/use-numeric-enum-json/google/protobuf/struct.ts b/integration/use-numeric-enum-json/google/protobuf/struct.ts index a64701a8d..b0c520b37 100644 --- a/integration/use-numeric-enum-json/google/protobuf/struct.ts +++ b/integration/use-numeric-enum-json/google/protobuf/struct.ts @@ -107,7 +107,7 @@ function createBaseStruct(): Struct { return { fields: {} }; } -export const Struct = { +export const Struct: MessageFns & StructWrapperFns = { encode(message: Struct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.fields).forEach(([key, value]) => { if (value !== undefined) { @@ -211,7 +211,7 @@ function createBaseStruct_FieldsEntry(): Struct_FieldsEntry { return { key: "", value: undefined }; } -export const Struct_FieldsEntry = { +export const Struct_FieldsEntry: MessageFns = { encode(message: Struct_FieldsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -292,7 +292,7 @@ function createBaseValue(): Value { }; } -export const Value = { +export const Value: MessageFns & AnyValueWrapperFns = { encode(message: Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.nullValue !== undefined) { writer.uint32(8).int32(message.nullValue); @@ -463,7 +463,7 @@ function createBaseListValue(): ListValue { return { values: [] }; } -export const ListValue = { +export const ListValue: MessageFns & ListValueWrapperFns = { encode(message: ListValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.values) { Value.encode(Value.wrap(v!), writer.uint32(10).fork()).join(); @@ -549,3 +549,27 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} + +export interface StructWrapperFns { + wrap(object: { [key: string]: any } | undefined): Struct; + unwrap(message: Struct): { [key: string]: any }; +} + +export interface AnyValueWrapperFns { + wrap(value: any): Value; + unwrap(message: any): string | number | boolean | Object | null | Array | undefined; +} + +export interface ListValueWrapperFns { + wrap(array: Array | undefined): ListValue; + unwrap(message: ListValue): Array; +} diff --git a/integration/use-numeric-enum-json/simple.ts b/integration/use-numeric-enum-json/simple.ts index 25ffd0796..9556c9824 100644 --- a/integration/use-numeric-enum-json/simple.ts +++ b/integration/use-numeric-enum-json/simple.ts @@ -63,7 +63,7 @@ function createBaseSimple(): Simple { return { name: "", state: 0, states: [], nullValue: 0, stateMap: {} }; } -export const Simple = { +export const Simple: MessageFns = { encode(message: Simple, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.name !== "") { writer.uint32(10).string(message.name); @@ -216,7 +216,7 @@ function createBaseSimple_StateMapEntry(): Simple_StateMapEntry { return { key: "", value: 0 }; } -export const Simple_StateMapEntry = { +export const Simple_StateMapEntry: MessageFns = { encode(message: Simple_StateMapEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -305,3 +305,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/use-objectid-true-external-import/objectid/objectid.ts b/integration/use-objectid-true-external-import/objectid/objectid.ts index 84cdc88bc..6f3abc72a 100644 --- a/integration/use-objectid-true-external-import/objectid/objectid.ts +++ b/integration/use-objectid-true-external-import/objectid/objectid.ts @@ -14,7 +14,7 @@ function createBaseObjectId(): ObjectId { return { value: "" }; } -export const ObjectId = { +export const ObjectId: MessageFns = { encode(message: ObjectId, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "") { writer.uint32(10).string(message.value); @@ -82,3 +82,12 @@ export type Exact = P extends Builtin ? P function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/use-objectid-true-external-import/use-objectid-true.ts b/integration/use-objectid-true-external-import/use-objectid-true.ts index 05311728e..524a0355b 100644 --- a/integration/use-objectid-true-external-import/use-objectid-true.ts +++ b/integration/use-objectid-true-external-import/use-objectid-true.ts @@ -25,7 +25,7 @@ function createBaseTodo(): Todo { return { id: "", oid: undefined, repeatedOid: [], optionalOid: undefined, mapOfOids: {} }; } -export const Todo = { +export const Todo: MessageFns = { encode(message: Todo, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== "") { writer.uint32(10).string(message.id); @@ -170,7 +170,7 @@ function createBaseTodo_MapOfOidsEntry(): Todo_MapOfOidsEntry { return { key: "", value: undefined }; } -export const Todo_MapOfOidsEntry = { +export const Todo_MapOfOidsEntry: MessageFns = { encode(message: Todo_MapOfOidsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -280,3 +280,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/use-optionals-all/google/protobuf/struct.ts b/integration/use-optionals-all/google/protobuf/struct.ts index 3ec696a18..b9f6d5fb3 100644 --- a/integration/use-optionals-all/google/protobuf/struct.ts +++ b/integration/use-optionals-all/google/protobuf/struct.ts @@ -107,7 +107,7 @@ function createBaseStruct(): Struct { return { fields: {} }; } -export const Struct = { +export const Struct: MessageFns & StructWrapperFns = { encode(message: Struct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.fields || {}).forEach(([key, value]) => { if (value !== undefined) { @@ -211,7 +211,7 @@ function createBaseStruct_FieldsEntry(): Struct_FieldsEntry { return { key: "", value: undefined }; } -export const Struct_FieldsEntry = { +export const Struct_FieldsEntry: MessageFns = { encode(message: Struct_FieldsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -292,7 +292,7 @@ function createBaseValue(): Value { }; } -export const Value = { +export const Value: MessageFns & AnyValueWrapperFns = { encode(message: Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.nullValue !== undefined) { writer.uint32(8).int32(message.nullValue); @@ -463,7 +463,7 @@ function createBaseListValue(): ListValue { return { values: [] }; } -export const ListValue = { +export const ListValue: MessageFns & ListValueWrapperFns = { encode(message: ListValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.values !== undefined && message.values.length !== 0) { for (const v of message.values) { @@ -551,3 +551,27 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} + +export interface StructWrapperFns { + wrap(object: { [key: string]: any } | undefined): Struct; + unwrap(message: Struct): { [key: string]: any }; +} + +export interface AnyValueWrapperFns { + wrap(value: any): Value; + unwrap(message: any): string | number | boolean | Object | null | Array | undefined; +} + +export interface ListValueWrapperFns { + wrap(array: Array | undefined): ListValue; + unwrap(message: ListValue): Array; +} diff --git a/integration/use-optionals-all/google/protobuf/timestamp.ts b/integration/use-optionals-all/google/protobuf/timestamp.ts index 03170667c..89f8bab83 100644 --- a/integration/use-optionals-all/google/protobuf/timestamp.ts +++ b/integration/use-optionals-all/google/protobuf/timestamp.ts @@ -119,7 +119,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== undefined && message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -215,3 +215,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/use-optionals-all/test.ts b/integration/use-optionals-all/test.ts index a254c7e96..0d3f54198 100644 --- a/integration/use-optionals-all/test.ts +++ b/integration/use-optionals-all/test.ts @@ -111,7 +111,7 @@ function createBaseOptionalsTest(): OptionalsTest { }; } -export const OptionalsTest = { +export const OptionalsTest: MessageFns = { encode(message: OptionalsTest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== undefined && message.id !== 0) { writer.uint32(8).int32(message.id); @@ -605,7 +605,7 @@ function createBaseOptionalsTest_TranslationsEntry(): OptionalsTest_Translations return { key: "", value: "" }; } -export const OptionalsTest_TranslationsEntry = { +export const OptionalsTest_TranslationsEntry: MessageFns = { encode(message: OptionalsTest_TranslationsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -681,7 +681,7 @@ function createBaseChild(): Child { return {}; } -export const Child = { +export const Child: MessageFns = { encode(_: Child, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -797,3 +797,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/use-optionals-deprecated-only/test.ts b/integration/use-optionals-deprecated-only/test.ts index b1ea9ce95..8fd62fcd5 100644 --- a/integration/use-optionals-deprecated-only/test.ts +++ b/integration/use-optionals-deprecated-only/test.ts @@ -111,7 +111,7 @@ function createBaseOptionalsTest(): OptionalsTest { }; } -export const OptionalsTest = { +export const OptionalsTest: MessageFns = { encode(message: OptionalsTest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== 0) { writer.uint32(8).int32(message.id); @@ -545,7 +545,7 @@ function createBaseOptionalsTest_TranslationsEntry(): OptionalsTest_Translations return { key: "", value: "" }; } -export const OptionalsTest_TranslationsEntry = { +export const OptionalsTest_TranslationsEntry: MessageFns = { encode(message: OptionalsTest_TranslationsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -672,3 +672,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/use-optionals-no-undefined/google/protobuf/struct.ts b/integration/use-optionals-no-undefined/google/protobuf/struct.ts index 029562169..5b3842a33 100644 --- a/integration/use-optionals-no-undefined/google/protobuf/struct.ts +++ b/integration/use-optionals-no-undefined/google/protobuf/struct.ts @@ -107,7 +107,7 @@ function createBaseStruct(): Struct { return {}; } -export const Struct = { +export const Struct: MessageFns & StructWrapperFns = { encode(message: Struct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.fields || {}).forEach(([key, value]) => { if (value !== undefined) { @@ -213,7 +213,7 @@ function createBaseStruct_FieldsEntry(): Struct_FieldsEntry { return { key: "" }; } -export const Struct_FieldsEntry = { +export const Struct_FieldsEntry: MessageFns = { encode(message: Struct_FieldsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -287,7 +287,7 @@ function createBaseValue(): Value { return {}; } -export const Value = { +export const Value: MessageFns & AnyValueWrapperFns = { encode(message: Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.nullValue !== undefined) { writer.uint32(8).int32(message.nullValue); @@ -458,7 +458,7 @@ function createBaseListValue(): ListValue { return {}; } -export const ListValue = { +export const ListValue: MessageFns & ListValueWrapperFns = { encode(message: ListValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.values !== undefined && message.values.length !== 0) { for (const v of message.values) { @@ -549,3 +549,27 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} + +export interface StructWrapperFns { + wrap(object: { [key: string]: any } | undefined): Struct; + unwrap(message: Struct): { [key: string]: any }; +} + +export interface AnyValueWrapperFns { + wrap(value: any): Value; + unwrap(message: any): string | number | boolean | Object | null | Array | undefined; +} + +export interface ListValueWrapperFns { + wrap(array: Array | undefined): ListValue; + unwrap(message: ListValue): Array; +} diff --git a/integration/use-optionals-no-undefined/test.ts b/integration/use-optionals-no-undefined/test.ts index 7dad7f005..9e288f033 100644 --- a/integration/use-optionals-no-undefined/test.ts +++ b/integration/use-optionals-no-undefined/test.ts @@ -84,7 +84,7 @@ function createBaseOptionalsTest(): OptionalsTest { return {}; } -export const OptionalsTest = { +export const OptionalsTest: MessageFns = { encode(message: OptionalsTest, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== undefined && message.id !== 0) { writer.uint32(8).int32(message.id); @@ -606,7 +606,7 @@ function createBaseOptionalsTest_TranslationsEntry(): OptionalsTest_Translations return { key: "", value: "" }; } -export const OptionalsTest_TranslationsEntry = { +export const OptionalsTest_TranslationsEntry: MessageFns = { encode(message: OptionalsTest_TranslationsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -682,7 +682,7 @@ function createBaseChild(): Child { return {}; } -export const Child = { +export const Child: MessageFns = { encode(_: Child, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -776,3 +776,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/use-readonly-types/google/protobuf/field_mask.ts b/integration/use-readonly-types/google/protobuf/field_mask.ts index 7ba814289..df31cf340 100644 --- a/integration/use-readonly-types/google/protobuf/field_mask.ts +++ b/integration/use-readonly-types/google/protobuf/field_mask.ts @@ -215,7 +215,7 @@ function createBaseFieldMask(): FieldMask { return { paths: [] }; } -export const FieldMask = { +export const FieldMask: MessageFns & FieldMaskWrapperFns = { encode(message: FieldMask, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.paths) { writer.uint32(10).string(v!); @@ -293,3 +293,17 @@ export type DeepPartial = T extends Builtin ? T type KeysOfUnion = T extends T ? keyof T : never; export type Exact = P extends Builtin ? P : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} + +export interface FieldMaskWrapperFns { + wrap(paths: readonly string[]): FieldMask; + unwrap(message: any): string[]; +} diff --git a/integration/use-readonly-types/google/protobuf/struct.ts b/integration/use-readonly-types/google/protobuf/struct.ts index 282187091..d2d469aa7 100644 --- a/integration/use-readonly-types/google/protobuf/struct.ts +++ b/integration/use-readonly-types/google/protobuf/struct.ts @@ -93,7 +93,7 @@ function createBaseStruct(): Struct { return { fields: {} }; } -export const Struct = { +export const Struct: MessageFns & StructWrapperFns = { encode(message: Struct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.fields).forEach(([key, value]) => { if (value !== undefined) { @@ -197,7 +197,7 @@ function createBaseStruct_FieldsEntry(): Struct_FieldsEntry { return { key: "", value: undefined }; } -export const Struct_FieldsEntry = { +export const Struct_FieldsEntry: MessageFns = { encode(message: Struct_FieldsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -271,7 +271,7 @@ function createBaseValue(): Value { return { kind: undefined }; } -export const Value = { +export const Value: MessageFns & AnyValueWrapperFns = { encode(message: Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { switch (message.kind?.$case) { case "nullValue": @@ -476,7 +476,7 @@ function createBaseListValue(): ListValue { return { values: [] }; } -export const ListValue = { +export const ListValue: MessageFns & ListValueWrapperFns = { encode(message: ListValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.values) { Value.encode(Value.wrap(v!), writer.uint32(10).fork()).join(); @@ -564,3 +564,27 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} + +export interface StructWrapperFns { + wrap(object: { [key: string]: any } | undefined): Struct; + unwrap(message: Struct): { [key: string]: any }; +} + +export interface AnyValueWrapperFns { + wrap(value: any): Value; + unwrap(message: any): string | number | boolean | Object | null | Array | undefined; +} + +export interface ListValueWrapperFns { + wrap(array: ReadonlyArray | undefined): ListValue; + unwrap(message: any): Array; +} diff --git a/integration/use-readonly-types/use-readonly-types.ts b/integration/use-readonly-types/use-readonly-types.ts index 7084b0975..544cacf90 100644 --- a/integration/use-readonly-types/use-readonly-types.ts +++ b/integration/use-readonly-types/use-readonly-types.ts @@ -45,7 +45,7 @@ function createBaseEntity(): Entity { }; } -export const Entity = { +export const Entity: MessageFns = { encode(message: Entity, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.intVal !== 0) { writer.uint32(8).int32(message.intVal); @@ -304,7 +304,7 @@ function createBaseSubEntity(): SubEntity { return { subVal: 0 }; } -export const SubEntity = { +export const SubEntity: MessageFns = { encode(message: SubEntity, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.subVal !== 0) { writer.uint32(8).int32(message.subVal); @@ -378,3 +378,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/value/google/protobuf/struct.ts b/integration/value/google/protobuf/struct.ts index 5172cf05f..c89463b36 100644 --- a/integration/value/google/protobuf/struct.ts +++ b/integration/value/google/protobuf/struct.ts @@ -107,7 +107,7 @@ function createBaseStruct(): Struct { return { fields: {} }; } -export const Struct = { +export const Struct: MessageFns & StructWrapperFns = { encode(message: Struct, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { Object.entries(message.fields).forEach(([key, value]) => { if (value !== undefined) { @@ -211,7 +211,7 @@ function createBaseStruct_FieldsEntry(): Struct_FieldsEntry { return { key: "", value: undefined }; } -export const Struct_FieldsEntry = { +export const Struct_FieldsEntry: MessageFns = { encode(message: Struct_FieldsEntry, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.key !== "") { writer.uint32(10).string(message.key); @@ -292,7 +292,7 @@ function createBaseValue(): Value { }; } -export const Value = { +export const Value: MessageFns & AnyValueWrapperFns = { encode(message: Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.nullValue !== undefined) { writer.uint32(8).int32(message.nullValue); @@ -463,7 +463,7 @@ function createBaseListValue(): ListValue { return { values: [] }; } -export const ListValue = { +export const ListValue: MessageFns & ListValueWrapperFns = { encode(message: ListValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.values) { Value.encode(Value.wrap(v!), writer.uint32(10).fork()).join(); @@ -549,3 +549,27 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} + +export interface StructWrapperFns { + wrap(object: { [key: string]: any } | undefined): Struct; + unwrap(message: Struct): { [key: string]: any }; +} + +export interface AnyValueWrapperFns { + wrap(value: any): Value; + unwrap(message: any): string | number | boolean | Object | null | Array | undefined; +} + +export interface ListValueWrapperFns { + wrap(array: Array | undefined): ListValue; + unwrap(message: ListValue): Array; +} diff --git a/integration/value/google/protobuf/wrappers.ts b/integration/value/google/protobuf/wrappers.ts index 52a93ce56..fd5825f88 100644 --- a/integration/value/google/protobuf/wrappers.ts +++ b/integration/value/google/protobuf/wrappers.ts @@ -100,7 +100,7 @@ function createBaseDoubleValue(): DoubleValue { return { value: 0 }; } -export const DoubleValue = { +export const DoubleValue: MessageFns = { encode(message: DoubleValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(9).double(message.value); @@ -157,7 +157,7 @@ function createBaseFloatValue(): FloatValue { return { value: 0 }; } -export const FloatValue = { +export const FloatValue: MessageFns = { encode(message: FloatValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(13).float(message.value); @@ -214,7 +214,7 @@ function createBaseInt64Value(): Int64Value { return { value: 0 }; } -export const Int64Value = { +export const Int64Value: MessageFns = { encode(message: Int64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int64(message.value); @@ -271,7 +271,7 @@ function createBaseUInt64Value(): UInt64Value { return { value: 0 }; } -export const UInt64Value = { +export const UInt64Value: MessageFns = { encode(message: UInt64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint64(message.value); @@ -328,7 +328,7 @@ function createBaseInt32Value(): Int32Value { return { value: 0 }; } -export const Int32Value = { +export const Int32Value: MessageFns = { encode(message: Int32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int32(message.value); @@ -385,7 +385,7 @@ function createBaseUInt32Value(): UInt32Value { return { value: 0 }; } -export const UInt32Value = { +export const UInt32Value: MessageFns = { encode(message: UInt32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint32(message.value); @@ -442,7 +442,7 @@ function createBaseBoolValue(): BoolValue { return { value: false }; } -export const BoolValue = { +export const BoolValue: MessageFns = { encode(message: BoolValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== false) { writer.uint32(8).bool(message.value); @@ -499,7 +499,7 @@ function createBaseStringValue(): StringValue { return { value: "" }; } -export const StringValue = { +export const StringValue: MessageFns = { encode(message: StringValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "") { writer.uint32(10).string(message.value); @@ -556,7 +556,7 @@ function createBaseBytesValue(): BytesValue { return { value: new Uint8Array(0) }; } -export const BytesValue = { +export const BytesValue: MessageFns = { encode(message: BytesValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value.length !== 0) { writer.uint32(10).bytes(message.value); @@ -660,3 +660,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/value/value.ts b/integration/value/value.ts index f3c4b52c2..834185651 100644 --- a/integration/value/value.ts +++ b/integration/value/value.ts @@ -20,7 +20,7 @@ function createBaseValueMessage(): ValueMessage { return { value: undefined, anyList: undefined, repeatedAny: [], repeatedStrings: [], structValue: undefined }; } -export const ValueMessage = { +export const ValueMessage: MessageFns = { encode(message: ValueMessage, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== undefined) { Value.encode(Value.wrap(message.value), writer.uint32(10).fork()).join(); @@ -156,3 +156,12 @@ function isObject(value: any): boolean { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/vector-tile/vector_tile.ts b/integration/vector-tile/vector_tile.ts index 0d7d790c4..8fa302e94 100644 --- a/integration/vector-tile/vector_tile.ts +++ b/integration/vector-tile/vector_tile.ts @@ -85,7 +85,7 @@ function createBaseTile(): Tile { return { layers: [] }; } -export const Tile = { +export const Tile: MessageFns = { encode(message: Tile, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { for (const v of message.layers) { Tile_Layer.encode(v!, writer.uint32(26).fork()).join(); @@ -144,7 +144,7 @@ function createBaseTile_Value(): Tile_Value { return { stringValue: "", floatValue: 0, doubleValue: 0, intValue: 0, uintValue: 0, sintValue: 0, boolValue: false }; } -export const Tile_Value = { +export const Tile_Value: MessageFns = { encode(message: Tile_Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.stringValue !== undefined && message.stringValue !== "") { writer.uint32(10).string(message.stringValue); @@ -293,7 +293,7 @@ function createBaseTile_Feature(): Tile_Feature { return { id: 0, tags: [], type: 0, geometry: [] }; } -export const Tile_Feature = { +export const Tile_Feature: MessageFns = { encode(message: Tile_Feature, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.id !== undefined && message.id !== 0) { writer.uint32(8).uint64(message.id); @@ -421,7 +421,7 @@ function createBaseTile_Layer(): Tile_Layer { return { version: 1, name: "", features: [], keys: [], values: [], extent: 4096 }; } -export const Tile_Layer = { +export const Tile_Layer: MessageFns = { encode(message: Tile_Layer, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.version !== 1) { writer.uint32(120).uint32(message.version); @@ -579,3 +579,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/wrappers-regression/google/protobuf/empty.ts b/integration/wrappers-regression/google/protobuf/empty.ts index 0cb5ae54e..f2d153f47 100644 --- a/integration/wrappers-regression/google/protobuf/empty.ts +++ b/integration/wrappers-regression/google/protobuf/empty.ts @@ -24,7 +24,7 @@ function createBaseEmpty(): Empty { return {}; } -export const Empty = { +export const Empty: MessageFns = { encode(_: Empty, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { return writer; }, @@ -74,3 +74,12 @@ export type DeepPartial = T extends Builtin ? T type KeysOfUnion = T extends T ? keyof T : never; export type Exact = P extends Builtin ? P : P & { [K in keyof P]: Exact } & { [K in Exclude>]: never }; + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/wrappers-regression/google/protobuf/timestamp.ts b/integration/wrappers-regression/google/protobuf/timestamp.ts index a4ccaeb2e..f4a29a6af 100644 --- a/integration/wrappers-regression/google/protobuf/timestamp.ts +++ b/integration/wrappers-regression/google/protobuf/timestamp.ts @@ -117,7 +117,7 @@ function createBaseTimestamp(): Timestamp { return { seconds: 0, nanos: 0 }; } -export const Timestamp = { +export const Timestamp: MessageFns = { encode(message: Timestamp, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.seconds !== 0) { writer.uint32(8).int64(message.seconds); @@ -213,3 +213,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/integration/wrappers-regression/google/protobuf/wrappers.ts b/integration/wrappers-regression/google/protobuf/wrappers.ts index 52a93ce56..fd5825f88 100644 --- a/integration/wrappers-regression/google/protobuf/wrappers.ts +++ b/integration/wrappers-regression/google/protobuf/wrappers.ts @@ -100,7 +100,7 @@ function createBaseDoubleValue(): DoubleValue { return { value: 0 }; } -export const DoubleValue = { +export const DoubleValue: MessageFns = { encode(message: DoubleValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(9).double(message.value); @@ -157,7 +157,7 @@ function createBaseFloatValue(): FloatValue { return { value: 0 }; } -export const FloatValue = { +export const FloatValue: MessageFns = { encode(message: FloatValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(13).float(message.value); @@ -214,7 +214,7 @@ function createBaseInt64Value(): Int64Value { return { value: 0 }; } -export const Int64Value = { +export const Int64Value: MessageFns = { encode(message: Int64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int64(message.value); @@ -271,7 +271,7 @@ function createBaseUInt64Value(): UInt64Value { return { value: 0 }; } -export const UInt64Value = { +export const UInt64Value: MessageFns = { encode(message: UInt64Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint64(message.value); @@ -328,7 +328,7 @@ function createBaseInt32Value(): Int32Value { return { value: 0 }; } -export const Int32Value = { +export const Int32Value: MessageFns = { encode(message: Int32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).int32(message.value); @@ -385,7 +385,7 @@ function createBaseUInt32Value(): UInt32Value { return { value: 0 }; } -export const UInt32Value = { +export const UInt32Value: MessageFns = { encode(message: UInt32Value, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== 0) { writer.uint32(8).uint32(message.value); @@ -442,7 +442,7 @@ function createBaseBoolValue(): BoolValue { return { value: false }; } -export const BoolValue = { +export const BoolValue: MessageFns = { encode(message: BoolValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== false) { writer.uint32(8).bool(message.value); @@ -499,7 +499,7 @@ function createBaseStringValue(): StringValue { return { value: "" }; } -export const StringValue = { +export const StringValue: MessageFns = { encode(message: StringValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value !== "") { writer.uint32(10).string(message.value); @@ -556,7 +556,7 @@ function createBaseBytesValue(): BytesValue { return { value: new Uint8Array(0) }; } -export const BytesValue = { +export const BytesValue: MessageFns = { encode(message: BytesValue, writer: BinaryWriter = new BinaryWriter()): BinaryWriter { if (message.value.length !== 0) { writer.uint32(10).bytes(message.value); @@ -660,3 +660,12 @@ function longToNumber(int64: { toString(): string }): number { function isSet(value: any): boolean { return value !== null && value !== undefined; } + +export interface MessageFns { + encode(message: T, writer?: BinaryWriter): BinaryWriter; + decode(input: BinaryReader | Uint8Array, length?: number): T; + fromJSON(object: any): T; + toJSON(message: T): unknown; + create, I>>(base?: I): T; + fromPartial, I>>(object: I): T; +} diff --git a/src/main.ts b/src/main.ts index 0d76f5598..357ad7e44 100644 --- a/src/main.ts +++ b/src/main.ts @@ -61,6 +61,7 @@ import { getEnumMethod, getFieldOptionsJsType, isAnyValueType, + isAnyValueTypeName, isBytes, isBytesValueType, isEnum, @@ -68,6 +69,7 @@ import { isFieldMaskTypeName, isJsTypeFieldOption, isListValueType, + isListValueTypeName, isLong, isLongValueType, isMapType, @@ -78,6 +80,7 @@ import { isRepeated, isScalar, isStructType, + isStructTypeName, isTimestamp, isValueType, isWholeNumber, @@ -216,7 +219,8 @@ export function generateFile(ctx: Context, fileDesc: FileDescriptorProto): [stri const staticMembers: Code[] = []; - if (options.outputTypeAnnotations || options.outputTypeRegistry) { + const hasTypeMember = options.outputTypeAnnotations || options.outputTypeRegistry; + if (hasTypeMember) { staticMembers.push(code`$type: '${fullTypeName}' as const`); } @@ -281,8 +285,38 @@ export function generateFile(ctx: Context, fileDesc: FileDescriptorProto): [stri } if (staticMembers.length > 0) { + const messageFnsTypeParameters = [fullName, hasTypeMember && `'${fullTypeName}'`] + .filter((p) => !!p) + .join(", "); + + const interfaces: Code[] = [code`${utils.MessageFns}<${messageFnsTypeParameters}>`]; + if ( + options.outputEncodeMethods && + options.outputExtensions && + options.unknownFields && + message.extensionRange.length + ) { + interfaces.push(code`${utils.ExtensionFns}<${fullName}>`); + } + if (isStructTypeName(fullTypeName)) { + interfaces.push(code`${utils.StructWrapperFns}`); + } else if (isAnyValueTypeName(fullTypeName)) { + interfaces.push(code`${utils.AnyValueWrapperFns}`); + } else if (isListValueTypeName(fullTypeName)) { + interfaces.push(code`${utils.ListValueWrapperFns}`); + } else if (isFieldMaskTypeName(fullTypeName)) { + interfaces.push(code`${utils.FieldMaskWrapperFns}`); + } + if (options.outputExtensions) { + for (const extension of message.extension) { + const name = maybeSnakeToCamel(extension.name, ctx.options); + const type = toTypeName(ctx, message, extension); + interfaces.push(code`${utils.ExtensionHolder}<"${name}", ${type}>`); + } + } + chunks.push(code` - export const ${def(fullName)} = { + export const ${def(fullName)}: ${joinCode(interfaces, { on: " & " })} = { ${joinCode(staticMembers, { on: ",\n\n" })} }; `); @@ -431,23 +465,27 @@ export type Utils = ReturnType & ReturnType & ReturnType & ReturnType & - ReturnType; + ReturnType & + ReturnType; /** These are runtime utility methods used by the generated code. */ export function makeUtils(options: Options): Utils { const bytes = makeByteUtils(options); const longs = makeLongUtils(options, bytes); + const deepPartial = makeDeepPartial(options, longs); + const extension = makeExtensionClass(options); return { ...bytes, - ...makeDeepPartial(options, longs), + ...deepPartial, ...makeObjectIdMethods(), ...makeTimestampMethods(options, longs, bytes), ...longs, ...makeComparisonUtils(), ...makeNiceGrpcServerStreamingMethodResult(options), ...makeGrpcWebErrorClass(bytes), - ...makeExtensionClass(options), + ...extension, ...makeAssertionUtils(bytes), + ...makeMessageFns(options, deepPartial, extension), }; } @@ -665,6 +703,164 @@ function makeDeepPartial(options: Options, longs: ReturnType, + extension: ReturnType, +) { + const BinaryWriter = imp("BinaryWriter@@bufbuild/protobuf/wire"); + const BinaryReader = imp("BinaryReader@@bufbuild/protobuf/wire"); + const { Exact, DeepPartial } = deepPartial; + const { Extension } = extension; + const commonStaticMembers: Code[] = []; + const extensionStaticMembers = []; + + const hasTypeMember = options.outputTypeAnnotations || options.outputTypeRegistry; + if (hasTypeMember) { + commonStaticMembers.push(code`readonly $type: V;`); + } + + if (options.outputEncodeMethods) { + if ( + options.outputEncodeMethods === true || + options.outputEncodeMethods === "encode-only" || + options.outputEncodeMethods === "encode-no-creation" + ) { + commonStaticMembers.push(code` + encode(message: T, writer?: ${BinaryWriter}): ${BinaryWriter}; + `); + + if (options.outputExtensions && options.unknownFields) { + extensionStaticMembers.push(code` + setExtension(message: T, extension: ${Extension}, value: E): void; + `); + } + } + if (options.outputEncodeMethods === true || options.outputEncodeMethods === "decode-only") { + commonStaticMembers.push(code` + decode(input: ${BinaryReader} | Uint8Array, length?: number): T; + `); + if (options.outputExtensions && options.unknownFields) { + extensionStaticMembers.push(code` + getExtension(message: T, extension: ${Extension}): E | undefined; + `); + } + } + } + + if (options.useAsyncIterable) { + commonStaticMembers.push(code` + encodeTransform( + source: AsyncIterable | Iterable + ): AsyncIterable; + `); + commonStaticMembers.push(code` + decodeTransform( + source: AsyncIterable | Iterable + ): AsyncIterable; + `); + } + + if (options.outputJsonMethods) { + if (options.outputJsonMethods === true || options.outputJsonMethods === "from-only") { + commonStaticMembers.push(code`fromJSON(object: any): T;`); + } + if (options.outputJsonMethods === true || options.outputJsonMethods === "to-only") { + commonStaticMembers.push(code`toJSON(message: T): unknown;`); + } + } + + if (options.outputPartialMethods) { + if (options.useExactTypes) { + commonStaticMembers.push(code`create, I>>(base?: I): T;`); + commonStaticMembers.push(code`fromPartial, I>>(object: I): T;`); + } else { + commonStaticMembers.push(code`create(base?: DeepPartial): T;`); + commonStaticMembers.push(code`fromPartial(object: DeepPartial): T;`); + } + } + + const maybeExport = options.exportCommonSymbols ? "export" : ""; + const MessageFns = conditionalOutput( + "MessageFns", + code` + ${maybeExport} interface MessageFns { + ${joinCode(commonStaticMembers, { on: "\n" })} + } + `, + ); + + const ExtensionFns = conditionalOutput( + "ExtensionFns", + code` + ${maybeExport} interface ExtensionFns { + ${joinCode(extensionStaticMembers, { on: "\n" })} + } + `, + ); + + const ExtensionHolder = conditionalOutput( + "ExtensionHolder", + code` + ${maybeExport} type ExtensionHolder = { + [key in T]: Extension; + } + `, + ); + + const StructWrapperFns = conditionalOutput( + "StructWrapperFns", + code` + ${maybeExport} interface StructWrapperFns { + wrap(object: {[key: string]: any} | undefined): Struct; + unwrap(message: Struct): {[key: string]: any}; + } + `, + ); + + const AnyValueWrapperFns = conditionalOutput( + "AnyValueWrapperFns", + code` + ${maybeExport} interface AnyValueWrapperFns { + wrap(value: any): Value; + unwrap(message: any): string | number | boolean | Object | null | Array | undefined; + } + `, + ); + + const ListValueWrapperFns = conditionalOutput( + "ListValueWrapperFns", + code` + ${maybeExport} interface ListValueWrapperFns { + wrap(array: ${options.useReadonlyTypes ? "Readonly" : ""}Array | undefined): ListValue; + unwrap(message: ${options.useReadonlyTypes ? "any" : "ListValue"}): Array; + } + `, + ); + + const FieldMaskWrapperFns = conditionalOutput( + "FieldMaskWrapperFns", + code` + ${maybeExport} interface FieldMaskWrapperFns { + wrap(paths: ${options.useReadonlyTypes ? "readonly" : ""} string[]): FieldMask; + unwrap(message: ${options.useReadonlyTypes ? "any" : "FieldMask"}): string[] ${ + options.useOptionals === "all" ? "| undefined" : "" + }; + } + `, + ); + + return { + MessageFns, + ExtensionFns, + ExtensionHolder, + StructWrapperFns, + AnyValueWrapperFns, + ListValueWrapperFns, + FieldMaskWrapperFns, + }; +} + function makeObjectIdMethods() { const mongodb = imp("mongodb*mongodb");