-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
179 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
// GENERATED CODE -- DO NOT EDIT! | ||
/* eslint-disable @typescript-eslint/no-non-null-assertion */ | ||
|
||
import * as protobufjs from 'protobufjs/light' | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-namespace | ||
export namespace Regressions { | ||
interface ConvertibleTo<T> { | ||
asInterface(): T | ||
} | ||
|
||
export interface IReg01Inner { | ||
value?: string | ||
} | ||
|
||
export interface IReg01Outer { | ||
inner?: IReg01Inner | ||
} | ||
|
||
@protobufjs.Type.d('regressions_Reg01Inner') | ||
export class Reg01Inner | ||
extends protobufjs.Message<Reg01Inner> | ||
implements ConvertibleTo<IReg01Inner>, IReg01Inner | ||
{ | ||
@protobufjs.Field.d(1, 'string', 'optional') | ||
public value?: string | ||
|
||
public asInterface(): IReg01Inner { | ||
const message = { | ||
...this, | ||
} | ||
for (const fieldName of Object.keys(message)) { | ||
if (message[fieldName as keyof IReg01Inner] == null) { | ||
// We remove the key to avoid problems with code making too many assumptions | ||
delete message[fieldName as keyof IReg01Inner] | ||
} | ||
} | ||
return message | ||
} | ||
|
||
public static fromInterface(this: void, value: IReg01Inner): Reg01Inner { | ||
return Reg01Inner.fromObject(value) | ||
} | ||
|
||
public static decodePatched( | ||
this: void, | ||
reader: protobufjs.Reader | Uint8Array | ||
): IReg01Inner { | ||
return Reg01Inner.decode(reader).asInterface() | ||
} | ||
|
||
public static encodePatched( | ||
this: void, | ||
message: IReg01Inner, | ||
writer?: protobufjs.Writer | ||
): protobufjs.Writer { | ||
return Reg01Inner.encode(message, writer) | ||
} | ||
} | ||
|
||
@protobufjs.Type.d('regressions_Reg01Outer') | ||
export class Reg01Outer | ||
extends protobufjs.Message<Reg01Outer> | ||
implements ConvertibleTo<IReg01Outer>, IReg01Outer | ||
{ | ||
@protobufjs.Field.d(1, Reg01Inner, 'optional') | ||
public inner?: Reg01Inner | ||
|
||
public asInterface(): IReg01Outer { | ||
const message = { | ||
...this, | ||
inner: this.inner?.asInterface(), | ||
} | ||
for (const fieldName of Object.keys(message)) { | ||
if (message[fieldName as keyof IReg01Outer] == null) { | ||
// We remove the key to avoid problems with code making too many assumptions | ||
delete message[fieldName as keyof IReg01Outer] | ||
} | ||
} | ||
return message | ||
} | ||
|
||
public static fromInterface(this: void, value: IReg01Outer): Reg01Outer { | ||
return Reg01Outer.fromObject(value) | ||
} | ||
|
||
public static decodePatched( | ||
this: void, | ||
reader: protobufjs.Reader | Uint8Array | ||
): IReg01Outer { | ||
return Reg01Outer.decode(reader).asInterface() | ||
} | ||
|
||
public static encodePatched( | ||
this: void, | ||
message: IReg01Outer, | ||
writer?: protobufjs.Writer | ||
): protobufjs.Writer { | ||
return Reg01Outer.encode(message, writer) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
syntax = "proto3"; | ||
|
||
package regressions; | ||
|
||
// Makes protoc happy (useful for Golang code generation, not for TS) | ||
option go_package = "github.com/join-com/protoc-gen-ts/regressions"; | ||
|
||
|
||
// Regression 01 | ||
|
||
message Reg01Inner { | ||
string value = 1; | ||
} | ||
|
||
message Reg01Outer { | ||
Reg01Inner inner = 1; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Regressions } from './generated/Regressions' | ||
|
||
describe('regressions', () => { | ||
it('decodes missing nested fields as undefined when there are no enums', () => { | ||
// Background: before this test was written, calling .asInterface() for nested objects was | ||
// done only when there were enum fields at some level of the object. | ||
|
||
const originalA: Regressions.IReg01Outer = {} | ||
const bufferA = Regressions.Reg01Outer.encodePatched(originalA).finish() | ||
const reconstructedA = Regressions.Reg01Outer.decodePatched(bufferA) | ||
|
||
const originalB: Regressions.IReg01Outer = { inner: {} } | ||
const bufferB = Regressions.Reg01Outer.encodePatched(originalB).finish() | ||
const reconstructedB = Regressions.Reg01Outer.decodePatched(bufferB) | ||
|
||
expect(reconstructedA.inner?.value).toBeUndefined() | ||
expect(reconstructedB.inner?.value).toBeUndefined() | ||
}) | ||
}) |