@replit/river 0.16.0 → 0.16.1

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.
Files changed (2) hide show
  1. package/README.md +17 -15
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -67,20 +67,21 @@ npm i ws isomorphic-ws
67
67
 
68
68
  ### A basic router
69
69
 
70
- First, we create a service using the `ServiceBuilder`
70
+ First, we create a service using `ServiceSchema`:
71
71
 
72
72
  ```ts
73
- import { ServiceBuilder, Ok, buildServiceDefs } from '@replit/river';
73
+ import { ServicaSchema, Procedure, Ok } from '@replit/river';
74
74
  import { Type } from '@sinclair/typebox';
75
75
 
76
- export const ExampleServiceConstructor = () =>
77
- ServiceBuilder.create('example')
76
+ export const ExampleService = ServiceSchema.define(
77
+ // configuration
78
+ {
78
79
  // initializer for shared state
79
- .initialState({
80
- count: 0,
81
- })
82
- .defineProcedure('add', {
83
- type: 'rpc',
80
+ initializeState: () => ({ count: 0 }),
81
+ },
82
+ // procedures
83
+ {
84
+ add: Procedure.rpc({
84
85
  input: Type.Object({ n: Type.Number() }),
85
86
  output: Type.Object({ result: Type.Number() }),
86
87
  errors: Type.Never(),
@@ -90,11 +91,9 @@ export const ExampleServiceConstructor = () =>
90
91
  ctx.state.count += n;
91
92
  return Ok({ result: ctx.state.count });
92
93
  },
93
- })
94
- .finalize();
95
-
96
- // expore a listing of all the services that we have
97
- export const serviceDefs = buildServiceDefs([ExampleServiceConstructor()]);
94
+ }),
95
+ },
96
+ );
98
97
  ```
99
98
 
100
99
  Then, we create the server:
@@ -111,7 +110,10 @@ const port = 3000;
111
110
  const wss = new WebSocketServer({ server: httpServer });
112
111
  const transport = new WebSocketServerTransport(wss, 'SERVER');
113
112
 
114
- export const server = createServer(transport, serviceDefs);
113
+ export const server = createServer(transport, {
114
+ example: ExampleService,
115
+ });
116
+
115
117
  export type ServiceSurface = typeof server;
116
118
 
117
119
  httpServer.listen(port);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@replit/river",
3
3
  "description": "It's like tRPC but... with JSON Schema Support, duplex streaming and support for service multiplexing. Transport agnostic!",
4
- "version": "0.16.0",
4
+ "version": "0.16.1",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": {