-
Notifications
You must be signed in to change notification settings - Fork 349
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* fix: Struct wrap/unwrap snake case #579 * test: Add more tests about struct snake case * style: format src/main.ts Co-authored-by: TJT <tjt@maimemo.com>
- Loading branch information
Showing
11 changed files
with
1,234 additions
and
40 deletions.
There are no files selected for viewing
515 changes: 515 additions & 0 deletions
515
integration/oneof-unions-snake/google/protobuf/struct.ts
Large diffs are not rendered by default.
Oops, something went wrong.
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 @@ | ||
snakeToCamel=false,oneof=unions |
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,12 @@ | ||
import { SimpleStruct } from './simple'; | ||
|
||
describe('oneof=unions,snakeToCamel=false', () => { | ||
it('struct snake case', () => { | ||
const simple: SimpleStruct = { | ||
simple_struct: { | ||
any: 'any' | ||
} | ||
} | ||
expect(simple.simple_struct!['any']).toEqual('any') | ||
}) | ||
}); |
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,9 @@ | ||
// Adding a comment to the syntax will become the first | ||
// comment in the output source file. | ||
syntax = "proto3"; | ||
import "google/protobuf/struct.proto"; | ||
package simple; | ||
|
||
message SimpleStruct { | ||
google.protobuf.Struct simple_struct = 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,94 @@ | ||
/* eslint-disable */ | ||
import * as Long from 'long'; | ||
import * as _m0 from 'protobufjs/minimal'; | ||
import { Struct } from './google/protobuf/struct'; | ||
|
||
export const protobufPackage = 'simple'; | ||
|
||
/** | ||
* Adding a comment to the syntax will become the first | ||
* comment in the output source file. | ||
*/ | ||
|
||
export interface SimpleStruct { | ||
simple_struct: { [key: string]: any } | undefined; | ||
} | ||
|
||
function createBaseSimpleStruct(): SimpleStruct { | ||
return { simple_struct: undefined }; | ||
} | ||
|
||
export const SimpleStruct = { | ||
encode(message: SimpleStruct, writer: _m0.Writer = _m0.Writer.create()): _m0.Writer { | ||
if (message.simple_struct !== undefined) { | ||
Struct.encode(Struct.wrap(message.simple_struct), writer.uint32(10).fork()).ldelim(); | ||
} | ||
return writer; | ||
}, | ||
|
||
decode(input: _m0.Reader | Uint8Array, length?: number): SimpleStruct { | ||
const reader = input instanceof _m0.Reader ? input : new _m0.Reader(input); | ||
let end = length === undefined ? reader.len : reader.pos + length; | ||
const message = createBaseSimpleStruct(); | ||
while (reader.pos < end) { | ||
const tag = reader.uint32(); | ||
switch (tag >>> 3) { | ||
case 1: | ||
message.simple_struct = Struct.unwrap(Struct.decode(reader, reader.uint32())); | ||
break; | ||
default: | ||
reader.skipType(tag & 7); | ||
break; | ||
} | ||
} | ||
return message; | ||
}, | ||
|
||
fromJSON(object: any): SimpleStruct { | ||
return { | ||
simple_struct: isObject(object.simple_struct) ? object.simple_struct : undefined, | ||
}; | ||
}, | ||
|
||
toJSON(message: SimpleStruct): unknown { | ||
const obj: any = {}; | ||
message.simple_struct !== undefined && (obj.simple_struct = message.simple_struct); | ||
return obj; | ||
}, | ||
|
||
fromPartial<I extends Exact<DeepPartial<SimpleStruct>, I>>(object: I): SimpleStruct { | ||
const message = createBaseSimpleStruct(); | ||
message.simple_struct = object.simple_struct ?? undefined; | ||
return message; | ||
}, | ||
}; | ||
|
||
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined; | ||
|
||
export type DeepPartial<T> = T extends Builtin | ||
? T | ||
: T extends Array<infer U> | ||
? Array<DeepPartial<U>> | ||
: T extends ReadonlyArray<infer U> | ||
? ReadonlyArray<DeepPartial<U>> | ||
: T extends { $case: string } | ||
? { [K in keyof Omit<T, '$case'>]?: DeepPartial<T[K]> } & { $case: T['$case'] } | ||
: T extends {} | ||
? { [K in keyof T]?: DeepPartial<T[K]> } | ||
: Partial<T>; | ||
|
||
type KeysOfUnion<T> = T extends T ? keyof T : never; | ||
export type Exact<P, I extends P> = P extends Builtin | ||
? P | ||
: P & { [K in keyof P]: Exact<P[K], I[K]> } & Record<Exclude<keyof I, KeysOfUnion<P>>, never>; | ||
|
||
// If you get a compile-error about 'Constructor<Long> and ... have no overlap', | ||
// add '--ts_proto_opt=esModuleInterop=true' as a flag when calling 'protoc'. | ||
if (_m0.util.Long !== Long) { | ||
_m0.util.Long = Long as any; | ||
_m0.configure(); | ||
} | ||
|
||
function isObject(value: any): boolean { | ||
return typeof value === 'object' && value !== null; | ||
} |
Oops, something went wrong.