@pbkit/runtime
Advanced tools
Comparing version 0.0.33 to 0.0.34
export declare function fromSingle<T>(value: T): AsyncGenerator<T>; | ||
export declare function first<T>(generator: AsyncGenerator<T>): Promise<T>; | ||
export declare function map<T>(asyncGenerator: AsyncGenerator<T>, fn: (value: T) => T | Promise<T>): AsyncGenerator<T>; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.map = exports.first = exports.fromSingle = void 0; | ||
exports.first = exports.fromSingle = void 0; | ||
async function* fromSingle(value) { | ||
@@ -15,6 +15,1 @@ yield value; | ||
exports.first = first; | ||
async function* map(asyncGenerator, fn) { | ||
for await (const value of asyncGenerator) | ||
yield await fn(value); | ||
} | ||
exports.map = map; |
@@ -30,2 +30,7 @@ import type { RpcClientImpl } from "./rpc"; | ||
}; | ||
"request-error": { | ||
configId: string; | ||
requestId: number; | ||
errorMessage: string; | ||
}; | ||
"response": { | ||
@@ -42,2 +47,7 @@ configId: string; | ||
}; | ||
"response-error": { | ||
configId: string; | ||
requestId: number; | ||
errorMessage: string; | ||
}; | ||
"response-trailer": { | ||
@@ -44,0 +54,0 @@ configId: string; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.wrapRpcClientImpl = exports.getDevtoolsConfig = exports.devtoolsKey = void 0; | ||
const async_generator_1 = require("./async/async-generator"); | ||
const event_emitter_1 = require("./async/event-emitter"); | ||
@@ -43,4 +42,4 @@ exports.devtoolsKey = "@pbkit/devtools"; | ||
devtoolsConfig.emit("request", { | ||
configId, | ||
requestId, | ||
configId, | ||
servicePath: methodDescriptor.service.serviceName, | ||
@@ -51,24 +50,36 @@ rpcName: methodDescriptor.methodName, | ||
}); | ||
const rpcMethodResult = rpcMethodImpl((0, async_generator_1.map)(req, (payload) => { | ||
const rpcMethodResult = rpcMethodImpl(mapAsyncGenerator(req, (payload) => { | ||
devtoolsConfig.emit("request-payload", { | ||
configId, | ||
requestId, | ||
configId, | ||
payloadJson: toJson(payload), | ||
payloadJson: methodDescriptor.requestType.serializeJson(payload), | ||
payloadProto: methodDescriptor.requestType.serializeBinary(payload), | ||
}); | ||
return payload; | ||
}, (error) => { | ||
devtoolsConfig.emit("request-error", { | ||
configId, | ||
requestId, | ||
errorMessage: getErrorMessage(error), | ||
}); | ||
}), metadata); | ||
const resAsyncGenerator = (0, async_generator_1.map)(rpcMethodResult[0], (payload) => { | ||
const resAsyncGenerator = mapAsyncGenerator(rpcMethodResult[0], (payload) => { | ||
devtoolsConfig.emit("response-payload", { | ||
configId, | ||
requestId, | ||
configId, | ||
payloadJson: toJson(payload), | ||
payloadJson: methodDescriptor.responseType.serializeJson(payload), | ||
payloadProto: methodDescriptor.responseType.serializeBinary(payload), | ||
}); | ||
return payload; | ||
}, (error) => { | ||
devtoolsConfig.emit("response-error", { | ||
configId, | ||
requestId, | ||
errorMessage: getErrorMessage(error), | ||
}); | ||
}); | ||
const headerPromise = rpcMethodResult[1].then((header) => { | ||
devtoolsConfig.emit("response", { | ||
configId, | ||
requestId, | ||
configId, | ||
headerJson: toJson(header), | ||
@@ -80,4 +91,4 @@ }); | ||
devtoolsConfig.emit("response-trailer", { | ||
configId, | ||
requestId, | ||
configId, | ||
trailerJson: toJson(trailer), | ||
@@ -97,1 +108,17 @@ }); | ||
} | ||
async function* mapAsyncGenerator(asyncGenerator, fn, catchFn) { | ||
try { | ||
for await (const value of asyncGenerator) { | ||
yield await fn(value); | ||
} | ||
} | ||
catch (error) { | ||
catchFn(error); | ||
throw error; | ||
} | ||
} | ||
function getErrorMessage(error) { | ||
if (error instanceof Error) | ||
return error.stack || error.message; | ||
return String(error); | ||
} |
{ | ||
"name": "@pbkit/runtime", | ||
"version": "0.0.33", | ||
"version": "0.0.34", | ||
"author": "JongChan Choi <jong@chan.moe>", | ||
@@ -5,0 +5,0 @@ "license": "(MIT OR Apache-2.0)", |
@@ -16,2 +16,3 @@ export declare type Method<TMetadata = any, THeader = any, TTrailer = any, TServiceName extends string = string, TMethodName extends string = string, TRequestStream extends boolean = boolean, TResponseStream extends boolean = boolean, TReq = any, TRes = any> = [ | ||
deserializeBinary: (value: Uint8Array) => TReq; | ||
serializeJson: (value: TReq) => string; | ||
}; | ||
@@ -21,2 +22,3 @@ responseType: { | ||
deserializeBinary: (value: Uint8Array) => TRes; | ||
serializeJson: (value: TRes) => string; | ||
}; | ||
@@ -23,0 +25,0 @@ } |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
50580
1437
0