request-is-better
Advanced tools
Comparing version 1.0.0 to 1.0.1
@@ -56,3 +56,3 @@ "use strict"; | ||
return { | ||
request, | ||
request: request, | ||
onReceive: onReceive | ||
@@ -59,0 +59,0 @@ }; |
@@ -6,6 +6,7 @@ export interface MessageToReqResInput { | ||
} | ||
export declare function messagingToRequestResponse(opts: MessageToReqResInput): { | ||
request: (m: unknown) => Promise<unknown> | unknown; | ||
export declare type RequestFunc<TReq = unknown, TRes = unknown> = (m: TReq) => Promise<TRes> | TRes; | ||
export declare function messagingToRequestResponse<TReq = unknown, TRes = unknown>(opts: MessageToReqResInput): { | ||
request: RequestFunc<TReq, TRes>; | ||
onReceive: (m: unknown) => void; | ||
}; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -49,5 +49,5 @@ "use strict"; | ||
} | ||
return { request, onReceive: onReceive }; | ||
return { request: request, onReceive: onReceive }; | ||
} | ||
exports.messagingToRequestResponse = messagingToRequestResponse; | ||
//# sourceMappingURL=index.js.map |
@@ -6,6 +6,7 @@ export interface MessageToReqResInput { | ||
} | ||
export declare function messagingToRequestResponse(opts: MessageToReqResInput): { | ||
request: (m: unknown) => Promise<unknown> | unknown; | ||
export type RequestFunc<TReq = unknown, TRes = unknown> = (m: TReq) => Promise<TRes> | TRes; | ||
export declare function messagingToRequestResponse<TReq = unknown, TRes = unknown>(opts: MessageToReqResInput): { | ||
request: RequestFunc<TReq, TRes>; | ||
onReceive: (m: unknown) => void; | ||
}; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "request-is-better", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "request-is-better is a TypeScript library which makes it easier to use request-response calls on any channel that implements a send-receive message interface.", | ||
@@ -5,0 +5,0 @@ "isApp": false, |
# request-is-better | ||
**Request-is-better** is a TypeScript library which makes it easier to use **request-response** calls on any channel that implements a send-receive message interface. | ||
Like the lib? Support it with a star! | ||
@@ -85,3 +86,5 @@ ## Features | ||
Like the lib? Support it with a star! | ||
# License | ||
The Unlicense |
@@ -11,6 +11,8 @@ // PackageName: request-is-better | ||
export function messagingToRequestResponse(opts: MessageToReqResInput) { | ||
export type RequestFunc<TReq = unknown, TRes = unknown> = (m: TReq) => Promise<TRes> | TRes; | ||
export function messagingToRequestResponse<TReq = unknown, TRes = unknown>(opts: MessageToReqResInput) { | ||
let lastRequestId = 0; | ||
const requests: { [key: number]: RequestContext } = {}; | ||
function request(m: unknown): Promise<unknown> | unknown { | ||
function request(m: any): Promise<any> | any { | ||
lastRequestId = ++lastRequestId < Number.MAX_SAFE_INTEGER - 1 ? lastRequestId : 1; | ||
@@ -54,3 +56,3 @@ const requestId = lastRequestId; | ||
} | ||
return { request, onReceive: onReceive as (m: unknown) => void }; | ||
return { request: request as RequestFunc<TReq, TRes>, onReceive: onReceive as (m: unknown) => void }; | ||
} | ||
@@ -57,0 +59,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
257817
126
3054
90