-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathinstant.schema.ts
165 lines (160 loc) · 3.59 KB
/
instant.schema.ts
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
import { i } from "@instantdb/core";
const _schema = i.schema({
// This section lets you define entities: think `posts`, `comments`, etc
// Take a look at the docs to learn more:
// https://www.instantdb.com/docs/modeling-data#2-attributes
entities: {
$users: i.entity({
email: i.string().unique().indexed(),
}),
shares: i.entity({
type: i.string(), // Yes or No
reserve: i.number(),
}),
options: i.entity({
name: i.string(),
color: i.string(),
image: i.string(),
}),
markets: i.entity({
name: i.string(),
description: i.string(),
image: i.string(),
allow_multiple_correct: i.boolean(),
created_at: i.date(),
resolve_at: i.date(),
stop_trading_at: i.date(),
rule: i.string(),
// social
// faster (don't have to aggregate)
// Only indexed and type-checked attrs can be used to order by.
num_votes: i.number().indexed(),
}),
holdings: i.entity({
amount: i.number(),
updated_at: i.date(),
}),
profiles: i.entity({
name: i.string(),
avatar_src: i.string(),
usd: i.number(),
}),
history__options: i.entity({
option_id: i.string(),
created_at: i.date(),
yesProb: i.number(),
}),
conversations: i.entity({
name: i.string(),
}),
blocks: i.entity({
created_at: i.date(),
updated_at: i.date(),
content: i.json(),
role: i.string(),
agent_step: i.string().optional(),
}),
votes: i.entity({
isUpvote: i.boolean(),
})
},
// You can define links here.
// For example, if `posts` should have many `comments`.
// More in the docs:
// https://www.instantdb.com/docs/modeling-data#3-links
links: {
profile_votes: {
forward: {
on: "profiles",
has: "many",
label: "votes",
},
reverse: {
on: "votes",
has: "one",
label: "profile",
},
},
market_votes: {
forward: {
on: "markets",
has: "many",
label: "votes",
},
reverse: {
on: "votes",
has: "one",
label: "market",
},
},
options_shares: {
forward: {
on: "options",
has: "many",
label: "shares",
},
reverse: {
on: "shares",
has: "one",
label: "option",
},
},
markets_options: {
forward: {
on: "markets",
has: "many",
label: "options",
},
reverse: {
on: "options",
has: "one",
label: "market",
},
},
profiles_holdings: {
forward: {
on: "profiles",
has: "many",
label: "holdings",
},
reverse: {
on: "holdings",
has: "one",
label: "profile",
},
},
holdings_shares: {
forward: {
on: "holdings",
has: "one",
label: "share",
},
reverse: {
on: "shares",
has: "many",
label: "holdings",
},
},
profile_blocks: {
forward: {
on: "profiles",
has: "many",
label: "blocks",
},
reverse: {
on: "blocks",
has: "one",
label: "profile",
},
}
},
// If you use presence, you can define a room schema here
// https://www.instantdb.com/docs/presence-and-topics#typesafety
rooms: {},
});
// This helps Typescript display nicer intellisense
type _AppSchema = typeof _schema;
interface AppSchema extends _AppSchema { }
const schema: AppSchema = _schema;
export type { AppSchema };
export default schema;