Skip to content

Commit

Permalink
adjust implementation to always return default options
Browse files Browse the repository at this point in the history
  • Loading branch information
n0v1 committed Apr 5, 2024
1 parent 99e8a06 commit 27d6087
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
11 changes: 7 additions & 4 deletions packages/proto-loader/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,10 +249,13 @@ function createSerializer(cls: Protobuf.Type): Serialize<object> {
};
}

function mapMethodOptions(options: Partial<MethodOptions>[] | undefined): MethodOptions | undefined {
return Array.isArray(options) ?
options.reduce((obj: MethodOptions, item: Partial<MethodOptions>) => ({ ...obj, ...item }), {}) :
undefined;
function mapMethodOptions(options: Partial<MethodOptions>[] | undefined): MethodOptions {
return (options || []).reduce((obj: MethodOptions, item: Partial<MethodOptions>) => ({ ...obj, ...item }),
{
deprecated: false,
idempotency_level: IdempotencyLevel.IDEMPOTENCY_UNKNOWN,
uninterpreted_option: []
});
}

function createMethodDefinition(
Expand Down
6 changes: 5 additions & 1 deletion packages/proto-loader/test/descriptor_type_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,10 @@ describe('Descriptor types', () => {
},
'(google.api.method_signature)': 'bar'
})
assert(service.HelloWithoutOptions.options === undefined)
assert.deepStrictEqual(service.HelloWithoutOptions.options, {
deprecated: false,
idempotency_level: 'IDEMPOTENCY_UNKNOWN',
uninterpreted_option: []
})
})
});

0 comments on commit 27d6087

Please sign in to comment.