-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.js
More file actions
28 lines (24 loc) · 750 Bytes
/
example.js
File metadata and controls
28 lines (24 loc) · 750 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const { schema, collection, dispatch } = require("./index.js")("./spec");
// define a standalone schema
schema("@hello/full-name", (s) => {
s.string("first-name");
s.string("last-name");
});
// create a collection with inline schema
collection("@hello/users", (c) => {
c.key("id")
c.uint("id");
c.uint("age");
c.struct("name", "@hello/full-name"); // struct with schema reference
c.struct("address", (s) => { // struct with nested inline schema (@hello/users/address)
s.string("city");
s.string("country");
});
});
// dispatch with schema reference
dispatch("@hello/change-name", "@hello/full-name");
// dispatch with inline schema
dispatch("@hello/change-address", (d) => {
d.string("city");
d.string("country");
});