@adventurelabs/scout-core 1.0.30 → 1.0.31
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/dist/helpers/events.d.ts +8 -3
- package/dist/helpers/events.js +42 -14
- package/dist/types/herd_module.js +2 -2
- package/package.json +1 -1
package/dist/helpers/events.d.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import { IEvent } from "../types/db";
|
|
2
2
|
import { IWebResponseCompatible } from "../types/requests";
|
|
3
|
-
export declare
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
export declare enum EnumSessionsVisibility {
|
|
4
|
+
Only = 0,
|
|
5
|
+
Exclude = 1,
|
|
6
|
+
Combine = 2
|
|
7
|
+
}
|
|
8
|
+
export declare function server_get_events_by_herd(herd_id: number, sessions_visibility: EnumSessionsVisibility): Promise<IWebResponseCompatible<IEvent[]>>;
|
|
9
|
+
export declare function server_get_more_events_by_herd(herd_id: number, offset: number, page_count: number | undefined, includeSessionEvents: boolean): Promise<IWebResponseCompatible<IEvent[]>>;
|
|
10
|
+
export declare function server_get_total_events_by_herd(herd_id: number, sessions_visibility: EnumSessionsVisibility): Promise<IWebResponseCompatible<number>>;
|
|
6
11
|
export declare function server_create_event(newEvent: any): Promise<IWebResponseCompatible<boolean>>;
|
package/dist/helpers/events.js
CHANGED
|
@@ -2,18 +2,31 @@
|
|
|
2
2
|
import { newServerClient } from "../supabase/server";
|
|
3
3
|
import { EnumWebResponse, IWebResponse, } from "../types/requests";
|
|
4
4
|
import { addSignedUrlsToEvents } from "./storage";
|
|
5
|
-
export
|
|
5
|
+
export var EnumSessionsVisibility;
|
|
6
|
+
(function (EnumSessionsVisibility) {
|
|
7
|
+
EnumSessionsVisibility[EnumSessionsVisibility["Only"] = 0] = "Only";
|
|
8
|
+
EnumSessionsVisibility[EnumSessionsVisibility["Exclude"] = 1] = "Exclude";
|
|
9
|
+
EnumSessionsVisibility[EnumSessionsVisibility["Combine"] = 2] = "Combine";
|
|
10
|
+
})(EnumSessionsVisibility || (EnumSessionsVisibility = {}));
|
|
11
|
+
export async function server_get_events_by_herd(herd_id, sessions_visibility) {
|
|
6
12
|
const supabase = await newServerClient();
|
|
7
13
|
// fetch events and include devices
|
|
8
14
|
// sort by timestamp
|
|
9
|
-
|
|
15
|
+
let query = supabase
|
|
10
16
|
.from("events")
|
|
11
17
|
.select(`
|
|
12
18
|
*,
|
|
13
19
|
devices: devices!inner(*)
|
|
14
20
|
`)
|
|
15
|
-
.eq("devices.herd_id", herd_id)
|
|
16
|
-
|
|
21
|
+
.eq("devices.herd_id", herd_id);
|
|
22
|
+
// Apply session filter based on sessions_visibility
|
|
23
|
+
if (sessions_visibility === EnumSessionsVisibility.Only) {
|
|
24
|
+
query = query.not("session_id", "is", null);
|
|
25
|
+
}
|
|
26
|
+
else if (sessions_visibility === EnumSessionsVisibility.Exclude) {
|
|
27
|
+
query = query.is("session_id", null);
|
|
28
|
+
}
|
|
29
|
+
const { data } = await query.order("timestamp_observation", { ascending: false });
|
|
17
30
|
// Add signed URLs to events using the same client
|
|
18
31
|
const eventsWithSignedUrls = data
|
|
19
32
|
? await addSignedUrlsToEvents(data, supabase)
|
|
@@ -22,21 +35,29 @@ export async function server_get_events_by_herd(herd_id) {
|
|
|
22
35
|
let response = IWebResponse.success(eventsWithSignedUrls);
|
|
23
36
|
return response.to_compatible();
|
|
24
37
|
}
|
|
25
|
-
export async function server_get_more_events_by_herd(herd_id, offset, page_count = 10) {
|
|
38
|
+
export async function server_get_more_events_by_herd(herd_id, offset, page_count = 10, includeSessionEvents) {
|
|
26
39
|
const from = offset * page_count;
|
|
27
40
|
const to = from + page_count - 1;
|
|
28
41
|
const supabase = await newServerClient();
|
|
29
42
|
// fetch events and include devices
|
|
30
43
|
// sort by timestamp
|
|
31
|
-
|
|
44
|
+
let query = supabase
|
|
32
45
|
.from("events")
|
|
33
46
|
.select(`
|
|
34
47
|
*,
|
|
35
48
|
devices: devices!inner(*)
|
|
36
49
|
`)
|
|
37
50
|
.eq("devices.herd_id", herd_id)
|
|
38
|
-
.range(from, to)
|
|
39
|
-
|
|
51
|
+
.range(from, to);
|
|
52
|
+
if (includeSessionEvents) {
|
|
53
|
+
// Include only events that have a session_id
|
|
54
|
+
query = query.not("session_id", "is", null);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
// Include only events that don't have a session_id
|
|
58
|
+
query = query.is("session_id", null);
|
|
59
|
+
}
|
|
60
|
+
const { data } = await query.order("timestamp_observation", { ascending: false });
|
|
40
61
|
// Add signed URLs to events using the same client
|
|
41
62
|
const eventsWithSignedUrls = data
|
|
42
63
|
? await addSignedUrlsToEvents(data, supabase)
|
|
@@ -46,12 +67,19 @@ export async function server_get_more_events_by_herd(herd_id, offset, page_count
|
|
|
46
67
|
return response.to_compatible();
|
|
47
68
|
}
|
|
48
69
|
// function to get total number of events for a herd
|
|
49
|
-
export async function server_get_total_events_by_herd(herd_id) {
|
|
70
|
+
export async function server_get_total_events_by_herd(herd_id, sessions_visibility) {
|
|
50
71
|
const supabase = await newServerClient();
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
72
|
+
let query = supabase
|
|
73
|
+
.from("events")
|
|
74
|
+
.select("id", { count: "exact", head: true })
|
|
75
|
+
.eq("devices.herd_id", herd_id);
|
|
76
|
+
if (sessions_visibility === EnumSessionsVisibility.Only) {
|
|
77
|
+
query = query.not("session_id", "is", null);
|
|
78
|
+
}
|
|
79
|
+
else if (sessions_visibility === EnumSessionsVisibility.Exclude) {
|
|
80
|
+
query = query.is("session_id", null);
|
|
81
|
+
}
|
|
82
|
+
const { count, error } = await query;
|
|
55
83
|
if (error) {
|
|
56
84
|
return {
|
|
57
85
|
status: EnumWebResponse.ERROR,
|
|
@@ -60,7 +88,7 @@ export async function server_get_total_events_by_herd(herd_id) {
|
|
|
60
88
|
};
|
|
61
89
|
}
|
|
62
90
|
else {
|
|
63
|
-
return IWebResponse.success(
|
|
91
|
+
return IWebResponse.success(count || 0).to_compatible();
|
|
64
92
|
}
|
|
65
93
|
}
|
|
66
94
|
export async function server_create_event(newEvent) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { LABELS } from "../constants/annotator";
|
|
2
2
|
import { get_devices_by_herd } from "../helpers/devices";
|
|
3
|
-
import { server_get_total_events_by_herd } from "../helpers/events";
|
|
3
|
+
import { EnumSessionsVisibility, server_get_total_events_by_herd, } from "../helpers/events";
|
|
4
4
|
import { server_get_plans_by_herd } from "../helpers/plans";
|
|
5
5
|
import { server_get_events_and_tags_for_device } from "../helpers/tags";
|
|
6
6
|
import { server_get_users_with_herd_access } from "../helpers/users";
|
|
@@ -88,7 +88,7 @@ export class HerdModule {
|
|
|
88
88
|
console.warn("Failed to get user roles:", error);
|
|
89
89
|
return { status: EnumWebResponse.ERROR, data: null };
|
|
90
90
|
}),
|
|
91
|
-
server_get_total_events_by_herd(herd.id).catch((error) => {
|
|
91
|
+
server_get_total_events_by_herd(herd.id, EnumSessionsVisibility.Exclude).catch((error) => {
|
|
92
92
|
console.warn("Failed to get total events count:", error);
|
|
93
93
|
return { status: EnumWebResponse.ERROR, data: null };
|
|
94
94
|
}),
|