-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
16 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ import { | |
} from "https://deno.land/x/[email protected]/core/runtime/async/event-emitter.ts"; | ||
import { useEffect, useRef } from "react"; | ||
import { WrpChannel } from "../channel.ts"; | ||
import { createWrpHost } from "../host.ts"; | ||
import { createWrpHost, WrpRequest } from "../host.ts"; | ||
import { Metadata } from "../metadata.ts"; | ||
import { createWrpServer, createWrpServerImplBuilder } from "../rpc/server.ts"; | ||
|
||
|
@@ -18,10 +18,10 @@ export type MethodImpl<TState extends Record<string, any>, TReq, TRes> = [ | |
( | ||
params: { | ||
req: Parameters< | ||
MethodImplHandler<TReq, TRes, Metadata, Metadata, Metadata> | ||
MethodImplHandler<TReq, TRes, WrpRequest, Metadata, Metadata> | ||
>[0]; | ||
res: Parameters< | ||
MethodImplHandler<TReq, TRes, Metadata, Metadata, Metadata> | ||
MethodImplHandler<TReq, TRes, WrpRequest, Metadata, Metadata> | ||
>[1]; | ||
getState: GetStateFn<TState>; | ||
stateChanges: EventEmitter<TState>; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,17 +2,17 @@ import { | |
createServerImplBuilder, | ||
Method, | ||
} from "https://deno.land/x/[email protected]/core/runtime/rpc.ts"; | ||
import type { WrpHost } from "../host.ts"; | ||
import type { WrpHost, WrpRequest } from "../host.ts"; | ||
import type { Metadata } from "../metadata.ts"; | ||
import { getMethodName, mapAsyncGenerator } from "./misc.ts"; | ||
|
||
export interface CreateWrpServerConfig { | ||
host: WrpHost; | ||
methods: AsyncGenerator<Method<Metadata, Metadata, Metadata>>; | ||
methods: AsyncGenerator<Method<WrpRequest, Metadata, Metadata>>; | ||
} | ||
export async function createWrpServer(config: CreateWrpServerConfig) { | ||
const methods: { | ||
[methodName: string]: Method<Metadata, Metadata, Metadata>; | ||
[methodName: string]: Method<WrpRequest, Metadata, Metadata>; | ||
} = {}; | ||
for await (const method of config.methods) { | ||
const methodName = getMethodName(method[0]); | ||
|
@@ -37,7 +37,7 @@ export async function createWrpServer(config: CreateWrpServerConfig) { | |
const { requestType, responseType } = methodDescriptor; | ||
const [res, header, trailer] = methodImpl( | ||
mapAsyncGenerator(req, requestType.deserializeBinary), | ||
request.metadata, | ||
request, | ||
); | ||
(async function () { | ||
let _header: Metadata = {}; | ||
|
@@ -61,7 +61,7 @@ export async function createWrpServer(config: CreateWrpServerConfig) { | |
} | ||
|
||
export function createWrpServerImplBuilder() { | ||
return createServerImplBuilder<Metadata, Metadata, Metadata>(); | ||
return createServerImplBuilder<WrpRequest, Metadata, Metadata>(); | ||
} | ||
|
||
function doOnce<T extends (...args: any) => any>(fn: T) { | ||
|