@goplus123/core-api 1.0.5 → 1.0.6

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
@@ -157,6 +157,7 @@ declare class GrpcClient {
157
157
  private hasHeader;
158
158
  private attachInvokerHeaders;
159
159
  private getInvokerClientKey;
160
+ private getServiceMethodMap;
160
161
  private getServiceMethodDesc;
161
162
  private getServiceViaInvoker;
162
163
  private invokeUnary;
package/dist/index.d.ts CHANGED
@@ -157,6 +157,7 @@ declare class GrpcClient {
157
157
  private hasHeader;
158
158
  private attachInvokerHeaders;
159
159
  private getInvokerClientKey;
160
+ private getServiceMethodMap;
160
161
  private getServiceMethodDesc;
161
162
  private getServiceViaInvoker;
162
163
  private invokeUnary;
package/dist/index.js CHANGED
@@ -148,20 +148,43 @@ var GrpcClient = class {
148
148
  getInvokerClientKey(service, baseUrl) {
149
149
  return `${String(service?.typeName ?? "")}@@${baseUrl}`;
150
150
  }
151
- getServiceMethodDesc(service, methodName) {
151
+ getServiceMethodMap(service) {
152
+ const out = {};
153
+ const addMethod = (m) => {
154
+ if (!m) return;
155
+ const localName = m.localName != null ? String(m.localName) : "";
156
+ const name = m.name != null ? String(m.name) : "";
157
+ if (localName) out[localName] = m;
158
+ if (name && !(name in out)) out[name] = m;
159
+ };
160
+ const direct = service?.method;
161
+ if (direct && typeof direct === "object") {
162
+ for (const [k, v] of Object.entries(direct)) {
163
+ if (v) out[k] = v;
164
+ addMethod(v);
165
+ }
166
+ }
152
167
  const methods = service?.methods;
153
- if (!methods) return void 0;
154
168
  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;
169
+ for (const m of methods) addMethod(m);
170
+ } else if (methods && typeof methods === "object") {
171
+ for (const [k, v] of Object.entries(methods)) {
172
+ if (v) out[k] = v;
173
+ addMethod(v);
160
174
  }
161
- return void 0;
162
175
  }
163
- if (typeof methods === "object") {
164
- return methods[methodName];
176
+ return Object.keys(out).length > 0 ? out : void 0;
177
+ }
178
+ getServiceMethodDesc(service, methodName) {
179
+ const methodMap = this.getServiceMethodMap(service);
180
+ if (!methodMap) return void 0;
181
+ const direct = methodMap[methodName];
182
+ if (direct) return direct;
183
+ for (const m of Object.values(methodMap)) {
184
+ if (!m) continue;
185
+ const localName = m.localName != null ? String(m.localName) : "";
186
+ const name = m.name != null ? String(m.name) : "";
187
+ if (localName === methodName || name === methodName) return m;
165
188
  }
166
189
  return void 0;
167
190
  }
@@ -170,24 +193,7 @@ var GrpcClient = class {
170
193
  const key = this.getInvokerClientKey(service, baseUrl);
171
194
  const cached = this.invokerClientByKey.get(key);
172
195
  if (cached) return cached;
173
- const methods = service?.methods;
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
- })();
196
+ const methodMap = this.getServiceMethodMap(service);
191
197
  const typeName = String(service?.typeName ?? "");
192
198
  const client = new Proxy(
193
199
  {},
@@ -195,7 +201,7 @@ var GrpcClient = class {
195
201
  get: (_target, prop) => {
196
202
  if (prop === "then") return void 0;
197
203
  if (typeof prop !== "string") return void 0;
198
- if (hasMethods && methodMap && !(prop in methodMap)) {
204
+ if (methodMap && !(prop in methodMap)) {
199
205
  return async () => {
200
206
  throw new Error(`gRPC method not found: ${typeName}.${prop}`);
201
207
  };