starpc 0.10.9 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/srpc/handler.ts CHANGED
@@ -145,7 +145,16 @@ export function createInvokeFn<R, O>(
145
145
  }
146
146
 
147
147
  // createHandler creates a handler from a definition and an implementation.
148
- export function createHandler(definition: Definition, impl: any): Handler {
148
+ // if serviceID is not set, uses the fullName of the service as the identifier.
149
+ export function createHandler(
150
+ definition: Definition,
151
+ impl: any,
152
+ serviceID?: string
153
+ ): Handler {
154
+ // serviceID defaults to the full name of the service from Protobuf.
155
+ serviceID = serviceID || definition.fullName
156
+
157
+ // build map of method ID -> method prototype.
149
158
  const methodMap: MethodMap = {}
150
159
  for (const methodInfo of Object.values(definition.methods)) {
151
160
  const methodName = methodInfo.name
@@ -157,5 +166,5 @@ export function createHandler(definition: Definition, impl: any): Handler {
157
166
  methodMap[methodName] = createInvokeFn(methodInfo, methodProto)
158
167
  }
159
168
 
160
- return new StaticHandler(definition.fullName, methodMap)
169
+ return new StaticHandler(serviceID, methodMap)
161
170
  }