@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.
- package/README.md +17 -15
- 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
|
|
70
|
+
First, we create a service using `ServiceSchema`:
|
|
71
71
|
|
|
72
72
|
```ts
|
|
73
|
-
import {
|
|
73
|
+
import { ServicaSchema, Procedure, Ok } from '@replit/river';
|
|
74
74
|
import { Type } from '@sinclair/typebox';
|
|
75
75
|
|
|
76
|
-
export const
|
|
77
|
-
|
|
76
|
+
export const ExampleService = ServiceSchema.define(
|
|
77
|
+
// configuration
|
|
78
|
+
{
|
|
78
79
|
// initializer for shared state
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
-
|
|
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,
|
|
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