@goplus123/core-api 1.0.4 → 1.0.5

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/dist/index.d.mts CHANGED
@@ -94,6 +94,7 @@ type GrpcInvokerUnaryArgs = {
94
94
  baseUrl: string;
95
95
  service: DescService;
96
96
  methodName: string;
97
+ method?: unknown;
97
98
  request: unknown;
98
99
  headers: Record<string, string>;
99
100
  callOptions?: CallOptions;
@@ -156,6 +157,7 @@ declare class GrpcClient {
156
157
  private hasHeader;
157
158
  private attachInvokerHeaders;
158
159
  private getInvokerClientKey;
160
+ private getServiceMethodDesc;
159
161
  private getServiceViaInvoker;
160
162
  private invokeUnary;
161
163
  /**
package/dist/index.d.ts CHANGED
@@ -94,6 +94,7 @@ type GrpcInvokerUnaryArgs = {
94
94
  baseUrl: string;
95
95
  service: DescService;
96
96
  methodName: string;
97
+ method?: unknown;
97
98
  request: unknown;
98
99
  headers: Record<string, string>;
99
100
  callOptions?: CallOptions;
@@ -156,6 +157,7 @@ declare class GrpcClient {
156
157
  private hasHeader;
157
158
  private attachInvokerHeaders;
158
159
  private getInvokerClientKey;
160
+ private getServiceMethodDesc;
159
161
  private getServiceViaInvoker;
160
162
  private invokeUnary;
161
163
  /**
package/dist/index.js CHANGED
@@ -148,13 +148,46 @@ var GrpcClient = class {
148
148
  getInvokerClientKey(service, baseUrl) {
149
149
  return `${String(service?.typeName ?? "")}@@${baseUrl}`;
150
150
  }
151
+ getServiceMethodDesc(service, methodName) {
152
+ const methods = service?.methods;
153
+ if (!methods) return void 0;
154
+ if (Array.isArray(methods)) {
155
+ for (const m of methods) {
156
+ if (!m) continue;
157
+ const localName = String(m.localName ?? "");
158
+ const name = String(m.name ?? "");
159
+ if (localName === methodName || name === methodName) return m;
160
+ }
161
+ return void 0;
162
+ }
163
+ if (typeof methods === "object") {
164
+ return methods[methodName];
165
+ }
166
+ return void 0;
167
+ }
151
168
  getServiceViaInvoker(service) {
152
169
  const baseUrl = this.pickBaseUrl(service.typeName ?? "");
153
170
  const key = this.getInvokerClientKey(service, baseUrl);
154
171
  const cached = this.invokerClientByKey.get(key);
155
172
  if (cached) return cached;
156
173
  const methods = service?.methods;
157
- const hasMethodsMap = methods && typeof methods === "object";
174
+ const hasMethods = methods != null;
175
+ const methodMap = (() => {
176
+ if (!methods) return void 0;
177
+ if (Array.isArray(methods)) {
178
+ const out = {};
179
+ for (const m of methods) {
180
+ if (!m) continue;
181
+ const localName = String(m.localName ?? "");
182
+ const name = String(m.name ?? "");
183
+ if (localName) out[localName] = m;
184
+ if (name && !(name in out)) out[name] = m;
185
+ }
186
+ return out;
187
+ }
188
+ if (typeof methods === "object") return methods;
189
+ return void 0;
190
+ })();
158
191
  const typeName = String(service?.typeName ?? "");
159
192
  const client = new Proxy(
160
193
  {},
@@ -162,7 +195,7 @@ var GrpcClient = class {
162
195
  get: (_target, prop) => {
163
196
  if (prop === "then") return void 0;
164
197
  if (typeof prop !== "string") return void 0;
165
- if (hasMethodsMap && !(prop in methods)) {
198
+ if (hasMethods && methodMap && !(prop in methodMap)) {
166
199
  return async () => {
167
200
  throw new Error(`gRPC method not found: ${typeName}.${prop}`);
168
201
  };
@@ -181,6 +214,7 @@ var GrpcClient = class {
181
214
  const baseUrl = this.pickBaseUrl(typeName);
182
215
  try {
183
216
  if (this.invoker) {
217
+ const method2 = this.getServiceMethodDesc(service, methodName);
184
218
  const headers = await this.attachInvokerHeaders(
185
219
  this.normalizeHeaders(options?.headers),
186
220
  methodName
@@ -195,6 +229,7 @@ var GrpcClient = class {
195
229
  baseUrl,
196
230
  service,
197
231
  methodName,
232
+ method: method2,
198
233
  request,
199
234
  headers,
200
235
  callOptions: options