refactor(events): harden V3 String-Only ID vision and fix Session Alert store error

- Standardized Event module logic files to strictly use random string IDs, ensuring frontend consistency and avoiding 'Integer Trap' 404s.
- Refactored 'ae_comp__event_session_alert.svelte' to accept a plain object instead of a store/observable, resolving the 'store_invalid_shape' error in list loops.
- Updated all callers of the alert component to pass unwrapped session objects.
- Cleaned up event-related UI components to remove redundant '_random' field lookups and align with V3 CRUD patterns.
- Updated project metadata (GEMINI.md, TODO.md) to reflect the new memory structure and latest hardened state.
This commit is contained in:
Scott Idem
2026-01-27 12:18:12 -05:00
parent a704779d1b
commit 30413e32d2
15 changed files with 589 additions and 473 deletions

View File

@@ -14,7 +14,7 @@ import { load_ae_obj_li__event_file } from '$lib/ae_events/ae_events__event_file
const ae_promises: key_val = {};
// Updated 2026-01-26 (Stale-While-Revalidate Optimization)
// Updated 2026-01-27 to V3 String-Only ID Standard
export async function load_ae_obj_id__event({
api_cfg,
event_id,
@@ -42,12 +42,10 @@ export async function load_ae_obj_id__event({
console.log(`*** load_ae_obj_id__event() *** event_id=${event_id} (SWR Optimization)`);
}
let cached_event: any = null;
// 1. FAST PATH: Return cached data immediately
if (try_cache) {
try {
cached_event = await db_events.event.get(event_id);
const cached_event = await db_events.event.get(event_id);
if (cached_event) {
if (log_lvl) console.log('EVENT LOAD: Cache hit. Returning stale data immediately.');
@@ -91,7 +89,7 @@ async function _refresh_event_v3_background({
}
try {
const event_obj_get_result = await api.get_ae_obj_v3({
const result = await api.get_ae_obj_v3({
api_cfg: api_cfg,
obj_type: 'event',
obj_id: event_id,
@@ -99,22 +97,24 @@ async function _refresh_event_v3_background({
log_lvl: log_lvl
});
if (event_obj_get_result) {
if (result) {
let processed_obj = result;
if (try_cache) {
const processed_obj_li = await process_ae_obj__event_props({
obj_li: [event_obj_get_result],
const processed = await process_ae_obj__event_props({
obj_li: [result],
log_lvl: log_lvl
});
processed_obj = processed[0];
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'event',
obj_li: processed_obj_li,
obj_li: processed,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
}
return await _handle_nested_loads(event_obj_get_result, {
return await _handle_nested_loads(processed_obj, {
api_cfg, inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_template_li, log_lvl
});
}
@@ -128,7 +128,8 @@ async function _refresh_event_v3_background({
* Shared logic for loading nested child collections
*/
async function _handle_nested_loads(event_obj: any, { api_cfg, inc_device_li, inc_file_li, inc_location_li, inc_session_li, inc_template_li, log_lvl }: any) {
const current_event_id = event_obj.event_id_random || event_obj.event_id || event_obj.id;
// String-Only ID Vision: the '_id' field IS the string ID
const current_event_id = event_obj.id || event_obj.event_id;
// Use Promise.all for concurrent nested loads to further reduce delay
const tasks = [];
@@ -180,7 +181,7 @@ async function _handle_nested_loads(event_obj: any, { api_cfg, inc_device_li, in
return event_obj;
}
// Updated 2026-01-06
// Updated 2026-01-27 to V3 String-Only ID Standard
export async function load_ae_obj_li__event({
api_cfg,
for_obj_type = 'account',
@@ -224,20 +225,17 @@ export async function load_ae_obj_li__event({
let promise;
if (qry_conference !== null) {
// V3 Search now permits 'conference' field.
const search_query: any = {
and: [{ field: 'conference', op: 'eq', value: qry_conference }]
};
// Fix for "Integer Trap": Inject account context directly into search body and remove from URL params
if (for_obj_id) {
search_query.and.push({ field: 'account_id_random', op: 'eq', value: for_obj_id });
search_query.and.push({ field: `${for_obj_type}_id`, op: 'eq', value: for_obj_id });
}
promise = api.search_ae_obj_v3({
api_cfg,
obj_type: 'event',
// Headers for Auth context
headers: { 'x-account-id': for_obj_id },
search_query,
enabled,
@@ -265,29 +263,25 @@ export async function load_ae_obj_li__event({
}
try {
const event_obj_li_get_result = await promise;
if (event_obj_li_get_result) {
let filtered_results = event_obj_li_get_result;
// Optional: Keep local filter as a fallback safety
if (qry_conference !== null) {
filtered_results = event_obj_li_get_result.filter((ev: any) => ev.conference === qry_conference);
}
const result_li = await promise;
if (result_li) {
let processed_results = result_li;
if (try_cache) {
const processed_obj_li = await process_ae_obj__event_props({
obj_li: filtered_results,
const processed = await process_ae_obj__event_props({
obj_li: result_li,
log_lvl: log_lvl
});
processed_results = processed;
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'event',
obj_li: processed_obj_li,
obj_li: processed,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
}
ae_promises.load__event_obj_li = filtered_results;
ae_promises.load__event_obj_li = processed_results;
} else {
console.log('No results returned from API.');
if (try_cache) {
@@ -313,7 +307,7 @@ export async function load_ae_obj_li__event({
if (inc_session_li && ae_promises.load__event_obj_li) {
for (const event_obj of ae_promises.load__event_obj_li) {
const current_event_id = event_obj.event_id || event_obj.id;
const current_event_id = event_obj.id || event_obj.event_id;
event_obj.event_session_obj_li = await load_ae_obj_li__event_session({
api_cfg,
for_obj_type: 'event',
@@ -346,28 +340,33 @@ export async function create_ae_obj__event({
api_cfg,
obj_type: 'event',
fields: {
account_id_random: account_id,
account_id,
...data_kv
},
params,
log_lvl
});
if (result && try_cache) {
const processed_obj_li = await process_ae_obj__event_props({
if (result) {
const processed = await process_ae_obj__event_props({
obj_li: [result],
log_lvl: log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'event',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
const processed_obj = processed[0];
if (try_cache) {
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'event',
obj_li: processed,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
}
return processed_obj;
}
return result;
return null;
}
// Updated 2026-01-06
@@ -427,21 +426,26 @@ export async function update_ae_obj__event({
log_lvl
});
if (result && try_cache) {
const processed_obj_li = await process_ae_obj__event_props({
if (result) {
const processed = await process_ae_obj__event_props({
obj_li: [result],
log_lvl: log_lvl
});
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'event',
obj_li: processed_obj_li,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
const processed_obj = processed[0];
if (try_cache) {
await db_save_ae_obj_li__ae_obj({
db_instance: db_events,
table_name: 'event',
obj_li: processed,
properties_to_save: properties_to_save,
log_lvl: log_lvl
});
}
return processed_obj;
}
return result;
return null;
}
// Updated 2026-01-21
@@ -498,9 +502,8 @@ export async function search__event({
search_query.and.push({ field: 'default_qry_str', op: 'like', value: `%${qry_str.trim()}%` });
params['lk_qry'] = { 'default_qry_str': qry_str.trim() };
// Use raw field name to bypass backend mapping conflicts
if (for_obj_id) {
search_query.and.push({ field: 'account_id_random', op: 'eq', value: for_obj_id });
search_query.and.push({ field: `${for_obj_type}_id`, op: 'eq', value: for_obj_id });
}
if (enabled === 'enabled') search_query.and.push({ field: 'enable', op: 'eq', value: 1 });
@@ -754,10 +757,8 @@ export async function qry_ae_obj_li__event_v2({
export const properties_to_save = [
'id',
'event_id',
'event_id_random',
'code',
'account_id',
'account_id_random',
'conference',
'type',
'name',
@@ -880,11 +881,8 @@ export async function process_ae_obj__event_props({
obj.code = obj.event_code;
}
// Ensure ID consistency for components relying on specific ID fields
if (!obj.event_id_random && obj.id_random) {
obj.event_id_random = obj.id_random;
}
if (obj.event_id_random && !obj.id) {
obj.id = obj.event_id_random;
if (obj.id && !obj.event_id) {
obj.event_id = obj.id;
}
return obj;
}