@@ -59,36 +59,39 @@ oc.init <- function() {
59
59
```
60
60
61
61
``` typescript
62
- // ocap.ts
63
- import { numeric , list , ocap } from " rserve-ts/types" ;
62
+ // app.ts
63
+ import { z } from " zod" ;
64
+ import { Robj } from " ../index" ;
64
65
65
- export const appFuns = {
66
- add: ocap ([z .number (), z .number ()], numeric ()),
67
- dist: ocap (
66
+ export const appSchema = {
67
+ add: Robj . ocap ([z .number (), z .number ()], Robj . numeric (1 )),
68
+ dist: Robj . ocap (
68
69
[z .enum ([" normal" , " uniform" ])],
69
- list ({
70
- sample: ocap ([z .number ()], numeric ()),
70
+ Robj . list ({
71
+ sample: Robj . ocap ([z .number ()], Robj . numeric ()),
71
72
})
72
73
),
73
74
};
74
75
```
75
76
76
77
``` typescript
77
- import { RserveClient } from " rserve-ts" ;
78
- import { appFuns } from " ./ocap" ;
78
+ // app.ts
79
+ import R from " ../index" ;
80
+ import { appSchema } from " ./app" ;
79
81
80
82
(async () => {
81
- const R = await RserveClient .create ({
82
- host: " http://127.0.0.1:8081" ,
83
- });
84
-
85
- const app = await R .ocap (appFuns );
86
-
87
- const sum = await app .add (1 , 2 );
88
- console .log (" 1 + 2 = " , sum );
89
-
90
- const chosenDist = await app .dist (" normal" );
91
- const sample = await chosenDist .sample (5 );
92
- console .log (" Normal sample: " , sample );
83
+ const s = await R .create ({ host: " ws://localhost:8181" });
84
+ const app = await s .ocap (appSchema );
85
+
86
+ const sum = await app .add (16 , 32 );
87
+ const cart = { total: sum };
88
+ cart .total ;
89
+
90
+ const { sample } = await app .dist (" uniform" );
91
+ const x = await sample (235 );
92
+ if (typeof x === " number" ) x + 5 ;
93
+ else {
94
+ // deal with an array
95
+ }
93
96
})();
94
97
```
0 commit comments