@adventurelabs/scout-core 1.5.4 → 2.0.0
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/README.md +47 -0
- package/dist/api_keys/actions.d.ts +0 -1
- package/dist/api_keys/actions.js +0 -14
- package/dist/client/index.d.ts +75 -0
- package/dist/client/index.js +82 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +1 -0
- package/dist/helpers/analysis_usage/jobs_server.d.ts +25 -0
- package/dist/helpers/analysis_usage/jobs_server.js +10 -0
- package/dist/helpers/analysis_usage/tasks_server.d.ts +63 -0
- package/dist/helpers/analysis_usage/tasks_server.js +14 -0
- package/dist/helpers/artifacts.d.ts +0 -1
- package/dist/helpers/artifacts.js +10 -147
- package/dist/helpers/artifacts.queries.d.ts +26 -0
- package/dist/helpers/{artifacts.internal.js → artifacts.queries.js} +24 -41
- package/dist/helpers/auth.d.ts +1 -1
- package/dist/helpers/auth.js +2 -3
- package/dist/helpers/auth_server.d.ts +2 -0
- package/dist/helpers/auth_server.js +10 -0
- package/dist/helpers/certificates_server.d.ts +101 -0
- package/dist/helpers/certificates_server.js +42 -0
- package/dist/helpers/chat.d.ts +1 -2
- package/dist/helpers/chat.js +3 -38
- package/dist/helpers/chat.queries.d.ts +13 -0
- package/dist/helpers/chat.queries.js +39 -0
- package/dist/helpers/client_abilities_jwt_keys.js +0 -1
- package/dist/helpers/client_abilities_token_server.d.ts +1 -0
- package/dist/helpers/client_abilities_token_server.js +5 -2
- package/dist/helpers/connectivity.d.ts +1 -5
- package/dist/helpers/connectivity.js +7 -140
- package/dist/helpers/connectivity.queries.d.ts +18 -0
- package/dist/helpers/connectivity.queries.js +121 -0
- package/dist/helpers/contacts_server.d.ts +63 -0
- package/dist/helpers/contacts_server.js +18 -0
- package/dist/helpers/deviceTransfer.js +2 -11
- package/dist/helpers/deviceTransfer.queries.d.ts +4 -0
- package/dist/helpers/deviceTransfer.queries.js +11 -0
- package/dist/helpers/devices.js +4 -61
- package/dist/helpers/devices.queries.d.ts +4 -1
- package/dist/helpers/devices.queries.js +52 -0
- package/dist/helpers/document_templates.js +6 -52
- package/dist/helpers/document_templates.queries.d.ts +9 -0
- package/dist/helpers/document_templates.queries.js +56 -0
- package/dist/helpers/documents_server.d.ts +226 -0
- package/dist/helpers/documents_server.js +38 -0
- package/dist/helpers/email.d.ts +0 -6
- package/dist/helpers/email.js +1 -19
- package/dist/helpers/embeddings.d.ts +0 -5
- package/dist/helpers/embeddings.js +2 -19
- package/dist/helpers/embeddings.queries.d.ts +7 -0
- package/dist/helpers/{embeddings.internal.js → embeddings.queries.js} +2 -2
- package/dist/helpers/eventUtils.d.ts +3 -12
- package/dist/helpers/eventUtils.js +0 -10
- package/dist/helpers/events.d.ts +0 -1
- package/dist/helpers/events.js +7 -107
- package/dist/helpers/events.queries.d.ts +17 -0
- package/dist/helpers/{events.internal.js → events.queries.js} +24 -15
- package/dist/helpers/health_metrics.js +3 -38
- package/dist/helpers/health_metrics.queries.d.ts +12 -0
- package/dist/helpers/health_metrics.queries.js +39 -0
- package/dist/helpers/heartbeats.js +4 -83
- package/dist/helpers/heartbeats.queries.d.ts +11 -0
- package/dist/helpers/heartbeats.queries.js +76 -0
- package/dist/helpers/herd_allowed_domains.js +2 -12
- package/dist/helpers/{herd_allowed_domains_internal.d.ts → herd_allowed_domains.queries.d.ts} +1 -1
- package/dist/helpers/{herd_allowed_domains_internal.js → herd_allowed_domains.queries.js} +2 -2
- package/dist/helpers/herd_credentials_server.d.ts +76 -0
- package/dist/helpers/herd_credentials_server.js +22 -0
- package/dist/helpers/herd_modules.queries.js +10 -7
- package/dist/helpers/herd_roles.js +13 -148
- package/dist/helpers/herd_roles.queries.d.ts +18 -0
- package/dist/helpers/{herd_roles_internal.js → herd_roles.queries.js} +28 -28
- package/dist/helpers/herds.js +5 -47
- package/dist/helpers/herds.queries.d.ts +8 -1
- package/dist/helpers/herds.queries.js +48 -0
- package/dist/helpers/invitations.js +7 -58
- package/dist/helpers/invitations.queries.d.ts +10 -0
- package/dist/helpers/{invitations_internal.js → invitations.queries.js} +12 -12
- package/dist/helpers/issuers.js +6 -52
- package/dist/helpers/issuers.queries.d.ts +9 -0
- package/dist/helpers/issuers.queries.js +53 -0
- package/dist/helpers/layers.js +2 -20
- package/dist/helpers/layers.queries.d.ts +2 -1
- package/dist/helpers/layers.queries.js +9 -13
- package/dist/helpers/lifecycle_server.d.ts +175 -0
- package/dist/helpers/lifecycle_server.js +38 -0
- package/dist/helpers/localizations.js +5 -42
- package/dist/helpers/localizations.queries.d.ts +8 -0
- package/dist/helpers/localizations.queries.js +45 -0
- package/dist/helpers/maintenance_requests_server.d.ts +124 -0
- package/dist/helpers/maintenance_requests_server.js +34 -0
- package/dist/helpers/manufacturers.js +5 -43
- package/dist/helpers/manufacturers.queries.d.ts +10 -0
- package/dist/helpers/manufacturers.queries.js +46 -0
- package/dist/helpers/media_urls.d.ts +13 -0
- package/dist/helpers/media_urls.js +21 -0
- package/dist/helpers/models.js +8 -80
- package/dist/helpers/models.queries.d.ts +13 -0
- package/dist/helpers/models.queries.js +79 -0
- package/dist/helpers/observations_server.d.ts +51 -0
- package/dist/helpers/observations_server.js +22 -0
- package/dist/helpers/operating_contexts.js +39 -154
- package/dist/helpers/operating_contexts.queries.d.ts +48 -0
- package/dist/helpers/operating_contexts.queries.js +223 -0
- package/dist/helpers/operators.js +4 -57
- package/dist/helpers/operators.queries.d.ts +7 -0
- package/dist/helpers/operators.queries.js +55 -0
- package/dist/helpers/parts.d.ts +0 -87
- package/dist/helpers/parts.js +4 -90
- package/dist/helpers/parts_server.d.ts +260 -0
- package/dist/helpers/parts_server.js +71 -0
- package/dist/helpers/pins_server.d.ts +118 -0
- package/dist/helpers/pins_server.js +38 -0
- package/dist/helpers/plans.js +4 -56
- package/dist/helpers/plans.queries.d.ts +4 -1
- package/dist/helpers/plans.queries.js +39 -12
- package/dist/helpers/points_for_user_server.d.ts +9 -0
- package/dist/helpers/points_for_user_server.js +14 -0
- package/dist/helpers/product_compatibilities.js +6 -78
- package/dist/helpers/product_compatibilities.queries.d.ts +9 -0
- package/dist/helpers/product_compatibilities.queries.js +83 -0
- package/dist/helpers/product_numbers.js +6 -55
- package/dist/helpers/product_numbers.queries.d.ts +9 -0
- package/dist/helpers/product_numbers.queries.js +58 -0
- package/dist/helpers/products.js +6 -54
- package/dist/helpers/products.queries.d.ts +11 -0
- package/dist/helpers/products.queries.js +58 -0
- package/dist/helpers/providers.js +5 -71
- package/dist/helpers/providers.queries.d.ts +5 -1
- package/dist/helpers/providers.queries.js +52 -11
- package/dist/helpers/pubsub_token_server.d.ts +1 -0
- package/dist/helpers/pubsub_token_server.js +5 -2
- package/dist/helpers/segmentations_sam3.js +5 -78
- package/dist/helpers/segmentations_sam3.queries.d.ts +16 -0
- package/dist/helpers/segmentations_sam3.queries.js +81 -0
- package/dist/helpers/sensor_poses_server.d.ts +98 -0
- package/dist/helpers/sensor_poses_server.js +26 -0
- package/dist/helpers/session_incidents_server.d.ts +106 -0
- package/dist/helpers/session_incidents_server.js +22 -0
- package/dist/helpers/session_summaries.d.ts +2 -0
- package/dist/helpers/session_summaries.js +7 -23
- package/dist/helpers/session_summaries.queries.d.ts +6 -3
- package/dist/helpers/session_summaries.queries.js +27 -0
- package/dist/helpers/sessions.js +8 -122
- package/dist/helpers/sessions.queries.d.ts +14 -2
- package/dist/helpers/sessions.queries.js +88 -1
- package/dist/helpers/storage.js +0 -1
- package/dist/helpers/supabase_auth.d.ts +6 -0
- package/dist/helpers/supabase_auth.js +37 -0
- package/dist/helpers/tags.d.ts +0 -1
- package/dist/helpers/tags.js +13 -559
- package/dist/helpers/tags.queries.d.ts +33 -0
- package/dist/helpers/tags.queries.js +454 -0
- package/dist/helpers/user_credentials_server.d.ts +76 -0
- package/dist/helpers/user_credentials_server.js +22 -0
- package/dist/helpers/users.d.ts +2 -2
- package/dist/helpers/users.js +8 -107
- package/dist/helpers/users.queries.d.ts +9 -1
- package/dist/helpers/users.queries.js +107 -0
- package/dist/helpers/versions_software.d.ts +3 -1
- package/dist/helpers/versions_software.js +24 -0
- package/dist/helpers/versions_software_server.d.ts +83 -4
- package/dist/helpers/versions_software_server.js +23 -50
- package/dist/helpers/zones.d.ts +1 -16
- package/dist/helpers/zones.js +4 -104
- package/dist/helpers/zones.queries.d.ts +6 -0
- package/dist/helpers/zones.queries.js +78 -0
- package/dist/hooks/useAuthorizedRealtimeTopics.js +8 -2
- package/dist/hooks/useInfiniteQuery.js +18 -14
- package/dist/hooks/useScoutRealtimeBroadcast.js +8 -6
- package/dist/hooks/useScoutRealtimeDocuments.js +3 -2
- package/dist/hooks/useScoutRefresh.d.ts +9 -25
- package/dist/hooks/useScoutRefresh.js +33 -213
- package/dist/providers/ScoutRefreshProvider.d.ts +1 -1
- package/dist/providers/ScoutRefreshProvider.js +56 -13
- package/dist/server/index.d.ts +77 -0
- package/dist/server/index.js +79 -0
- package/dist/server/middleware.d.ts +2 -0
- package/dist/server/middleware.js +2 -0
- package/dist/server/supabase.d.ts +2 -0
- package/dist/server/supabase.js +2 -0
- package/dist/store/api.d.ts +40 -40
- package/dist/store/api.js +38 -109
- package/dist/store/configureStore.d.ts +0 -55
- package/dist/store/configureStore.js +1 -8
- package/dist/store/hooks.js +1 -0
- package/dist/supabase/client.d.ts +3 -0
- package/dist/supabase/client.js +10 -0
- package/dist/supabase/middleware.d.ts +1 -0
- package/dist/supabase/middleware.js +6 -20
- package/dist/supabase/server.d.ts +7 -2
- package/dist/supabase/server.js +13 -1
- package/dist/types/db.d.ts +2 -2
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.js +5 -0
- package/package.json +53 -4
- package/dist/api_keys/index.d.ts +0 -1
- package/dist/api_keys/index.js +0 -1
- package/dist/helpers/artifacts.internal.d.ts +0 -22
- package/dist/helpers/client_abilities_jwt_keys_internal.d.ts +0 -9
- package/dist/helpers/client_abilities_jwt_keys_internal.js +0 -20
- package/dist/helpers/connectivity.internal.d.ts +0 -10
- package/dist/helpers/connectivity.internal.js +0 -47
- package/dist/helpers/credentials.d.ts +0 -9
- package/dist/helpers/credentials.js +0 -92
- package/dist/helpers/embeddings.internal.d.ts +0 -5
- package/dist/helpers/events.internal.d.ts +0 -13
- package/dist/helpers/herd_roles_internal.d.ts +0 -18
- package/dist/helpers/index.d.ts +0 -56
- package/dist/helpers/index.js +0 -56
- package/dist/helpers/invitations_internal.d.ts +0 -10
- package/dist/helpers/versions_software_internal.d.ts +0 -6
- package/dist/helpers/versions_software_internal.js +0 -53
- package/dist/hooks/useDeviceDisplayName.d.ts +0 -8
- package/dist/hooks/useDeviceDisplayName.js +0 -49
- package/dist/index.d.ts +0 -108
- package/dist/index.js +0 -114
- package/dist/supabase/index.d.ts +0 -2
- package/dist/supabase/index.js +0 -2
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { IWebResponse } from "../types/requests";
|
|
2
|
+
function error(message) {
|
|
3
|
+
return IWebResponse.error(message).to_compatible();
|
|
4
|
+
}
|
|
5
|
+
function page_limit(options) {
|
|
6
|
+
const limit = options?.limit ?? 100;
|
|
7
|
+
return limit < 1 || limit > 500 ? null : limit;
|
|
8
|
+
}
|
|
9
|
+
async function authenticated_user_id(client) {
|
|
10
|
+
const { data, error: authError } = await client.auth.getUser();
|
|
11
|
+
return authError ? null : (data.user?.id ?? null);
|
|
12
|
+
}
|
|
13
|
+
function with_lifecycle_actor(updates, user_id) {
|
|
14
|
+
return updates.lifecycle
|
|
15
|
+
? { ...updates, lifecycle_changed_by: user_id }
|
|
16
|
+
: updates;
|
|
17
|
+
}
|
|
18
|
+
function with_update_actor(updates, user_id) {
|
|
19
|
+
return { ...with_lifecycle_actor(updates, user_id), updated_by: user_id };
|
|
20
|
+
}
|
|
21
|
+
function update_error(updates) {
|
|
22
|
+
if (Object.keys(updates).length === 0)
|
|
23
|
+
return "no fields to update";
|
|
24
|
+
if (updates.lifecycle_reason !== undefined && updates.lifecycle === undefined) {
|
|
25
|
+
return "lifecycle_reason requires lifecycle";
|
|
26
|
+
}
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
async function list_by(client, table, column, value, options) {
|
|
30
|
+
const limit = page_limit(options);
|
|
31
|
+
if (limit == null)
|
|
32
|
+
return error("limit must be between 1 and 500");
|
|
33
|
+
let query = client
|
|
34
|
+
.from(table)
|
|
35
|
+
.select("*")
|
|
36
|
+
.eq(column, value)
|
|
37
|
+
.order("id")
|
|
38
|
+
.limit(limit);
|
|
39
|
+
if (!options?.include_inactive)
|
|
40
|
+
query = query.eq("lifecycle", "active");
|
|
41
|
+
if (options?.after_id != null)
|
|
42
|
+
query = query.gt("id", options.after_id);
|
|
43
|
+
const { data, error: queryError } = await query;
|
|
44
|
+
return queryError
|
|
45
|
+
? error(queryError.message)
|
|
46
|
+
: IWebResponse.success((data ?? [])).to_compatible();
|
|
47
|
+
}
|
|
48
|
+
async function insert_row(client, table, row) {
|
|
49
|
+
const { data, error: queryError } = await client
|
|
50
|
+
.from(table)
|
|
51
|
+
.insert(row)
|
|
52
|
+
.select("*")
|
|
53
|
+
.single();
|
|
54
|
+
return queryError
|
|
55
|
+
? error(queryError.message)
|
|
56
|
+
: IWebResponse.success(data).to_compatible();
|
|
57
|
+
}
|
|
58
|
+
async function insert_with_creator(client, table, row) {
|
|
59
|
+
const user_id = await authenticated_user_id(client);
|
|
60
|
+
if (!user_id)
|
|
61
|
+
return error("authentication required");
|
|
62
|
+
const { data, error: queryError } = await client
|
|
63
|
+
.from(table)
|
|
64
|
+
.insert({ ...row, created_by: user_id })
|
|
65
|
+
.select("*")
|
|
66
|
+
.single();
|
|
67
|
+
return queryError
|
|
68
|
+
? error(queryError.message)
|
|
69
|
+
: IWebResponse.success(data).to_compatible();
|
|
70
|
+
}
|
|
71
|
+
async function patch_row(client, table, id, updates, actor) {
|
|
72
|
+
const invalid = update_error(updates);
|
|
73
|
+
if (invalid)
|
|
74
|
+
return error(invalid);
|
|
75
|
+
const user_id = await authenticated_user_id(client);
|
|
76
|
+
if (!user_id)
|
|
77
|
+
return error("authentication required");
|
|
78
|
+
const payload = actor === "update"
|
|
79
|
+
? with_update_actor(updates, user_id)
|
|
80
|
+
: with_lifecycle_actor(updates, user_id);
|
|
81
|
+
const { data, error: queryError } = await client
|
|
82
|
+
.from(table)
|
|
83
|
+
.update(payload)
|
|
84
|
+
.eq("id", id)
|
|
85
|
+
.select("*")
|
|
86
|
+
.single();
|
|
87
|
+
return queryError
|
|
88
|
+
? error(queryError.message)
|
|
89
|
+
: IWebResponse.success(data).to_compatible();
|
|
90
|
+
}
|
|
91
|
+
export async function get_document_conditions_by_localization_query(client, localization_id, options) {
|
|
92
|
+
return list_by(client, "document_conditions", "localization_id", localization_id, options);
|
|
93
|
+
}
|
|
94
|
+
export async function create_document_condition_query(client, row) {
|
|
95
|
+
return insert_row(client, "document_conditions", row);
|
|
96
|
+
}
|
|
97
|
+
export async function update_document_condition_query(client, id, updates) {
|
|
98
|
+
return patch_row(client, "document_conditions", id, updates, "lifecycle");
|
|
99
|
+
}
|
|
100
|
+
export async function get_operating_context_types_by_localization_query(client, localization_id, options) {
|
|
101
|
+
return list_by(client, "operating_context_types", "localization_id", localization_id, options);
|
|
102
|
+
}
|
|
103
|
+
export async function create_operating_context_type_query(client, row) {
|
|
104
|
+
return insert_row(client, "operating_context_types", row);
|
|
105
|
+
}
|
|
106
|
+
export async function update_operating_context_type_query(client, id, updates) {
|
|
107
|
+
return patch_row(client, "operating_context_types", id, updates, "lifecycle");
|
|
108
|
+
}
|
|
109
|
+
export async function get_operating_context_roles_by_localization_query(client, localization_id, options) {
|
|
110
|
+
return list_by(client, "operating_context_roles", "localization_id", localization_id, options);
|
|
111
|
+
}
|
|
112
|
+
export async function create_operating_context_role_query(client, row) {
|
|
113
|
+
return insert_row(client, "operating_context_roles", row);
|
|
114
|
+
}
|
|
115
|
+
export async function update_operating_context_role_query(client, id, updates) {
|
|
116
|
+
return patch_row(client, "operating_context_roles", id, updates, "lifecycle");
|
|
117
|
+
}
|
|
118
|
+
export async function get_operating_context_equipment_categories_by_localization_query(client, localization_id, options) {
|
|
119
|
+
return list_by(client, "operating_context_equipment_categories", "localization_id", localization_id, options);
|
|
120
|
+
}
|
|
121
|
+
export async function create_operating_context_equipment_category_query(client, row) {
|
|
122
|
+
return insert_row(client, "operating_context_equipment_categories", row);
|
|
123
|
+
}
|
|
124
|
+
export async function update_operating_context_equipment_category_query(client, id, updates) {
|
|
125
|
+
return patch_row(client, "operating_context_equipment_categories", id, updates, "lifecycle");
|
|
126
|
+
}
|
|
127
|
+
export async function get_operating_context_equipment_items_by_category_query(client, equipment_category_id, options) {
|
|
128
|
+
return list_by(client, "operating_context_equipment_items", "equipment_category_id", equipment_category_id, options);
|
|
129
|
+
}
|
|
130
|
+
export async function create_operating_context_equipment_item_query(client, row) {
|
|
131
|
+
return insert_row(client, "operating_context_equipment_items", row);
|
|
132
|
+
}
|
|
133
|
+
export async function update_operating_context_equipment_item_query(client, id, updates) {
|
|
134
|
+
return patch_row(client, "operating_context_equipment_items", id, updates, "lifecycle");
|
|
135
|
+
}
|
|
136
|
+
export async function get_operating_contexts_by_herd_query(client, herd_id, options) {
|
|
137
|
+
return list_by(client, "operating_contexts", "herd_id", herd_id, options);
|
|
138
|
+
}
|
|
139
|
+
export async function get_operating_context_by_id_query(client, id) {
|
|
140
|
+
const { data, error: queryError } = await client
|
|
141
|
+
.from("operating_contexts")
|
|
142
|
+
.select("*")
|
|
143
|
+
.eq("id", id)
|
|
144
|
+
.maybeSingle();
|
|
145
|
+
return queryError
|
|
146
|
+
? error(queryError.message)
|
|
147
|
+
: IWebResponse.success(data).to_compatible();
|
|
148
|
+
}
|
|
149
|
+
export async function create_operating_context_query(client, row) {
|
|
150
|
+
return insert_with_creator(client, "operating_contexts", row);
|
|
151
|
+
}
|
|
152
|
+
export async function update_operating_context_query(client, id, updates) {
|
|
153
|
+
return patch_row(client, "operating_contexts", id, updates, "update");
|
|
154
|
+
}
|
|
155
|
+
export async function get_operating_context_payloads_by_operating_context_query(client, operating_context_id, options) {
|
|
156
|
+
return list_by(client, "operating_context_payloads", "operating_context_id", operating_context_id, options);
|
|
157
|
+
}
|
|
158
|
+
export async function create_operating_context_payload_query(client, row) {
|
|
159
|
+
return insert_with_creator(client, "operating_context_payloads", row);
|
|
160
|
+
}
|
|
161
|
+
export async function update_operating_context_payload_query(client, id, updates) {
|
|
162
|
+
return patch_row(client, "operating_context_payloads", id, updates, "update");
|
|
163
|
+
}
|
|
164
|
+
export async function get_operating_context_role_assignments_by_operating_context_query(client, operating_context_id, options) {
|
|
165
|
+
return list_by(client, "operating_context_role_assignments", "operating_context_id", operating_context_id, options);
|
|
166
|
+
}
|
|
167
|
+
export async function create_operating_context_role_assignment_query(client, row) {
|
|
168
|
+
return insert_row(client, "operating_context_role_assignments", row);
|
|
169
|
+
}
|
|
170
|
+
export async function update_operating_context_role_assignment_query(client, id, updates) {
|
|
171
|
+
return patch_row(client, "operating_context_role_assignments", id, updates, "lifecycle");
|
|
172
|
+
}
|
|
173
|
+
export async function get_operating_context_devices_by_operating_context_query(client, operating_context_id, options) {
|
|
174
|
+
return list_by(client, "operating_contexts_devices", "operating_context_id", operating_context_id, options);
|
|
175
|
+
}
|
|
176
|
+
export async function create_operating_context_device_query(client, row) {
|
|
177
|
+
return insert_row(client, "operating_contexts_devices", row);
|
|
178
|
+
}
|
|
179
|
+
export async function update_operating_context_device_query(client, id, updates) {
|
|
180
|
+
return patch_row(client, "operating_contexts_devices", id, updates, "lifecycle");
|
|
181
|
+
}
|
|
182
|
+
export async function get_operating_context_equipment_requirements_by_operating_context_query(client, operating_context_id, options) {
|
|
183
|
+
return list_by(client, "operating_context_equipment_requirements", "operating_context_id", operating_context_id, options);
|
|
184
|
+
}
|
|
185
|
+
export async function create_operating_context_equipment_requirement_query(client, row) {
|
|
186
|
+
return insert_row(client, "operating_context_equipment_requirements", row);
|
|
187
|
+
}
|
|
188
|
+
export async function update_operating_context_equipment_requirement_query(client, id, updates) {
|
|
189
|
+
return patch_row(client, "operating_context_equipment_requirements", id, updates, "lifecycle");
|
|
190
|
+
}
|
|
191
|
+
export async function get_operating_context_regions_by_operating_context_query(client, operating_context_id, options) {
|
|
192
|
+
return list_by(client, "operating_context_regions", "operating_context_id", operating_context_id, options);
|
|
193
|
+
}
|
|
194
|
+
export async function create_operating_context_region_query(client, row) {
|
|
195
|
+
return insert_with_creator(client, "operating_context_regions", row);
|
|
196
|
+
}
|
|
197
|
+
export async function update_operating_context_region_query(client, id, updates) {
|
|
198
|
+
return patch_row(client, "operating_context_regions", id, updates, "update");
|
|
199
|
+
}
|
|
200
|
+
export async function get_operating_context_risks_by_operating_context_query(client, operating_context_id, options) {
|
|
201
|
+
return list_by(client, "operating_context_risks", "operating_context_id", operating_context_id, options);
|
|
202
|
+
}
|
|
203
|
+
export async function create_operating_context_risk_query(client, row) {
|
|
204
|
+
return insert_with_creator(client, "operating_context_risks", row);
|
|
205
|
+
}
|
|
206
|
+
export async function update_operating_context_risk_query(client, id, updates) {
|
|
207
|
+
return patch_row(client, "operating_context_risks", id, updates, "update");
|
|
208
|
+
}
|
|
209
|
+
export async function get_operating_context_weather_snapshots_query(client, operating_context_id, options) {
|
|
210
|
+
if (options?.limit != null &&
|
|
211
|
+
(options.limit < 1 || options.limit > 500)) {
|
|
212
|
+
return error("limit must be between 1 and 500");
|
|
213
|
+
}
|
|
214
|
+
const { data, error: queryError } = await client.rpc("get_operating_context_weather_snapshots", {
|
|
215
|
+
operating_context_id_caller: operating_context_id,
|
|
216
|
+
limit_caller: options?.limit,
|
|
217
|
+
cursor_collected_at: options?.cursor?.collected_at,
|
|
218
|
+
cursor_id: options?.cursor?.id,
|
|
219
|
+
});
|
|
220
|
+
return queryError
|
|
221
|
+
? error(queryError.message)
|
|
222
|
+
: IWebResponse.success(data ?? []).to_compatible();
|
|
223
|
+
}
|
|
@@ -1,64 +1,11 @@
|
|
|
1
|
-
"use server";
|
|
2
1
|
import { newServerClient } from "../supabase/server";
|
|
3
|
-
import {
|
|
4
|
-
// Get operators by session id (server id)
|
|
2
|
+
import { get_operators_by_session_id_filtered_query, get_operators_by_session_id_query, get_operators_by_user_id_query, } from "./operators.queries";
|
|
5
3
|
export async function server_get_operators_by_session_id(sessionId) {
|
|
6
|
-
|
|
7
|
-
const { data, error } = await supabase
|
|
8
|
-
.from("operators")
|
|
9
|
-
.select("*")
|
|
10
|
-
.eq("session_id", sessionId)
|
|
11
|
-
.order("created_at", { ascending: false });
|
|
12
|
-
if (error) {
|
|
13
|
-
console.warn("Error fetching operators by session id:", error.message);
|
|
14
|
-
return {
|
|
15
|
-
status: EnumWebResponse.ERROR,
|
|
16
|
-
msg: error.message,
|
|
17
|
-
data: [],
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
return IWebResponse.success(data || []).to_compatible();
|
|
4
|
+
return get_operators_by_session_id_query(await newServerClient(), sessionId);
|
|
21
5
|
}
|
|
22
|
-
// Get all operators for a specific user
|
|
23
6
|
export async function server_get_operators_by_user_id(userId) {
|
|
24
|
-
|
|
25
|
-
const { data, error } = await supabase
|
|
26
|
-
.from("operators")
|
|
27
|
-
.select("*")
|
|
28
|
-
.eq("user_id", userId)
|
|
29
|
-
.order("created_at", { ascending: false });
|
|
30
|
-
if (error) {
|
|
31
|
-
console.warn("Error fetching operators by user id:", error.message);
|
|
32
|
-
return {
|
|
33
|
-
status: EnumWebResponse.ERROR,
|
|
34
|
-
msg: error.message,
|
|
35
|
-
data: [],
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
return IWebResponse.success(data || []).to_compatible();
|
|
7
|
+
return get_operators_by_user_id_query(await newServerClient(), userId);
|
|
39
8
|
}
|
|
40
|
-
// Get operators by session id with additional filters
|
|
41
9
|
export async function server_get_operators_by_session_id_filtered(sessionId, action, timestampAfter) {
|
|
42
|
-
|
|
43
|
-
let query = supabase
|
|
44
|
-
.from("operators")
|
|
45
|
-
.select("*")
|
|
46
|
-
.eq("session_id", sessionId);
|
|
47
|
-
// Apply optional filters
|
|
48
|
-
if (action) {
|
|
49
|
-
query = query.eq("action", action);
|
|
50
|
-
}
|
|
51
|
-
if (timestampAfter) {
|
|
52
|
-
query = query.gte("timestamp", timestampAfter);
|
|
53
|
-
}
|
|
54
|
-
const { data, error } = await query.order("timestamp", { ascending: false });
|
|
55
|
-
if (error) {
|
|
56
|
-
console.warn("Error fetching filtered operators by session id:", error.message);
|
|
57
|
-
return {
|
|
58
|
-
status: EnumWebResponse.ERROR,
|
|
59
|
-
msg: error.message,
|
|
60
|
-
data: [],
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
return IWebResponse.success(data || []).to_compatible();
|
|
10
|
+
return get_operators_by_session_id_filtered_query(await newServerClient(), sessionId, action, timestampAfter);
|
|
64
11
|
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SupabaseClient } from "@supabase/supabase-js";
|
|
2
|
+
import { IOperator } from "../types/db";
|
|
3
|
+
import { IWebResponseCompatible } from "../types/requests";
|
|
4
|
+
import { Database } from "../types/supabase";
|
|
5
|
+
export declare function get_operators_by_session_id_query(client: SupabaseClient<Database>, sessionId: number): Promise<IWebResponseCompatible<IOperator[]>>;
|
|
6
|
+
export declare function get_operators_by_user_id_query(client: SupabaseClient<Database>, userId: string): Promise<IWebResponseCompatible<IOperator[]>>;
|
|
7
|
+
export declare function get_operators_by_session_id_filtered_query(client: SupabaseClient<Database>, sessionId: number, action?: string, timestampAfter?: string): Promise<IWebResponseCompatible<IOperator[]>>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { EnumWebResponse, IWebResponse, } from "../types/requests";
|
|
2
|
+
export async function get_operators_by_session_id_query(client, sessionId) {
|
|
3
|
+
const { data, error } = await client
|
|
4
|
+
.from("operators")
|
|
5
|
+
.select("*")
|
|
6
|
+
.eq("session_id", sessionId)
|
|
7
|
+
.order("created_at", { ascending: false });
|
|
8
|
+
if (error) {
|
|
9
|
+
console.warn("Error fetching operators by session id:", error.message);
|
|
10
|
+
return {
|
|
11
|
+
status: EnumWebResponse.ERROR,
|
|
12
|
+
msg: error.message,
|
|
13
|
+
data: [],
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
return IWebResponse.success(data || []).to_compatible();
|
|
17
|
+
}
|
|
18
|
+
export async function get_operators_by_user_id_query(client, userId) {
|
|
19
|
+
const { data, error } = await client
|
|
20
|
+
.from("operators")
|
|
21
|
+
.select("*")
|
|
22
|
+
.eq("user_id", userId)
|
|
23
|
+
.order("created_at", { ascending: false });
|
|
24
|
+
if (error) {
|
|
25
|
+
console.warn("Error fetching operators by user id:", error.message);
|
|
26
|
+
return {
|
|
27
|
+
status: EnumWebResponse.ERROR,
|
|
28
|
+
msg: error.message,
|
|
29
|
+
data: [],
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
return IWebResponse.success(data || []).to_compatible();
|
|
33
|
+
}
|
|
34
|
+
export async function get_operators_by_session_id_filtered_query(client, sessionId, action, timestampAfter) {
|
|
35
|
+
let query = client
|
|
36
|
+
.from("operators")
|
|
37
|
+
.select("*")
|
|
38
|
+
.eq("session_id", sessionId);
|
|
39
|
+
if (action) {
|
|
40
|
+
query = query.eq("action", action);
|
|
41
|
+
}
|
|
42
|
+
if (timestampAfter) {
|
|
43
|
+
query = query.gte("timestamp", timestampAfter);
|
|
44
|
+
}
|
|
45
|
+
const { data, error } = await query.order("timestamp", { ascending: false });
|
|
46
|
+
if (error) {
|
|
47
|
+
console.warn("Error fetching filtered operators by session id:", error.message);
|
|
48
|
+
return {
|
|
49
|
+
status: EnumWebResponse.ERROR,
|
|
50
|
+
msg: error.message,
|
|
51
|
+
data: [],
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
return IWebResponse.success(data || []).to_compatible();
|
|
55
|
+
}
|
package/dist/helpers/parts.d.ts
CHANGED
|
@@ -3,108 +3,21 @@ import { EntityLifecycle, IPart, IPartWithProduct, PartInsert } from "../types/d
|
|
|
3
3
|
import { IWebResponseCompatible } from "../types/requests";
|
|
4
4
|
import { SupabaseClient } from "@supabase/supabase-js";
|
|
5
5
|
import { LifecycleUpdateOptions } from "./lifecycle";
|
|
6
|
-
/**
|
|
7
|
-
* Retrieves all active parts for a specific device
|
|
8
|
-
* @param client - Supabase client instance
|
|
9
|
-
* @param device_id - ID of the device to get parts for
|
|
10
|
-
*/
|
|
11
6
|
export declare function get_parts_by_device_id(client: SupabaseClient<Database>, device_id: number): Promise<IWebResponseCompatible<IPart[]>>;
|
|
12
|
-
/**
|
|
13
|
-
* Retrieves a single active part by its ID
|
|
14
|
-
* @param client - Supabase client instance
|
|
15
|
-
* @param part_id - ID of the part to retrieve
|
|
16
|
-
*/
|
|
17
7
|
export declare function get_part_by_id(client: SupabaseClient<Database>, part_id: number): Promise<IWebResponseCompatible<IPart | null>>;
|
|
18
|
-
/**
|
|
19
|
-
* Retrieves all active parts with a specific serial number
|
|
20
|
-
* @param client - Supabase client instance
|
|
21
|
-
* @param serial_number - Serial number to search for
|
|
22
|
-
*/
|
|
23
8
|
export declare function get_parts_by_serial_number(client: SupabaseClient<Database>, serial_number: string): Promise<IWebResponseCompatible<IPart[]>>;
|
|
24
|
-
/**
|
|
25
|
-
* Retrieves all active parts with a specific product number
|
|
26
|
-
* @param client - Supabase client instance
|
|
27
|
-
* @param product_number - Product number to search for
|
|
28
|
-
*/
|
|
29
9
|
export declare function get_parts_by_product_number(client: SupabaseClient<Database>, product_number: string): Promise<IWebResponseCompatible<IPart[]>>;
|
|
30
|
-
/**
|
|
31
|
-
* Retrieves all parts with a specific lifecycle state
|
|
32
|
-
* @param client - Supabase client instance
|
|
33
|
-
* @param lifecycle - Lifecycle state to filter by
|
|
34
|
-
*/
|
|
35
10
|
export declare function get_parts_by_lifecycle(client: SupabaseClient<Database>, lifecycle: EntityLifecycle): Promise<IWebResponseCompatible<IPart[]>>;
|
|
36
11
|
/** @deprecated Use get_parts_by_lifecycle */
|
|
37
12
|
export declare const get_parts_by_status: typeof get_parts_by_lifecycle;
|
|
38
|
-
/**
|
|
39
|
-
* Creates a new part with validation
|
|
40
|
-
* @param client - Supabase client instance
|
|
41
|
-
* @param newPart - Part data to create
|
|
42
|
-
*/
|
|
43
13
|
export declare function create_part(client: SupabaseClient<Database>, newPart: PartInsert): Promise<IWebResponseCompatible<IPart | null>>;
|
|
44
|
-
/**
|
|
45
|
-
* Updates an existing part
|
|
46
|
-
* @param client - Supabase client instance
|
|
47
|
-
* @param part_id - ID of the part to update
|
|
48
|
-
* @param updatedPart - Partial part data to update
|
|
49
|
-
*/
|
|
50
14
|
export declare function update_part(client: SupabaseClient<Database>, part_id: number, updatedPart: Partial<PartInsert>): Promise<IWebResponseCompatible<IPart | null>>;
|
|
51
|
-
/**
|
|
52
|
-
* Marks an active part as deleted (lifecycle)
|
|
53
|
-
* @param client - Supabase client instance
|
|
54
|
-
* @param part_id - ID of the part to delete
|
|
55
|
-
* @param options - Optional lifecycle metadata
|
|
56
|
-
*/
|
|
57
15
|
export declare function delete_part(client: SupabaseClient<Database>, part_id: number, options?: LifecycleUpdateOptions): Promise<IWebResponseCompatible<IPart | null>>;
|
|
58
|
-
/**
|
|
59
|
-
* Updates the lifecycle of a specific part
|
|
60
|
-
* @param client - Supabase client instance
|
|
61
|
-
* @param part_id - ID of the part to update
|
|
62
|
-
* @param lifecycle - New lifecycle state
|
|
63
|
-
* @param options - Optional lifecycle metadata
|
|
64
|
-
*/
|
|
65
16
|
export declare function update_part_status(client: SupabaseClient<Database>, part_id: number, lifecycle: EntityLifecycle, options?: LifecycleUpdateOptions): Promise<IWebResponseCompatible<IPart | null>>;
|
|
66
|
-
/**
|
|
67
|
-
* Retrieves all active parts associated with a certificate
|
|
68
|
-
* @param client - Supabase client instance
|
|
69
|
-
* @param certificate_id - ID of the certificate to search for
|
|
70
|
-
*/
|
|
71
17
|
export declare function get_parts_by_certificate_id(client: SupabaseClient<Database>, certificate_id: number): Promise<IWebResponseCompatible<IPart[]>>;
|
|
72
|
-
/**
|
|
73
|
-
* Retrieves all active parts for a herd
|
|
74
|
-
* @param client - Supabase client instance
|
|
75
|
-
* @param herd_id - ID of the herd to get parts for
|
|
76
|
-
*/
|
|
77
18
|
export declare function get_parts_by_herd_id(client: SupabaseClient<Database>, herd_id: number): Promise<IWebResponseCompatible<IPart[]>>;
|
|
78
|
-
/**
|
|
79
|
-
* Retrieves active parts for all devices across many herds in one query,
|
|
80
|
-
* grouped by device_id.
|
|
81
|
-
* @param client - Supabase client instance
|
|
82
|
-
* @param herd_ids - IDs of the herds to get parts for
|
|
83
|
-
*/
|
|
84
19
|
export declare function get_parts_by_herd_ids(client: SupabaseClient<Database>, herd_ids: number[]): Promise<IWebResponseCompatible<Record<number, IPartWithProduct[]>>>;
|
|
85
|
-
/**
|
|
86
|
-
* Restores a deleted part to active lifecycle
|
|
87
|
-
* @param client - Supabase client instance
|
|
88
|
-
* @param part_id - ID of the part to restore
|
|
89
|
-
* @param options - Optional lifecycle metadata
|
|
90
|
-
*/
|
|
91
20
|
export declare function restore_part(client: SupabaseClient<Database>, part_id: number, options?: LifecycleUpdateOptions): Promise<IWebResponseCompatible<IPart | null>>;
|
|
92
|
-
/**
|
|
93
|
-
* Permanently deletes a part that is already in deleted lifecycle
|
|
94
|
-
* @param client - Supabase client instance
|
|
95
|
-
* @param part_id - ID of the part to permanently delete
|
|
96
|
-
*/
|
|
97
21
|
export declare function hard_delete_part(client: SupabaseClient<Database>, part_id: number): Promise<IWebResponseCompatible<IPart | null>>;
|
|
98
|
-
/**
|
|
99
|
-
* Retrieves all deleted parts for a specific device
|
|
100
|
-
* @param client - Supabase client instance
|
|
101
|
-
* @param device_id - ID of the device to get deleted parts for
|
|
102
|
-
*/
|
|
103
22
|
export declare function get_deleted_parts_by_device_id(client: SupabaseClient<Database>, device_id: number): Promise<IWebResponseCompatible<IPart[]>>;
|
|
104
|
-
/**
|
|
105
|
-
* Retrieves a part by its composite unique constraint (product + serial)
|
|
106
|
-
* @param client - Supabase client instance
|
|
107
|
-
* @param product_number - Product number to search for
|
|
108
|
-
* @param serial_number - Serial number to search for
|
|
109
|
-
*/
|
|
110
23
|
export declare function get_parts_by_product_and_serial(client: SupabaseClient<Database>, product_number: string, serial_number: string): Promise<IWebResponseCompatible<IPart | null>>;
|
package/dist/helpers/parts.js
CHANGED
|
@@ -1,10 +1,5 @@
|
|
|
1
1
|
import { IWebResponse } from "../types/requests";
|
|
2
2
|
import { update_part_lifecycle } from "./lifecycle";
|
|
3
|
-
/**
|
|
4
|
-
* Retrieves all active parts for a specific device
|
|
5
|
-
* @param client - Supabase client instance
|
|
6
|
-
* @param device_id - ID of the device to get parts for
|
|
7
|
-
*/
|
|
8
3
|
export async function get_parts_by_device_id(client, device_id) {
|
|
9
4
|
const { data, error } = await client
|
|
10
5
|
.from("parts")
|
|
@@ -20,11 +15,6 @@ export async function get_parts_by_device_id(client, device_id) {
|
|
|
20
15
|
}
|
|
21
16
|
return IWebResponse.success(data).to_compatible();
|
|
22
17
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Retrieves a single active part by its ID
|
|
25
|
-
* @param client - Supabase client instance
|
|
26
|
-
* @param part_id - ID of the part to retrieve
|
|
27
|
-
*/
|
|
28
18
|
export async function get_part_by_id(client, part_id) {
|
|
29
19
|
const { data, error } = await client
|
|
30
20
|
.from("parts")
|
|
@@ -40,11 +30,6 @@ export async function get_part_by_id(client, part_id) {
|
|
|
40
30
|
}
|
|
41
31
|
return IWebResponse.success(data).to_compatible();
|
|
42
32
|
}
|
|
43
|
-
/**
|
|
44
|
-
* Retrieves all active parts with a specific serial number
|
|
45
|
-
* @param client - Supabase client instance
|
|
46
|
-
* @param serial_number - Serial number to search for
|
|
47
|
-
*/
|
|
48
33
|
export async function get_parts_by_serial_number(client, serial_number) {
|
|
49
34
|
const { data, error } = await client
|
|
50
35
|
.from("parts")
|
|
@@ -60,11 +45,6 @@ export async function get_parts_by_serial_number(client, serial_number) {
|
|
|
60
45
|
}
|
|
61
46
|
return IWebResponse.success(data).to_compatible();
|
|
62
47
|
}
|
|
63
|
-
/**
|
|
64
|
-
* Retrieves all active parts with a specific product number
|
|
65
|
-
* @param client - Supabase client instance
|
|
66
|
-
* @param product_number - Product number to search for
|
|
67
|
-
*/
|
|
68
48
|
export async function get_parts_by_product_number(client, product_number) {
|
|
69
49
|
const { data, error } = await client
|
|
70
50
|
.from("parts")
|
|
@@ -80,11 +60,6 @@ export async function get_parts_by_product_number(client, product_number) {
|
|
|
80
60
|
}
|
|
81
61
|
return IWebResponse.success(data).to_compatible();
|
|
82
62
|
}
|
|
83
|
-
/**
|
|
84
|
-
* Retrieves all parts with a specific lifecycle state
|
|
85
|
-
* @param client - Supabase client instance
|
|
86
|
-
* @param lifecycle - Lifecycle state to filter by
|
|
87
|
-
*/
|
|
88
63
|
export async function get_parts_by_lifecycle(client, lifecycle) {
|
|
89
64
|
const { data, error } = await client
|
|
90
65
|
.from("parts")
|
|
@@ -101,13 +76,8 @@ export async function get_parts_by_lifecycle(client, lifecycle) {
|
|
|
101
76
|
}
|
|
102
77
|
/** @deprecated Use get_parts_by_lifecycle */
|
|
103
78
|
export const get_parts_by_status = get_parts_by_lifecycle;
|
|
104
|
-
/**
|
|
105
|
-
* Creates a new part with validation
|
|
106
|
-
* @param client - Supabase client instance
|
|
107
|
-
* @param newPart - Part data to create
|
|
108
|
-
*/
|
|
109
79
|
export async function create_part(client, newPart) {
|
|
110
|
-
// part
|
|
80
|
+
// A part belongs to one device or one herd.
|
|
111
81
|
const scope_count = [newPart.device_id, newPart.herd_id].filter((scope) => scope != null).length;
|
|
112
82
|
if (scope_count !== 1) {
|
|
113
83
|
return IWebResponse.error("exactly one of device_id or herd_id is required").to_compatible();
|
|
@@ -131,14 +101,7 @@ export async function create_part(client, newPart) {
|
|
|
131
101
|
}
|
|
132
102
|
return IWebResponse.success(data).to_compatible();
|
|
133
103
|
}
|
|
134
|
-
/**
|
|
135
|
-
* Updates an existing part
|
|
136
|
-
* @param client - Supabase client instance
|
|
137
|
-
* @param part_id - ID of the part to update
|
|
138
|
-
* @param updatedPart - Partial part data to update
|
|
139
|
-
*/
|
|
140
104
|
export async function update_part(client, part_id, updatedPart) {
|
|
141
|
-
// Remove fields that shouldn't be updated
|
|
142
105
|
const updateData = { ...updatedPart };
|
|
143
106
|
delete updateData.id;
|
|
144
107
|
delete updateData.created_at;
|
|
@@ -156,12 +119,6 @@ export async function update_part(client, part_id, updatedPart) {
|
|
|
156
119
|
}
|
|
157
120
|
return IWebResponse.success(data).to_compatible();
|
|
158
121
|
}
|
|
159
|
-
/**
|
|
160
|
-
* Marks an active part as deleted (lifecycle)
|
|
161
|
-
* @param client - Supabase client instance
|
|
162
|
-
* @param part_id - ID of the part to delete
|
|
163
|
-
* @param options - Optional lifecycle metadata
|
|
164
|
-
*/
|
|
165
122
|
export async function delete_part(client, part_id, options) {
|
|
166
123
|
const { data, error } = await client
|
|
167
124
|
.from("parts")
|
|
@@ -186,21 +143,9 @@ export async function delete_part(client, part_id, options) {
|
|
|
186
143
|
}
|
|
187
144
|
return IWebResponse.success(data).to_compatible();
|
|
188
145
|
}
|
|
189
|
-
/**
|
|
190
|
-
* Updates the lifecycle of a specific part
|
|
191
|
-
* @param client - Supabase client instance
|
|
192
|
-
* @param part_id - ID of the part to update
|
|
193
|
-
* @param lifecycle - New lifecycle state
|
|
194
|
-
* @param options - Optional lifecycle metadata
|
|
195
|
-
*/
|
|
196
146
|
export async function update_part_status(client, part_id, lifecycle, options) {
|
|
197
147
|
return update_part_lifecycle(client, part_id, lifecycle, options);
|
|
198
148
|
}
|
|
199
|
-
/**
|
|
200
|
-
* Retrieves all active parts associated with a certificate
|
|
201
|
-
* @param client - Supabase client instance
|
|
202
|
-
* @param certificate_id - ID of the certificate to search for
|
|
203
|
-
*/
|
|
204
149
|
export async function get_parts_by_certificate_id(client, certificate_id) {
|
|
205
150
|
const { data, error } = await client
|
|
206
151
|
.from("parts")
|
|
@@ -216,11 +161,6 @@ export async function get_parts_by_certificate_id(client, certificate_id) {
|
|
|
216
161
|
}
|
|
217
162
|
return IWebResponse.success(data).to_compatible();
|
|
218
163
|
}
|
|
219
|
-
/**
|
|
220
|
-
* Retrieves all active parts for a herd
|
|
221
|
-
* @param client - Supabase client instance
|
|
222
|
-
* @param herd_id - ID of the herd to get parts for
|
|
223
|
-
*/
|
|
224
164
|
export async function get_parts_by_herd_id(client, herd_id) {
|
|
225
165
|
const { data, error } = await client.rpc("get_parts_for_herd", {
|
|
226
166
|
herd_id_caller: herd_id,
|
|
@@ -230,12 +170,6 @@ export async function get_parts_by_herd_id(client, herd_id) {
|
|
|
230
170
|
}
|
|
231
171
|
return IWebResponse.success(data ?? []).to_compatible();
|
|
232
172
|
}
|
|
233
|
-
/**
|
|
234
|
-
* Retrieves active parts for all devices across many herds in one query,
|
|
235
|
-
* grouped by device_id.
|
|
236
|
-
* @param client - Supabase client instance
|
|
237
|
-
* @param herd_ids - IDs of the herds to get parts for
|
|
238
|
-
*/
|
|
239
173
|
export async function get_parts_by_herd_ids(client, herd_ids) {
|
|
240
174
|
var _a;
|
|
241
175
|
if (herd_ids.length === 0) {
|
|
@@ -246,7 +180,9 @@ export async function get_parts_by_herd_ids(client, herd_ids) {
|
|
|
246
180
|
.select(`
|
|
247
181
|
*,
|
|
248
182
|
devices!parts_device_id_fkey(herd_id),
|
|
249
|
-
product_numbers!parts_product_number_fkey(
|
|
183
|
+
product_numbers!parts_product_number_fkey(
|
|
184
|
+
products!product_numbers_product_id_fkey(*)
|
|
185
|
+
)
|
|
250
186
|
`)
|
|
251
187
|
.in("devices.herd_id", herd_ids)
|
|
252
188
|
.eq("lifecycle", "active")
|
|
@@ -268,12 +204,6 @@ export async function get_parts_by_herd_ids(client, herd_ids) {
|
|
|
268
204
|
}
|
|
269
205
|
return IWebResponse.success(grouped).to_compatible();
|
|
270
206
|
}
|
|
271
|
-
/**
|
|
272
|
-
* Restores a deleted part to active lifecycle
|
|
273
|
-
* @param client - Supabase client instance
|
|
274
|
-
* @param part_id - ID of the part to restore
|
|
275
|
-
* @param options - Optional lifecycle metadata
|
|
276
|
-
*/
|
|
277
207
|
export async function restore_part(client, part_id, options) {
|
|
278
208
|
const { data, error } = await client
|
|
279
209
|
.from("parts")
|
|
@@ -298,11 +228,6 @@ export async function restore_part(client, part_id, options) {
|
|
|
298
228
|
}
|
|
299
229
|
return IWebResponse.success(data).to_compatible();
|
|
300
230
|
}
|
|
301
|
-
/**
|
|
302
|
-
* Permanently deletes a part that is already in deleted lifecycle
|
|
303
|
-
* @param client - Supabase client instance
|
|
304
|
-
* @param part_id - ID of the part to permanently delete
|
|
305
|
-
*/
|
|
306
231
|
export async function hard_delete_part(client, part_id) {
|
|
307
232
|
const { data, error } = await client
|
|
308
233
|
.from("parts")
|
|
@@ -319,11 +244,6 @@ export async function hard_delete_part(client, part_id) {
|
|
|
319
244
|
}
|
|
320
245
|
return IWebResponse.success(data).to_compatible();
|
|
321
246
|
}
|
|
322
|
-
/**
|
|
323
|
-
* Retrieves all deleted parts for a specific device
|
|
324
|
-
* @param client - Supabase client instance
|
|
325
|
-
* @param device_id - ID of the device to get deleted parts for
|
|
326
|
-
*/
|
|
327
247
|
export async function get_deleted_parts_by_device_id(client, device_id) {
|
|
328
248
|
const { data, error } = await client
|
|
329
249
|
.from("parts")
|
|
@@ -339,12 +259,6 @@ export async function get_deleted_parts_by_device_id(client, device_id) {
|
|
|
339
259
|
}
|
|
340
260
|
return IWebResponse.success(data).to_compatible();
|
|
341
261
|
}
|
|
342
|
-
/**
|
|
343
|
-
* Retrieves a part by its composite unique constraint (product + serial)
|
|
344
|
-
* @param client - Supabase client instance
|
|
345
|
-
* @param product_number - Product number to search for
|
|
346
|
-
* @param serial_number - Serial number to search for
|
|
347
|
-
*/
|
|
348
262
|
export async function get_parts_by_product_and_serial(client, product_number, serial_number) {
|
|
349
263
|
const { data, error } = await client
|
|
350
264
|
.from("parts")
|