@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.cjs +35 -29
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.mts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +35 -29
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -186,20 +186,43 @@ var GrpcClient = class {
|
|
|
186
186
|
getInvokerClientKey(service, baseUrl) {
|
|
187
187
|
return `${String(service?.typeName ?? "")}@@${baseUrl}`;
|
|
188
188
|
}
|
|
189
|
-
|
|
189
|
+
getServiceMethodMap(service) {
|
|
190
|
+
const out = {};
|
|
191
|
+
const addMethod = (m) => {
|
|
192
|
+
if (!m) return;
|
|
193
|
+
const localName = m.localName != null ? String(m.localName) : "";
|
|
194
|
+
const name = m.name != null ? String(m.name) : "";
|
|
195
|
+
if (localName) out[localName] = m;
|
|
196
|
+
if (name && !(name in out)) out[name] = m;
|
|
197
|
+
};
|
|
198
|
+
const direct = service?.method;
|
|
199
|
+
if (direct && typeof direct === "object") {
|
|
200
|
+
for (const [k, v] of Object.entries(direct)) {
|
|
201
|
+
if (v) out[k] = v;
|
|
202
|
+
addMethod(v);
|
|
203
|
+
}
|
|
204
|
+
}
|
|
190
205
|
const methods = service?.methods;
|
|
191
|
-
if (!methods) return void 0;
|
|
192
206
|
if (Array.isArray(methods)) {
|
|
193
|
-
for (const m of methods)
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
207
|
+
for (const m of methods) addMethod(m);
|
|
208
|
+
} else if (methods && typeof methods === "object") {
|
|
209
|
+
for (const [k, v] of Object.entries(methods)) {
|
|
210
|
+
if (v) out[k] = v;
|
|
211
|
+
addMethod(v);
|
|
198
212
|
}
|
|
199
|
-
return void 0;
|
|
200
213
|
}
|
|
201
|
-
|
|
202
|
-
|
|
214
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
215
|
+
}
|
|
216
|
+
getServiceMethodDesc(service, methodName) {
|
|
217
|
+
const methodMap = this.getServiceMethodMap(service);
|
|
218
|
+
if (!methodMap) return void 0;
|
|
219
|
+
const direct = methodMap[methodName];
|
|
220
|
+
if (direct) return direct;
|
|
221
|
+
for (const m of Object.values(methodMap)) {
|
|
222
|
+
if (!m) continue;
|
|
223
|
+
const localName = m.localName != null ? String(m.localName) : "";
|
|
224
|
+
const name = m.name != null ? String(m.name) : "";
|
|
225
|
+
if (localName === methodName || name === methodName) return m;
|
|
203
226
|
}
|
|
204
227
|
return void 0;
|
|
205
228
|
}
|
|
@@ -208,24 +231,7 @@ var GrpcClient = class {
|
|
|
208
231
|
const key = this.getInvokerClientKey(service, baseUrl);
|
|
209
232
|
const cached = this.invokerClientByKey.get(key);
|
|
210
233
|
if (cached) return cached;
|
|
211
|
-
const
|
|
212
|
-
const hasMethods = methods != null;
|
|
213
|
-
const methodMap = (() => {
|
|
214
|
-
if (!methods) return void 0;
|
|
215
|
-
if (Array.isArray(methods)) {
|
|
216
|
-
const out = {};
|
|
217
|
-
for (const m of methods) {
|
|
218
|
-
if (!m) continue;
|
|
219
|
-
const localName = String(m.localName ?? "");
|
|
220
|
-
const name = String(m.name ?? "");
|
|
221
|
-
if (localName) out[localName] = m;
|
|
222
|
-
if (name && !(name in out)) out[name] = m;
|
|
223
|
-
}
|
|
224
|
-
return out;
|
|
225
|
-
}
|
|
226
|
-
if (typeof methods === "object") return methods;
|
|
227
|
-
return void 0;
|
|
228
|
-
})();
|
|
234
|
+
const methodMap = this.getServiceMethodMap(service);
|
|
229
235
|
const typeName = String(service?.typeName ?? "");
|
|
230
236
|
const client = new Proxy(
|
|
231
237
|
{},
|
|
@@ -233,7 +239,7 @@ var GrpcClient = class {
|
|
|
233
239
|
get: (_target, prop) => {
|
|
234
240
|
if (prop === "then") return void 0;
|
|
235
241
|
if (typeof prop !== "string") return void 0;
|
|
236
|
-
if (
|
|
242
|
+
if (methodMap && !(prop in methodMap)) {
|
|
237
243
|
return async () => {
|
|
238
244
|
throw new Error(`gRPC method not found: ${typeName}.${prop}`);
|
|
239
245
|
};
|