@replit/river
Advanced tools
Comparing version 0.1.5 to 0.1.6
@@ -6,7 +6,10 @@ import http from 'http'; | ||
import { afterAll, beforeAll, describe, expect, test } from 'vitest'; | ||
import { createWebSocketServer, createWsTransports, onServerReady } from '../transport/ws.util'; | ||
import { createWebSocketServer, createWsTransports, onServerReady, } from '../transport/util'; | ||
import { createServer } from '../router/server'; | ||
import { createClient } from '../router/client'; | ||
import { asClientRpc, asClientStream } from '../router/server.util'; | ||
export const EchoRequest = Type.Object({ msg: Type.String(), ignore: Type.Boolean() }); | ||
export const EchoRequest = Type.Object({ | ||
msg: Type.String(), | ||
ignore: Type.Boolean(), | ||
}); | ||
export const EchoResponse = Type.Object({ response: Type.String() }); | ||
@@ -102,4 +105,8 @@ export const TestServiceConstructor = () => ServiceBuilder.create('test') | ||
i.end(); | ||
await expect(o.next().then((res) => res.value)).resolves.toStrictEqual({ response: 'abc' }); | ||
await expect(o.next().then((res) => res.value)).resolves.toStrictEqual({ response: 'ghi' }); | ||
await expect(o.next().then((res) => res.value)).resolves.toStrictEqual({ | ||
response: 'abc', | ||
}); | ||
await expect(o.next().then((res) => res.value)).resolves.toStrictEqual({ | ||
response: 'ghi', | ||
}); | ||
expect(o.readableLength).toBe(0); | ||
@@ -127,3 +134,5 @@ }); | ||
const client = createClient(ct); | ||
await expect(client.test.add({ n: 3 })).resolves.toStrictEqual({ result: 3 }); | ||
await expect(client.test.add({ n: 3 })).resolves.toStrictEqual({ | ||
result: 3, | ||
}); | ||
}); | ||
@@ -140,6 +149,10 @@ test('stream', async () => { | ||
i.end(); | ||
await expect(o.next().then((res) => res.value)).resolves.toStrictEqual({ response: 'abc' }); | ||
await expect(o.next().then((res) => res.value)).resolves.toStrictEqual({ response: 'ghi' }); | ||
await expect(o.next().then((res) => res.value)).resolves.toStrictEqual({ | ||
response: 'abc', | ||
}); | ||
await expect(o.next().then((res) => res.value)).resolves.toStrictEqual({ | ||
response: 'ghi', | ||
}); | ||
close(); | ||
}); | ||
}); |
@@ -1,2 +0,2 @@ | ||
import { Codec } from "./types"; | ||
import { Codec } from './types'; | ||
export declare const NaiveJsonCodec: Codec; |
@@ -11,4 +11,4 @@ export { serializeService, ServiceBuilder } from './router/builder'; | ||
export type { TransportMessage, MessageId, OpaqueTransportMessage, TransportClientId, TransportMessageAck, } from './transport/message'; | ||
export { StdioTransport } from './transport/stdio'; | ||
export { StreamTransport } from './transport/stream'; | ||
export { WebSocketTransport } from './transport/ws'; | ||
export { createWebSocketServer, onServerReady, createWsTransports, waitForMessage, waitForSocketReady, createWebSocketClient, } from './transport/ws.util'; | ||
export { createWebSocketServer, onServerReady, createWsTransports, waitForMessage, waitForSocketReady, createWebSocketClient, } from './transport/util'; |
@@ -7,4 +7,4 @@ export { serializeService, ServiceBuilder } from './router/builder'; | ||
export { TransportMessageSchema, OpaqueTransportMessageSchema, TransportAckSchema, msg, payloadToTransportMessage, ack, reply, } from './transport/message'; | ||
export { StdioTransport } from './transport/stdio'; | ||
export { StreamTransport } from './transport/stream'; | ||
export { WebSocketTransport } from './transport/ws'; | ||
export { createWebSocketServer, onServerReady, createWsTransports, waitForMessage, waitForSocketReady, createWebSocketClient, } from './transport/ws.util'; | ||
export { createWebSocketServer, onServerReady, createWsTransports, waitForMessage, waitForSocketReady, createWebSocketClient, } from './transport/util'; |
import { pushable } from 'it-pushable'; | ||
import { msg } from '../transport/message'; | ||
import { waitForMessage } from '../transport/ws.util'; | ||
import { waitForMessage } from '../transport/util'; | ||
const noop = () => { }; | ||
@@ -5,0 +5,0 @@ function _createRecursiveProxy(callback, path) { |
@@ -40,3 +40,4 @@ import { Value } from '@sinclair/typebox/value'; | ||
const inputMessage = msg; | ||
if (procedure.type === 'rpc' && Value.Check(procedure.input, inputMessage.payload)) { | ||
if (procedure.type === 'rpc' && | ||
Value.Check(procedure.input, inputMessage.payload)) { | ||
// synchronous rpc | ||
@@ -43,0 +44,0 @@ const response = await procedure.handler(service.state, inputMessage); |
@@ -1,5 +0,7 @@ | ||
import { payloadToTransportMessage } from '../transport/message'; | ||
import { payloadToTransportMessage, } from '../transport/message'; | ||
import { pushable } from 'it-pushable'; | ||
export function asClientRpc(state, proc) { | ||
return (msg) => proc.handler(state, payloadToTransportMessage(msg)).then((res) => res.payload); | ||
return (msg) => proc | ||
.handler(state, payloadToTransportMessage(msg)) | ||
.then((res) => res.payload); | ||
} | ||
@@ -6,0 +8,0 @@ export function asClientStream(state, proc) { |
import http from 'http'; | ||
import { WebSocketTransport } from './ws'; | ||
import { describe, test, expect, beforeAll, afterAll } from 'vitest'; | ||
import { createWebSocketClient, createWebSocketServer, onServerReady, waitForMessage, } from './ws.util'; | ||
import { createWebSocketClient, createWebSocketServer, onServerReady, waitForMessage, } from './util'; | ||
const port = 3000; | ||
@@ -6,0 +6,0 @@ describe('sending and receiving across websockets works', () => { |
{ | ||
"name": "@replit/river", | ||
"description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"type": "module", | ||
@@ -20,3 +20,3 @@ "main": "dist/index.js", | ||
"@types/ws": "^8.5.5", | ||
"prettier": "^3.0.3", | ||
"prettier": "^3.0.0", | ||
"tsup": "^7.2.0", | ||
@@ -27,3 +27,4 @@ "typescript": "^5.2.2", | ||
"scripts": { | ||
"check": "tsc --noEmit", | ||
"check": "tsc --noEmit && npx prettier . --check", | ||
"format": "npx prettier . --write", | ||
"build": "tsc", | ||
@@ -43,14 +44,3 @@ "prepack": "npm run build", | ||
"author": "Jacky Zhao", | ||
"license": "MIT", | ||
"prettier": { | ||
"printWidth": 100, | ||
"tabWidth": 2, | ||
"singleQuote": true, | ||
"trailingComma": "all", | ||
"bracketSpacing": true, | ||
"semi": true, | ||
"useTabs": false, | ||
"parser": "typescript", | ||
"arrowParens": "always" | ||
} | ||
"license": "MIT" | ||
} |
# river - Streaming Remote Procedure Calls | ||
It's like tRPC but... | ||
- with JSON Schema Support | ||
@@ -10,2 +11,3 @@ - with full-duplex streaming | ||
## Levels of abstraction | ||
- Router | ||
@@ -16,2 +18,3 @@ - Service | ||
## TODO | ||
- support broadcast | ||
- support broadcast |
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
40637
41
1005
19