Skip to content

Commit a5e90df

Browse files
committed
regen api
1 parent 28e0409 commit a5e90df

File tree

1 file changed

+154
-6
lines changed

1 file changed

+154
-6
lines changed

api.ts

Lines changed: 154 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -86,25 +86,55 @@ export interface Model extends Base {
8686

8787
/* ----- api/v1/objects ----- */
8888
export type ServiceState = {
89+
_v: number;
8990
_ts: number;
9091
_oid: ItemId;
9192
_gid: ItemId;
93+
9294
time: number;
9395
online: boolean;
9496
};
9597

96-
export type BaseState = ServiceState & {
97-
[argumentId: string]: number | boolean | string | BaseState;
98+
export type GeographyState = {
99+
lat: number;
100+
lon: number;
101+
};
102+
103+
export type GeometryState = {
104+
x: number;
105+
y: number;
106+
z?: number;
107+
};
108+
109+
export type GpsState = GeographyState & {
110+
alt: number;
111+
speed: number;
112+
sats?: number;
113+
};
114+
115+
/** we love MQTT so much that we even defined it in base types
116+
* (but we really shouldn't) */
117+
export type MqttState = {
118+
topic: string;
119+
payload: string;
98120
};
99121

100-
export type BaseConfig = {
122+
export type State = ServiceState &
123+
GpsState &
124+
MqttState &
125+
GeometryState & {
126+
[argumentId: string]: number | boolean | string;
127+
};
128+
129+
export type Config = {
101130
[parentId: string]: {
102131
[argumentId: string]: number | boolean | string;
103132
};
104133
};
105134

106-
export interface RicObject<TState = BaseState, TConfig = BaseConfig>
107-
extends Base {
135+
export type Packet = Partial<State>;
136+
137+
export interface RicObject<TState = State, TConfig = Config> extends Base {
108138
id: string;
109139
model: ItemId;
110140

@@ -116,7 +146,7 @@ export interface RicObject<TState = BaseState, TConfig = BaseConfig>
116146
* Type alias exported, but not recommended to use
117147
* sinse it conflicts with JavaScript `Object` built-in
118148
*/
119-
export type Object<TState = BaseState, TConfig = BaseConfig> = RicObject<
149+
export type Object<TState = State, TConfig = Config> = RicObject<
120150
TState,
121151
TConfig
122152
>;
@@ -135,6 +165,117 @@ export interface Event<T = unknown> {
135165
}
136166

137167

168+
/* ----- api/v1/geofences ----- */
169+
export type Geography = [lat: number, lon: number];
170+
171+
export type GeographyType =
172+
| "polygon"
173+
| "polyline"
174+
| "marker"
175+
| "circle"
176+
| "rectangle"
177+
| "route";
178+
179+
export type Geopoint = {
180+
type: "marker" | "circle";
181+
center: Geography;
182+
};
183+
184+
export type Geoline = {
185+
type: "polygon" | "polyline" | "rectangle";
186+
points: Geography[];
187+
};
188+
189+
export type Georoute = {
190+
type: "route";
191+
path: { name: string; geoline: string }[];
192+
};
193+
194+
export type Geoshape = Geopoint | Geoline | Georoute;
195+
196+
export interface Geofence extends Base {
197+
color?: string;
198+
shape?: Geoshape;
199+
floors?: Floor[];
200+
}
201+
202+
203+
/* ----- api/v1/scenes ----- */
204+
export type Geometry = [x: number, y: number, z?: number];
205+
206+
export interface Room {
207+
id: string;
208+
name: string;
209+
points: Geometry[];
210+
}
211+
212+
export interface Beacon {
213+
name: string;
214+
id?: string;
215+
type?: string;
216+
x: number;
217+
y: number;
218+
z?: number;
219+
}
220+
221+
export interface Floor {
222+
kind: "floor" | "template";
223+
name?: string;
224+
225+
floorId: string;
226+
sceneId: ItemId;
227+
228+
heightFrom?: number;
229+
heightTo?: number;
230+
231+
beacons?: Beacon[];
232+
}
233+
234+
export interface Scene extends Base {
235+
type: "2d" | "3d";
236+
file: ItemId;
237+
props?: Record<string, string>;
238+
}
239+
240+
241+
/* ----- api/v1/roles ----- */
242+
export interface Role extends Base {
243+
credentials: string[];
244+
}
245+
246+
247+
/* ----- api/v1/groups ----- */
248+
export interface Group extends Base {
249+
role: ItemId;
250+
251+
tagname: string;
252+
license?: ItemId;
253+
}
254+
255+
256+
/* ----- api/v1/users ----- */
257+
export interface User extends Base {
258+
role: ItemId;
259+
260+
/**
261+
@validate required, unique
262+
*/
263+
email: string;
264+
265+
/**
266+
@validate required, unique, alphanumeric, min:4, max:40
267+
*/
268+
login: string;
269+
270+
/* not stored in db and logs */
271+
password?: string;
272+
273+
phone: string;
274+
locale: string;
275+
timezoneOffset: number;
276+
}
277+
278+
138279
/* ----- api/v1/index ----- */
139280
export interface WellKnown {
140281
base: Base;
@@ -143,6 +284,13 @@ export interface WellKnown {
143284
objects: RicObject;
144285

145286
events: Event;
287+
288+
geofences: Geofence;
289+
scenes: Scene;
290+
291+
roles: Role;
292+
groups: Group;
293+
users: User;
146294
}
147295

148296

0 commit comments

Comments
 (0)