@dxos/codec-protobuf
Advanced tools
Comparing version 2.25.1-dev.0ff9b5c9 to 2.25.1-dev.3e7251f9
@@ -12,3 +12,2 @@ "use strict"; | ||
// Will set empty repeated fields to [] instead of undefined. | ||
// TODO(marik-d): Type repeated fields as non-optional arrays. | ||
arrays: true | ||
@@ -15,0 +14,0 @@ }; |
@@ -38,4 +38,5 @@ "use strict"; | ||
const responseCodec = schema.tryGetCodecForType(method.resolvedResponseType.fullName); | ||
const methodName = mapRpcMethodName(method.name); | ||
if (!method.responseStream) { | ||
this[method.name] = async (request) => { | ||
this[methodName] = async (request) => { | ||
const encoded = requestCodec.encode(request); | ||
@@ -50,3 +51,3 @@ const response = await backend.call(method.name, { | ||
else { | ||
this[method.name] = (request) => { | ||
this[methodName] = (request) => { | ||
const encoded = requestCodec.encode(request); | ||
@@ -64,3 +65,3 @@ return new stream_1.Stream(({ next, close }) => { | ||
// Set function name so that is properly named in stack traces. | ||
Object.defineProperty(this[method.name], 'name', { value: method.name }); | ||
Object.defineProperty(this[methodName], 'name', { value: methodName }); | ||
} | ||
@@ -80,5 +81,6 @@ } | ||
(0, assert_1.default)(!method.responseStream, `Invalid RPC method call: response streaming mismatch. ${methodName}`); | ||
const mappedMethodName = mapRpcMethodName(methodName); | ||
const handler = this._handlers[mappedMethodName]; | ||
(0, assert_1.default)(handler, `Handler is missing: ${mappedMethodName}`); | ||
const requestDecoded = requestCodec.decode(request.value); | ||
const handler = this._handlers[methodName]; | ||
(0, assert_1.default)(handler, `Handler is missing: ${methodName}`); | ||
const response = await handler.bind(this._handlers)(requestDecoded); | ||
@@ -95,5 +97,6 @@ const responseEncoded = responseCodec.encode(response); | ||
(0, assert_1.default)(method.responseStream, `Invalid RPC method call: response streaming mismatch., ${methodName}`); | ||
const mappedMethodName = mapRpcMethodName(methodName); | ||
const handler = this._handlers[mappedMethodName]; | ||
(0, assert_1.default)(handler, `Handler is missing: ${mappedMethodName}`); | ||
const requestDecoded = requestCodec.decode(request.value); | ||
const handler = this._handlers[methodName]; | ||
(0, assert_1.default)(handler, `Handler is missing: ${methodName}`); | ||
const responseStream = handler.bind(this._handlers)(requestDecoded); | ||
@@ -120,2 +123,5 @@ return new stream_1.Stream(({ next, close }) => { | ||
exports.ServiceHandler = ServiceHandler; | ||
function mapRpcMethodName(name) { | ||
return name[0].toLocaleLowerCase() + name.substring(1); | ||
} | ||
//# sourceMappingURL=service.js.map |
{ | ||
"name": "@dxos/codec-protobuf", | ||
"version": "2.25.1-dev.0ff9b5c9", | ||
"version": "2.25.1-dev.3e7251f9", | ||
"license": "AGPL-3.0", | ||
@@ -5,0 +5,0 @@ "author": "DXOS.org", |
@@ -16,3 +16,2 @@ // | ||
// Will set empty repeated fields to [] instead of undefined. | ||
// TODO(marik-d): Type repeated fields as non-optional arrays. | ||
arrays: true | ||
@@ -19,0 +18,0 @@ }; |
@@ -55,5 +55,6 @@ // | ||
const responseCodec = schema.tryGetCodecForType(method.resolvedResponseType.fullName); | ||
const methodName = mapRpcMethodName(method.name); | ||
if (!method.responseStream) { | ||
(this as any)[method.name] = async (request: unknown) => { | ||
(this as any)[methodName] = async (request: unknown) => { | ||
const encoded = requestCodec.encode(request); | ||
@@ -67,3 +68,3 @@ const response = await backend.call(method.name, { | ||
} else { | ||
(this as any)[method.name] = (request: unknown) => { | ||
(this as any)[methodName] = (request: unknown) => { | ||
const encoded = requestCodec.encode(request); | ||
@@ -83,3 +84,3 @@ return new Stream(({ next, close }) => { | ||
// Set function name so that is properly named in stack traces. | ||
Object.defineProperty((this as any)[method.name], 'name', { value: method.name }); | ||
Object.defineProperty((this as any)[methodName], 'name', { value: methodName }); | ||
} | ||
@@ -101,9 +102,9 @@ } | ||
const requestDecoded = requestCodec.decode(request.value!); | ||
const mappedMethodName = mapRpcMethodName(methodName); | ||
const handler = this._handlers[methodName as keyof S]; | ||
assert(handler, `Handler is missing: ${methodName}`); | ||
const handler = this._handlers[mappedMethodName as keyof S]; | ||
assert(handler, `Handler is missing: ${mappedMethodName}`); | ||
const requestDecoded = requestCodec.decode(request.value!); | ||
const response = await (handler as any).bind(this._handlers)(requestDecoded); | ||
const responseEncoded = responseCodec.encode(response); | ||
@@ -122,7 +123,8 @@ | ||
const requestDecoded = requestCodec.decode(request.value!); | ||
const mappedMethodName = mapRpcMethodName(methodName); | ||
const handler = this._handlers[methodName as keyof S]; | ||
assert(handler, `Handler is missing: ${methodName}`); | ||
const handler = this._handlers[mappedMethodName as keyof S]; | ||
assert(handler, `Handler is missing: ${mappedMethodName}`); | ||
const requestDecoded = requestCodec.decode(request.value!); | ||
const responseStream = (handler as any).bind(this._handlers)(requestDecoded) as Stream<unknown>; | ||
@@ -152,1 +154,5 @@ return new Stream<Any>(({ next, close }) => { | ||
} | ||
function mapRpcMethodName (name: string) { | ||
return name[0].toLocaleLowerCase() + name.substring(1); | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
104357
1393