@adventurelabs/scout-core 2.1.3 → 2.2.1

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.
@@ -1,35 +1,51 @@
1
1
  import { EnumWebResponse, IWebResponse, } from "../types/requests";
2
+ function connectivityError(msg, data) {
3
+ return {
4
+ status: EnumWebResponse.ERROR,
5
+ msg,
6
+ data,
7
+ };
8
+ }
9
+ function herdRangeError(msg, offset) {
10
+ return {
11
+ ...connectivityError(msg, []),
12
+ hasMore: false,
13
+ nextOffset: offset,
14
+ };
15
+ }
16
+ function connectivityTimestampMs(timestamp) {
17
+ if (!timestamp)
18
+ return null;
19
+ const time = new Date(timestamp).getTime();
20
+ return Number.isNaN(time) ? null : time;
21
+ }
2
22
  function sortConnectivityByTimestamp(data) {
3
- return data.sort((a, b) => {
4
- if (!a.timestamp_start || !b.timestamp_start)
23
+ const withTimes = data.map((row) => ({
24
+ row,
25
+ time: connectivityTimestampMs(row.timestamp_start),
26
+ }));
27
+ withTimes.sort((a, b) => {
28
+ if (a.time == null || b.time == null)
5
29
  return 0;
6
- return (new Date(a.timestamp_start).getTime() -
7
- new Date(b.timestamp_start).getTime());
30
+ return a.time - b.time;
8
31
  });
32
+ return withTimes.map(({ row }) => row);
9
33
  }
10
34
  export async function get_connectivity_by_session_id_query(client, sessionId) {
11
35
  const { data, error } = await client.rpc("get_connectivity_with_coordinates", { session_id_caller: sessionId });
12
36
  if (error) {
13
37
  console.warn("Error fetching connectivity by session id:", error.message);
14
- return {
15
- status: EnumWebResponse.ERROR,
16
- msg: error.message,
17
- data: [],
18
- };
38
+ return connectivityError(error.message, []);
19
39
  }
20
- return IWebResponse.success(sortConnectivityByTimestamp(data || [])).to_compatible();
40
+ return IWebResponse.success(sortConnectivityByTimestamp(data ?? [])).to_compatible();
21
41
  }
22
42
  export async function get_connectivity_by_device_id_query(client, deviceId, timestamp) {
23
43
  const { data, error } = await client.rpc("get_connectivity_with_coordinates_by_device_and_timestamp", { device_id_caller: deviceId, timestamp_filter: timestamp });
24
44
  if (error) {
25
- console.warn("Error fetching connectivity by session id:", error.message);
26
- return {
27
- status: EnumWebResponse.ERROR,
28
- msg: error.message,
29
- data: [],
30
- };
45
+ console.warn("Error fetching connectivity by device id:", error.message);
46
+ return connectivityError(error.message, []);
31
47
  }
32
- return IWebResponse.success(sortConnectivityByTimestamp(data || [])).to_compatible();
48
+ return IWebResponse.success(sortConnectivityByTimestamp(data ?? [])).to_compatible();
33
49
  }
34
50
  export async function insert_connectivity_query(client, connectivity) {
35
51
  const connectivityArray = Array.isArray(connectivity)
@@ -41,13 +57,9 @@ export async function insert_connectivity_query(client, connectivity) {
41
57
  .select("*");
42
58
  if (error) {
43
59
  console.warn("Error inserting connectivity:", error.message);
44
- return {
45
- status: EnumWebResponse.ERROR,
46
- msg: error.message,
47
- data: [],
48
- };
60
+ return connectivityError(error.message, []);
49
61
  }
50
- return IWebResponse.success(data || []).to_compatible();
62
+ return IWebResponse.success(data ?? []).to_compatible();
51
63
  }
52
64
  export async function update_connectivity_query(client, connectivity) {
53
65
  const connectivityArray = Array.isArray(connectivity)
@@ -65,11 +77,7 @@ export async function update_connectivity_query(client, connectivity) {
65
77
  .single();
66
78
  if (error) {
67
79
  console.warn("Error updating connectivity:", error.message);
68
- return {
69
- status: EnumWebResponse.ERROR,
70
- msg: error.message,
71
- data: [],
72
- };
80
+ return connectivityError(error.message, []);
73
81
  }
74
82
  if (data) {
75
83
  updatedConnectivity.push(data);
@@ -87,15 +95,9 @@ export async function get_connectivity_for_herd_time_range_query(client, herdId,
87
95
  });
88
96
  if (error) {
89
97
  console.warn("Error fetching connectivity for herd time range:", error.message);
90
- return {
91
- status: EnumWebResponse.ERROR,
92
- msg: error.message,
93
- data: [],
94
- hasMore: false,
95
- nextOffset: offset,
96
- };
98
+ return herdRangeError(error.message, offset);
97
99
  }
98
- const sorted = sortConnectivityByTimestamp(data || []);
100
+ const sorted = sortConnectivityByTimestamp(data ?? []);
99
101
  const hasMore = sorted.length > maxCount;
100
102
  const items = hasMore ? sorted.slice(0, maxCount) : sorted;
101
103
  return {
@@ -111,11 +113,7 @@ export async function get_connectivity_for_artifact_query(client, artifactId, ma
111
113
  });
112
114
  if (error) {
113
115
  console.warn("Error fetching connectivity for artifact:", error.message);
114
- return {
115
- status: EnumWebResponse.ERROR,
116
- msg: error.message,
117
- data: [],
118
- };
116
+ return connectivityError(error.message, []);
119
117
  }
120
- return IWebResponse.success(sortConnectivityByTimestamp(data || [])).to_compatible();
118
+ return IWebResponse.success(sortConnectivityByTimestamp(data ?? [])).to_compatible();
121
119
  }
@@ -1,3 +1,3 @@
1
- import { SupabaseClient } from "@supabase/supabase-js";
2
- import { Database } from "../types/supabase";
3
- export declare function createClientWithApiKey(user_api_key: string): SupabaseClient<Database> | null;
1
+ import type { AnyScoutDatabase, ScoutDatabase } from "../types/extend";
2
+ import type { ScoutDatabaseClient } from "../types/db";
3
+ export declare function createClientWithApiKey<DB extends AnyScoutDatabase = ScoutDatabase>(user_api_key: string): ScoutDatabaseClient<DB> | null;
@@ -175,7 +175,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
175
175
  isFetching: false;
176
176
  isSuccess: false;
177
177
  isError: false;
178
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
178
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
179
179
  isSuccess: true;
180
180
  isFetching: true;
181
181
  error: undefined;
@@ -199,7 +199,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
199
199
  isFetching: false;
200
200
  isSuccess: false;
201
201
  isError: false;
202
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
202
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
203
203
  isSuccess: true;
204
204
  isFetching: false;
205
205
  error: undefined;
@@ -284,7 +284,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
284
284
  isFetching: false;
285
285
  isSuccess: false;
286
286
  isError: false;
287
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
287
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
288
288
  isSuccess: true;
289
289
  isFetching: true;
290
290
  error: undefined;
@@ -308,7 +308,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
308
308
  isFetching: false;
309
309
  isSuccess: false;
310
310
  isError: false;
311
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
311
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
312
312
  isSuccess: true;
313
313
  isFetching: false;
314
314
  error: undefined;
@@ -391,7 +391,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
391
391
  isFetching: false;
392
392
  isSuccess: false;
393
393
  isError: false;
394
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
394
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
395
395
  isSuccess: true;
396
396
  isFetching: true;
397
397
  error: undefined;
@@ -415,7 +415,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
415
415
  isFetching: false;
416
416
  isSuccess: false;
417
417
  isError: false;
418
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
418
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
419
419
  isSuccess: true;
420
420
  isFetching: false;
421
421
  error: undefined;
@@ -500,7 +500,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
500
500
  isFetching: false;
501
501
  isSuccess: false;
502
502
  isError: false;
503
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
503
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
504
504
  isSuccess: true;
505
505
  isFetching: true;
506
506
  error: undefined;
@@ -524,7 +524,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
524
524
  isFetching: false;
525
525
  isSuccess: false;
526
526
  isError: false;
527
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
527
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
528
528
  isSuccess: true;
529
529
  isFetching: false;
530
530
  error: undefined;
@@ -607,7 +607,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
607
607
  isFetching: false;
608
608
  isSuccess: false;
609
609
  isError: false;
610
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
610
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
611
611
  isSuccess: true;
612
612
  isFetching: true;
613
613
  error: undefined;
@@ -631,7 +631,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
631
631
  isFetching: false;
632
632
  isSuccess: false;
633
633
  isError: false;
634
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
634
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
635
635
  isSuccess: true;
636
636
  isFetching: false;
637
637
  error: undefined;
@@ -716,7 +716,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
716
716
  isFetching: false;
717
717
  isSuccess: false;
718
718
  isError: false;
719
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
719
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
720
720
  isSuccess: true;
721
721
  isFetching: true;
722
722
  error: undefined;
@@ -740,7 +740,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
740
740
  isFetching: false;
741
741
  isSuccess: false;
742
742
  isError: false;
743
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
743
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
744
744
  isSuccess: true;
745
745
  isFetching: false;
746
746
  error: undefined;
@@ -823,7 +823,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
823
823
  isFetching: false;
824
824
  isSuccess: false;
825
825
  isError: false;
826
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
826
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
827
827
  isSuccess: true;
828
828
  isFetching: true;
829
829
  error: undefined;
@@ -847,7 +847,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
847
847
  isFetching: false;
848
848
  isSuccess: false;
849
849
  isError: false;
850
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
850
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
851
851
  isSuccess: true;
852
852
  isFetching: false;
853
853
  error: undefined;
@@ -932,7 +932,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
932
932
  isFetching: false;
933
933
  isSuccess: false;
934
934
  isError: false;
935
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
935
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
936
936
  isSuccess: true;
937
937
  isFetching: true;
938
938
  error: undefined;
@@ -956,7 +956,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
956
956
  isFetching: false;
957
957
  isSuccess: false;
958
958
  isError: false;
959
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
959
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
960
960
  isSuccess: true;
961
961
  isFetching: false;
962
962
  error: undefined;
@@ -1039,7 +1039,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
1039
1039
  isFetching: false;
1040
1040
  isSuccess: false;
1041
1041
  isError: false;
1042
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
1042
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
1043
1043
  isSuccess: true;
1044
1044
  isFetching: true;
1045
1045
  error: undefined;
@@ -1063,7 +1063,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
1063
1063
  isFetching: false;
1064
1064
  isSuccess: false;
1065
1065
  isError: false;
1066
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
1066
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
1067
1067
  isSuccess: true;
1068
1068
  isFetching: false;
1069
1069
  error: undefined;
@@ -1148,7 +1148,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
1148
1148
  isFetching: false;
1149
1149
  isSuccess: false;
1150
1150
  isError: false;
1151
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
1151
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
1152
1152
  isSuccess: true;
1153
1153
  isFetching: true;
1154
1154
  error: undefined;
@@ -1172,7 +1172,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
1172
1172
  isFetching: false;
1173
1173
  isSuccess: false;
1174
1174
  isError: false;
1175
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
1175
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
1176
1176
  isSuccess: true;
1177
1177
  isFetching: false;
1178
1178
  error: undefined;
@@ -1255,7 +1255,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
1255
1255
  isFetching: false;
1256
1256
  isSuccess: false;
1257
1257
  isError: false;
1258
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
1258
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
1259
1259
  isSuccess: true;
1260
1260
  isFetching: true;
1261
1261
  error: undefined;
@@ -1279,7 +1279,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
1279
1279
  isFetching: false;
1280
1280
  isSuccess: false;
1281
1281
  isError: false;
1282
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
1282
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
1283
1283
  isSuccess: true;
1284
1284
  isFetching: false;
1285
1285
  error: undefined;
@@ -1364,7 +1364,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
1364
1364
  isFetching: false;
1365
1365
  isSuccess: false;
1366
1366
  isError: false;
1367
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
1367
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
1368
1368
  isSuccess: true;
1369
1369
  isFetching: true;
1370
1370
  error: undefined;
@@ -1388,7 +1388,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
1388
1388
  isFetching: false;
1389
1389
  isSuccess: false;
1390
1390
  isError: false;
1391
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
1391
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
1392
1392
  isSuccess: true;
1393
1393
  isFetching: false;
1394
1394
  error: undefined;
@@ -1467,7 +1467,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
1467
1467
  isFetching: false;
1468
1468
  isSuccess: false;
1469
1469
  isError: false;
1470
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
1470
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
1471
1471
  isSuccess: true;
1472
1472
  isFetching: true;
1473
1473
  error: undefined;
@@ -1487,7 +1487,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
1487
1487
  isFetching: false;
1488
1488
  isSuccess: false;
1489
1489
  isError: false;
1490
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
1490
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
1491
1491
  isSuccess: true;
1492
1492
  isFetching: false;
1493
1493
  error: undefined;
@@ -1560,7 +1560,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
1560
1560
  isFetching: false;
1561
1561
  isSuccess: false;
1562
1562
  isError: false;
1563
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
1563
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
1564
1564
  isSuccess: true;
1565
1565
  isFetching: true;
1566
1566
  error: undefined;
@@ -1580,7 +1580,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
1580
1580
  isFetching: false;
1581
1581
  isSuccess: false;
1582
1582
  isError: false;
1583
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
1583
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
1584
1584
  isSuccess: true;
1585
1585
  isFetching: false;
1586
1586
  error: undefined;
@@ -1651,7 +1651,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
1651
1651
  isFetching: false;
1652
1652
  isSuccess: false;
1653
1653
  isError: false;
1654
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
1654
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
1655
1655
  isSuccess: true;
1656
1656
  isFetching: true;
1657
1657
  error: undefined;
@@ -1671,7 +1671,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
1671
1671
  isFetching: false;
1672
1672
  isSuccess: false;
1673
1673
  isError: false;
1674
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
1674
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
1675
1675
  isSuccess: true;
1676
1676
  isFetching: false;
1677
1677
  error: undefined;
@@ -1744,7 +1744,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
1744
1744
  isFetching: false;
1745
1745
  isSuccess: false;
1746
1746
  isError: false;
1747
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
1747
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
1748
1748
  isSuccess: true;
1749
1749
  isFetching: true;
1750
1750
  error: undefined;
@@ -1764,7 +1764,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
1764
1764
  isFetching: false;
1765
1765
  isSuccess: false;
1766
1766
  isError: false;
1767
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
1767
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
1768
1768
  isSuccess: true;
1769
1769
  isFetching: false;
1770
1770
  error: undefined;
@@ -1835,7 +1835,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
1835
1835
  isFetching: false;
1836
1836
  isSuccess: false;
1837
1837
  isError: false;
1838
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
1838
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
1839
1839
  isSuccess: true;
1840
1840
  isFetching: true;
1841
1841
  error: undefined;
@@ -1855,7 +1855,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
1855
1855
  isFetching: false;
1856
1856
  isSuccess: false;
1857
1857
  isError: false;
1858
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
1858
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
1859
1859
  isSuccess: true;
1860
1860
  isFetching: false;
1861
1861
  error: undefined;
@@ -1928,7 +1928,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
1928
1928
  isFetching: false;
1929
1929
  isSuccess: false;
1930
1930
  isError: false;
1931
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
1931
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
1932
1932
  isSuccess: true;
1933
1933
  isFetching: true;
1934
1934
  error: undefined;
@@ -1948,7 +1948,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
1948
1948
  isFetching: false;
1949
1949
  isSuccess: false;
1950
1950
  isError: false;
1951
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
1951
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
1952
1952
  isSuccess: true;
1953
1953
  isFetching: false;
1954
1954
  error: undefined;
@@ -2019,7 +2019,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
2019
2019
  isFetching: false;
2020
2020
  isSuccess: false;
2021
2021
  isError: false;
2022
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
2022
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
2023
2023
  isSuccess: true;
2024
2024
  isFetching: true;
2025
2025
  error: undefined;
@@ -2039,7 +2039,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
2039
2039
  isFetching: false;
2040
2040
  isSuccess: false;
2041
2041
  isError: false;
2042
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
2042
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
2043
2043
  isSuccess: true;
2044
2044
  isFetching: false;
2045
2045
  error: undefined;
@@ -2112,7 +2112,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
2112
2112
  isFetching: false;
2113
2113
  isSuccess: false;
2114
2114
  isError: false;
2115
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
2115
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
2116
2116
  isSuccess: true;
2117
2117
  isFetching: true;
2118
2118
  error: undefined;
@@ -2132,7 +2132,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
2132
2132
  isFetching: false;
2133
2133
  isSuccess: false;
2134
2134
  isError: false;
2135
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
2135
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
2136
2136
  isSuccess: true;
2137
2137
  isFetching: false;
2138
2138
  error: undefined;
@@ -2203,7 +2203,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
2203
2203
  isFetching: false;
2204
2204
  isSuccess: false;
2205
2205
  isError: false;
2206
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
2206
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
2207
2207
  isSuccess: true;
2208
2208
  isFetching: true;
2209
2209
  error: undefined;
@@ -2223,7 +2223,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
2223
2223
  isFetching: false;
2224
2224
  isSuccess: false;
2225
2225
  isError: false;
2226
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
2226
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
2227
2227
  isSuccess: true;
2228
2228
  isFetching: false;
2229
2229
  error: undefined;
@@ -2296,7 +2296,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
2296
2296
  isFetching: false;
2297
2297
  isSuccess: false;
2298
2298
  isError: false;
2299
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
2299
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
2300
2300
  isSuccess: true;
2301
2301
  isFetching: true;
2302
2302
  error: undefined;
@@ -2316,7 +2316,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
2316
2316
  isFetching: false;
2317
2317
  isSuccess: false;
2318
2318
  isError: false;
2319
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
2319
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
2320
2320
  isSuccess: true;
2321
2321
  isFetching: false;
2322
2322
  error: undefined;
@@ -2387,7 +2387,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
2387
2387
  isFetching: false;
2388
2388
  isSuccess: false;
2389
2389
  isError: false;
2390
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
2390
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
2391
2391
  isSuccess: true;
2392
2392
  isFetching: true;
2393
2393
  error: undefined;
@@ -2407,7 +2407,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
2407
2407
  isFetching: false;
2408
2408
  isSuccess: false;
2409
2409
  isError: false;
2410
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
2410
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
2411
2411
  isSuccess: true;
2412
2412
  isFetching: false;
2413
2413
  error: undefined;
@@ -2480,7 +2480,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
2480
2480
  isFetching: false;
2481
2481
  isSuccess: false;
2482
2482
  isError: false;
2483
- }, "data" | "error" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
2483
+ }, "error" | "data" | "fulfilledTimeStamp" | "isFetching" | "isSuccess"> & {
2484
2484
  isSuccess: true;
2485
2485
  isFetching: true;
2486
2486
  error: undefined;
@@ -2500,7 +2500,7 @@ export declare const useGetSessionsInfiniteByHerdQuery: <R extends Record<string
2500
2500
  isFetching: false;
2501
2501
  isSuccess: false;
2502
2502
  isError: false;
2503
- }, "data" | "error" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
2503
+ }, "error" | "data" | "fulfilledTimeStamp" | "currentData" | "isFetching" | "isSuccess"> & {
2504
2504
  isSuccess: true;
2505
2505
  isFetching: false;
2506
2506
  error: undefined;
@@ -1,3 +1,3 @@
1
- import type { SupabaseClient } from "@supabase/supabase-js";
2
- import type { Database } from "../types/supabase";
3
- export declare function createScoutBrowserClient(): SupabaseClient<Database>;
1
+ import type { AnyScoutDatabase, ScoutDatabase } from "../types/extend";
2
+ import type { ScoutDatabaseClient } from "../types/db";
3
+ export declare function createScoutBrowserClient<DB extends AnyScoutDatabase = ScoutDatabase>(): ScoutDatabaseClient<DB>;
@@ -1,6 +1,6 @@
1
1
  import "server-only";
2
- import type { Database } from "../types/supabase";
3
- import type { SupabaseClient } from "@supabase/supabase-js";
2
+ import type { AnyScoutDatabase, ScoutDatabase } from "../types/extend";
3
+ import type { ScoutDatabaseClient } from "../types/db";
4
4
  export interface IServerClientOptions {
5
5
  persistSession?: boolean;
6
6
  }
@@ -8,4 +8,4 @@ export interface IServerClientOptions {
8
8
  * Reuses one read client per RSC request. Cookie writes are opt-in for
9
9
  * auth-mutating actions; middleware persists normal session refreshes.
10
10
  */
11
- export declare function newServerClient(options?: IServerClientOptions): Promise<SupabaseClient<Database>>;
11
+ export declare function newServerClient<DB extends AnyScoutDatabase = ScoutDatabase>(options?: IServerClientOptions): Promise<ScoutDatabaseClient<DB>>;
@@ -31,5 +31,6 @@ const cachedRequestClient = cache(() => createRequestClient({}));
31
31
  export function newServerClient(options = {}) {
32
32
  return options.persistSession
33
33
  ? createRequestClient(options)
34
- : cachedRequestClient();
34
+ : // The schema only exists at compile time, so the cached client serves any extension of it.
35
+ cachedRequestClient();
35
36
  }
@@ -1,6 +1,11 @@
1
1
  import type { SupabaseClient, User } from "@supabase/supabase-js";
2
2
  import type { Database } from "./supabase";
3
- export type ScoutDatabaseClient = SupabaseClient<Database, "public">;
3
+ import type { AnyScoutDatabase, ScoutDatabase } from "./extend";
4
+ /**
5
+ * A Supabase client over Scout's schema, or over any deployment schema that extends it (see
6
+ * `ExtendDatabase`). Scout helpers accept both.
7
+ */
8
+ export type ScoutDatabaseClient<DB extends AnyScoutDatabase = ScoutDatabase> = SupabaseClient<DB>;
4
9
  export type DeviceType = Database["public"]["Enums"]["device_type"];
5
10
  export type MediaType = Database["public"]["Enums"]["media_type"];
6
11
  export type TagObservationType = Database["public"]["Enums"]["tag_observation_type"];
@@ -0,0 +1,126 @@
1
+ import type { DatabaseWithoutInternals } from "@supabase/supabase-js";
2
+ import type { Database } from "./supabase";
3
+ /**
4
+ * Scout's generated schema. Deployments that add their own tables, views, functions, enums or
5
+ * composite types describe the additions with `ExtendDatabase` instead of replacing this, so
6
+ * Scout's own helpers keep working against the same client.
7
+ */
8
+ export type ScoutDatabase = Database;
9
+ /**
10
+ * What Scout requires of a deployment's schema: that it covers Scout's own. Generator metadata
11
+ * is excluded because `__InternalSupabase` pins the PostgREST version the types were generated
12
+ * against, and a deployment that runs its own `supabase gen types` will not report Scout's.
13
+ */
14
+ export type AnyScoutDatabase = DatabaseWithoutInternals<ScoutDatabase>;
15
+ type ScoutSchema = ScoutDatabase["public"];
16
+ /**
17
+ * A foreign key reachable from a table, as the Supabase generator emits it. Mirrors PostgREST's
18
+ * own `GenericRelationship`, which the package declares but does not export.
19
+ */
20
+ export interface TableRelationship {
21
+ foreignKeyName: string;
22
+ columns: string[];
23
+ isOneToOne?: boolean;
24
+ referencedRelation: string;
25
+ referencedColumns: string[];
26
+ }
27
+ /**
28
+ * A table (or updatable view) a deployment adds. Only `Row` is required.
29
+ *
30
+ * Declare row shapes as type aliases, not interfaces: PostgREST needs an index signature to
31
+ * resolve a schema, and TypeScript only infers one for aliases. Loosening this constraint does
32
+ * not help, it just trades this error for a silently untyped client.
33
+ */
34
+ export interface TableExtension {
35
+ Row: Record<string, unknown>;
36
+ Insert?: Record<string, unknown>;
37
+ Update?: Record<string, unknown>;
38
+ Relationships?: TableRelationship[];
39
+ }
40
+ /** A PostgREST function a deployment adds, as reached through `client.rpc(...)`. */
41
+ export interface FunctionExtension {
42
+ Args: Record<string, unknown>;
43
+ Returns: unknown;
44
+ }
45
+ /** Everything a deployment adds to the `public` schema on top of Scout's. */
46
+ export interface SchemaExtension {
47
+ Tables?: Record<string, TableExtension>;
48
+ Views?: Record<string, TableExtension>;
49
+ Functions?: Record<string, FunctionExtension>;
50
+ Enums?: Record<string, string>;
51
+ CompositeTypes?: Record<string, Record<string, unknown>>;
52
+ }
53
+ type Added<Ext extends SchemaExtension, K extends keyof SchemaExtension> = K extends keyof Ext ? Exclude<Ext[K], undefined> : {};
54
+ /** Supplies the `Insert`/`Update`/`Relationships` members the Supabase generator would emit. */
55
+ type NormalizeTables<T> = {
56
+ [K in keyof T]: {
57
+ Row: T[K] extends {
58
+ Row: infer R;
59
+ } ? R : never;
60
+ Insert: T[K] extends {
61
+ Insert: infer I;
62
+ } ? I : T[K] extends {
63
+ Row: infer R;
64
+ } ? R : never;
65
+ Update: T[K] extends {
66
+ Update: infer U;
67
+ } ? U : T[K] extends {
68
+ Row: infer R;
69
+ } ? Partial<R> : never;
70
+ Relationships: T[K] extends {
71
+ Relationships: infer L;
72
+ } ? L : [];
73
+ };
74
+ };
75
+ type NormalizeViews<T> = {
76
+ [K in keyof T]: Omit<T[K], "Relationships"> & {
77
+ Relationships: T[K] extends {
78
+ Relationships: infer L;
79
+ } ? L : [];
80
+ };
81
+ };
82
+ /**
83
+ * Merges a deployment's additions into Scout's schema. The result stays assignable to
84
+ * `ScoutDatabase`, so a client built from it satisfies every Scout helper while also typing the
85
+ * deployment's own tables and RPCs.
86
+ *
87
+ * ```ts
88
+ * type AppDatabase = ExtendDatabase<{
89
+ * Tables: { field_notes: { Row: { id: number; body: string } } };
90
+ * Functions: { notes_for_herd: { Args: { herd_id: number }; Returns: { id: number }[] } };
91
+ * }>;
92
+ * ```
93
+ *
94
+ * Each member intersects rather than being merged with a mapped type. Intersecting leaves
95
+ * Scout's schema as one constituent that resolves lazily, so the constraint check short-circuits
96
+ * on its identity; a mapped merge has to walk all of it eagerly and measured ~49% more type
97
+ * instantiations. The cost is that hover text shows the intersection unreduced.
98
+ */
99
+ export type ExtendDatabase<Ext extends SchemaExtension> = Omit<ScoutDatabase, "public"> & {
100
+ public: {
101
+ Tables: ScoutSchema["Tables"] & NormalizeTables<Added<Ext, "Tables">>;
102
+ Views: ScoutSchema["Views"] & NormalizeViews<Added<Ext, "Views">>;
103
+ Functions: ScoutSchema["Functions"] & Added<Ext, "Functions">;
104
+ Enums: ScoutSchema["Enums"] & Added<Ext, "Enums">;
105
+ CompositeTypes: ScoutSchema["CompositeTypes"] & Added<Ext, "CompositeTypes">;
106
+ };
107
+ };
108
+ /**
109
+ * Adopts a schema a deployment generated from its own project, for deployments whose own
110
+ * `supabase gen types` run already covers Scout's tables alongside theirs.
111
+ *
112
+ * Only the generator metadata is rewritten. `supabase gen types` records the PostgREST version
113
+ * of the project it ran against, and `SupabaseClient` carries that version in its own type, so a
114
+ * deployment on a different version would otherwise produce a client no Scout helper accepts
115
+ * even though the schemas agree. Scout's helpers are written against Scout's PostgREST
116
+ * regardless. The `AnyScoutDatabase` constraint still rejects a schema that does not cover
117
+ * Scout's.
118
+ *
119
+ * ```ts
120
+ * import type { Database as Generated } from "@/types/supabase";
121
+ *
122
+ * export type AppDatabase = AdoptDatabase<Generated>;
123
+ * ```
124
+ */
125
+ export type AdoptDatabase<DB extends AnyScoutDatabase> = Omit<DB, "__InternalSupabase"> & Pick<ScoutDatabase, "__InternalSupabase">;
126
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -4,6 +4,7 @@ export * from "./ui";
4
4
  export * from "./requests";
5
5
  export * from "./gps";
6
6
  export * from "./supabase";
7
+ export * from "./extend";
7
8
  export * from "./bounding_boxes";
8
9
  export * from "./events";
9
10
  export * from "./data_source";
@@ -4,6 +4,7 @@ export * from "./ui";
4
4
  export * from "./requests";
5
5
  export * from "./gps";
6
6
  export * from "./supabase";
7
+ export * from "./extend";
7
8
  export * from "./bounding_boxes";
8
9
  export * from "./events";
9
10
  export * from "./data_source";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@adventurelabs/scout-core",
3
- "version": "2.1.3",
3
+ "version": "2.2.1",
4
4
  "description": "Core utilities and helpers for Adventure Labs Scout applications",
5
5
  "exports": {
6
6
  "./client": {