style(journals): apply expanded 80-width formatting and snake_case
- Batch formatted all Journals module files using Prettier with printWidth: 80. - Refactored preventDefault to prevent_default across all Svelte components. - Standardized line breaks for imports and long attribute lists for better readability. - Ensured consistent snake_case naming for internal identifiers.
This commit is contained in:
@@ -46,7 +46,9 @@ export async function load_ae_obj_id__journal({
|
||||
log_lvl?: number;
|
||||
}): Promise<ae_Journal | null> {
|
||||
if (log_lvl) {
|
||||
console.log(`*** load_ae_obj_id__journal() *** journal_id=${journal_id} (SWR)`);
|
||||
console.log(
|
||||
`*** load_ae_obj_id__journal() *** journal_id=${journal_id} (SWR)`
|
||||
);
|
||||
}
|
||||
|
||||
// 1. FAST PATH: Return cached data immediately
|
||||
@@ -54,16 +56,39 @@ export async function load_ae_obj_id__journal({
|
||||
try {
|
||||
const cached = await db_journals.journal.get(journal_id);
|
||||
if (cached) {
|
||||
if (log_lvl) console.log('JOURNAL LOAD: Cache hit. Returning stale data.');
|
||||
_refresh_journal_id_background({
|
||||
api_cfg, journal_id, view, params, try_cache,
|
||||
inc_entry_li, enabled, hidden, limit, offset, order_by_li, log_lvl: 0
|
||||
if (log_lvl)
|
||||
console.log(
|
||||
'JOURNAL LOAD: Cache hit. Returning stale data.'
|
||||
);
|
||||
_refresh_journal_id_background({
|
||||
api_cfg,
|
||||
journal_id,
|
||||
view,
|
||||
params,
|
||||
try_cache,
|
||||
inc_entry_li,
|
||||
enabled,
|
||||
hidden,
|
||||
limit,
|
||||
offset,
|
||||
order_by_li,
|
||||
log_lvl: 0
|
||||
});
|
||||
if (inc_entry_li && !cached.journal_entry_li) {
|
||||
cached.journal_entry_li = await load_ae_obj_li__journal_entry({
|
||||
api_cfg, for_obj_type: 'journal', for_obj_id: journal_id,
|
||||
enabled, hidden, limit, offset, order_by_li, params, try_cache, log_lvl
|
||||
});
|
||||
cached.journal_entry_li =
|
||||
await load_ae_obj_li__journal_entry({
|
||||
api_cfg,
|
||||
for_obj_type: 'journal',
|
||||
for_obj_id: journal_id,
|
||||
enabled,
|
||||
hidden,
|
||||
limit,
|
||||
offset,
|
||||
order_by_li,
|
||||
params,
|
||||
try_cache,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
return cached;
|
||||
}
|
||||
@@ -71,28 +96,76 @@ export async function load_ae_obj_id__journal({
|
||||
}
|
||||
|
||||
// 2. SLOW PATH: Wait for API
|
||||
return await _refresh_journal_id_background({
|
||||
api_cfg, journal_id, view, params, try_cache,
|
||||
inc_entry_li, enabled, hidden, limit, offset, order_by_li, log_lvl
|
||||
return await _refresh_journal_id_background({
|
||||
api_cfg,
|
||||
journal_id,
|
||||
view,
|
||||
params,
|
||||
try_cache,
|
||||
inc_entry_li,
|
||||
enabled,
|
||||
hidden,
|
||||
limit,
|
||||
offset,
|
||||
order_by_li,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal background refresh for a single journal
|
||||
*/
|
||||
async function _refresh_journal_id_background({ api_cfg, journal_id, view, params, try_cache, inc_entry_li, enabled, hidden, limit, offset, order_by_li, log_lvl }: any) {
|
||||
async function _refresh_journal_id_background({
|
||||
api_cfg,
|
||||
journal_id,
|
||||
view,
|
||||
params,
|
||||
try_cache,
|
||||
inc_entry_li,
|
||||
enabled,
|
||||
hidden,
|
||||
limit,
|
||||
offset,
|
||||
order_by_li,
|
||||
log_lvl
|
||||
}: any) {
|
||||
if (typeof navigator !== 'undefined' && !navigator.onLine) return null;
|
||||
try {
|
||||
const result = await api.get_ae_obj_v3({ api_cfg, obj_type: 'journal', obj_id: journal_id, view, params, log_lvl });
|
||||
const result = await api.get_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'journal',
|
||||
obj_id: journal_id,
|
||||
view,
|
||||
params,
|
||||
log_lvl
|
||||
});
|
||||
if (result) {
|
||||
if (try_cache) {
|
||||
const processed = await process_ae_obj__journal_props({ obj_li: [result], log_lvl });
|
||||
await db_save_ae_obj_li__ae_obj({ db_instance: db_journals, table_name: 'journal', obj_li: processed, properties_to_save, log_lvl });
|
||||
const processed = await process_ae_obj__journal_props({
|
||||
obj_li: [result],
|
||||
log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_journals,
|
||||
table_name: 'journal',
|
||||
obj_li: processed,
|
||||
properties_to_save,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
if (inc_entry_li) {
|
||||
result.journal_entry_li = await load_ae_obj_li__journal_entry({
|
||||
api_cfg, for_obj_type: 'journal', for_obj_id: journal_id,
|
||||
enabled, hidden, limit, offset, order_by_li, params, try_cache, log_lvl
|
||||
api_cfg,
|
||||
for_obj_type: 'journal',
|
||||
for_obj_id: journal_id,
|
||||
enabled,
|
||||
hidden,
|
||||
limit,
|
||||
offset,
|
||||
order_by_li,
|
||||
params,
|
||||
try_cache,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
return result;
|
||||
@@ -138,18 +211,37 @@ export async function load_ae_obj_li__journal({
|
||||
log_lvl?: number;
|
||||
}): Promise<ae_Journal[]> {
|
||||
if (log_lvl) {
|
||||
console.log(`*** load_ae_obj_li__journal() *** for=${for_obj_type}:${for_obj_id} (SWR)`);
|
||||
console.log(
|
||||
`*** load_ae_obj_li__journal() *** for=${for_obj_type}:${for_obj_id} (SWR)`
|
||||
);
|
||||
}
|
||||
|
||||
// 1. FAST PATH: Check cache
|
||||
if (try_cache) {
|
||||
try {
|
||||
const cached_li = await db_journals.journal.where('for_id').equals(for_obj_id).toArray();
|
||||
const cached_li = await db_journals.journal
|
||||
.where('for_id')
|
||||
.equals(for_obj_id)
|
||||
.toArray();
|
||||
if (cached_li && cached_li.length > 0) {
|
||||
if (log_lvl) console.log(`JOURNAL LIST: Cache hit (${cached_li.length}).`);
|
||||
_refresh_journal_li_background({
|
||||
api_cfg, for_obj_type, for_obj_id, qry_person_id, inc_entry_li,
|
||||
enabled, hidden, limit, offset, order_by_li, params, try_cache, log_lvl: 0
|
||||
if (log_lvl)
|
||||
console.log(
|
||||
`JOURNAL LIST: Cache hit (${cached_li.length}).`
|
||||
);
|
||||
_refresh_journal_li_background({
|
||||
api_cfg,
|
||||
for_obj_type,
|
||||
for_obj_id,
|
||||
qry_person_id,
|
||||
inc_entry_li,
|
||||
enabled,
|
||||
hidden,
|
||||
limit,
|
||||
offset,
|
||||
order_by_li,
|
||||
params,
|
||||
try_cache,
|
||||
log_lvl: 0
|
||||
});
|
||||
return cached_li;
|
||||
}
|
||||
@@ -157,39 +249,110 @@ export async function load_ae_obj_li__journal({
|
||||
}
|
||||
|
||||
// 2. SLOW PATH: API
|
||||
return await _refresh_journal_li_background({
|
||||
api_cfg, for_obj_type, for_obj_id, qry_person_id, inc_entry_li,
|
||||
enabled, hidden, limit, offset, order_by_li, params, try_cache, log_lvl
|
||||
return await _refresh_journal_li_background({
|
||||
api_cfg,
|
||||
for_obj_type,
|
||||
for_obj_id,
|
||||
qry_person_id,
|
||||
inc_entry_li,
|
||||
enabled,
|
||||
hidden,
|
||||
limit,
|
||||
offset,
|
||||
order_by_li,
|
||||
params,
|
||||
try_cache,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
async function _refresh_journal_li_background({ api_cfg, for_obj_type, for_obj_id, qry_person_id, inc_entry_li, enabled, hidden, limit, offset, order_by_li, params, try_cache, log_lvl }: any) {
|
||||
async function _refresh_journal_li_background({
|
||||
api_cfg,
|
||||
for_obj_type,
|
||||
for_obj_id,
|
||||
qry_person_id,
|
||||
inc_entry_li,
|
||||
enabled,
|
||||
hidden,
|
||||
limit,
|
||||
offset,
|
||||
order_by_li,
|
||||
params,
|
||||
try_cache,
|
||||
log_lvl
|
||||
}: any) {
|
||||
if (typeof navigator !== 'undefined' && !navigator.onLine) return [];
|
||||
|
||||
|
||||
let promise;
|
||||
if (qry_person_id) {
|
||||
const search_query: any = { and: [{ field: 'person_id_random', op: 'eq', value: qry_person_id }] };
|
||||
if (for_obj_id) search_query.and.push({ field: `${for_obj_type}_id_random`, op: 'eq', value: for_obj_id });
|
||||
if (enabled === 'enabled') search_query.and.push({ field: 'enable', op: 'eq', value: true });
|
||||
if (hidden === 'hidden') search_query.and.push({ field: 'hide', op: 'eq', value: true });
|
||||
const search_query: any = {
|
||||
and: [{ field: 'person_id_random', op: 'eq', value: qry_person_id }]
|
||||
};
|
||||
if (for_obj_id)
|
||||
search_query.and.push({
|
||||
field: `${for_obj_type}_id_random`,
|
||||
op: 'eq',
|
||||
value: for_obj_id
|
||||
});
|
||||
if (enabled === 'enabled')
|
||||
search_query.and.push({ field: 'enable', op: 'eq', value: true });
|
||||
if (hidden === 'hidden')
|
||||
search_query.and.push({ field: 'hide', op: 'eq', value: true });
|
||||
|
||||
promise = api.search_ae_obj_v3({ api_cfg, obj_type: 'journal', search_query, order_by_li, limit, offset, log_lvl });
|
||||
promise = api.search_ae_obj_v3({
|
||||
api_cfg,
|
||||
obj_type: 'journal',
|
||||
search_query,
|
||||
order_by_li,
|
||||
limit,
|
||||
offset,
|
||||
log_lvl
|
||||
});
|
||||
} else {
|
||||
promise = api.get_ae_obj_li_v3({ api_cfg, obj_type: 'journal', for_obj_type, for_obj_id, enabled, hidden, limit, offset, order_by_li, log_lvl });
|
||||
promise = api.get_ae_obj_li_v3({
|
||||
api_cfg,
|
||||
obj_type: 'journal',
|
||||
for_obj_type,
|
||||
for_obj_id,
|
||||
enabled,
|
||||
hidden,
|
||||
limit,
|
||||
offset,
|
||||
order_by_li,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
|
||||
try {
|
||||
const results = await promise;
|
||||
if (results) {
|
||||
if (try_cache) {
|
||||
const processed = await process_ae_obj__journal_props({ obj_li: results, log_lvl });
|
||||
await db_save_ae_obj_li__ae_obj({ db_instance: db_journals, table_name: 'journal', obj_li: processed, properties_to_save, log_lvl });
|
||||
const processed = await process_ae_obj__journal_props({
|
||||
obj_li: results,
|
||||
log_lvl
|
||||
});
|
||||
await db_save_ae_obj_li__ae_obj({
|
||||
db_instance: db_journals,
|
||||
table_name: 'journal',
|
||||
obj_li: processed,
|
||||
properties_to_save,
|
||||
log_lvl
|
||||
});
|
||||
}
|
||||
if (inc_entry_li) {
|
||||
for (const journal of results) {
|
||||
load_ae_obj_li__journal_entry({
|
||||
api_cfg, for_obj_type: 'journal', for_obj_id: journal.journal_id_random,
|
||||
enabled, hidden, limit, offset, order_by_li, params, try_cache, log_lvl: 0
|
||||
api_cfg,
|
||||
for_obj_type: 'journal',
|
||||
for_obj_id: journal.journal_id_random,
|
||||
enabled,
|
||||
hidden,
|
||||
limit,
|
||||
offset,
|
||||
order_by_li,
|
||||
params,
|
||||
try_cache,
|
||||
log_lvl: 0
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -216,11 +379,15 @@ export async function create_ae_obj__journal({
|
||||
log_lvl?: number;
|
||||
}): Promise<ae_Journal | null> {
|
||||
if (log_lvl) {
|
||||
console.log(`*** create_ae_obj__journal() *** account_id=${account_id}`);
|
||||
console.log(
|
||||
`*** create_ae_obj__journal() *** account_id=${account_id}`
|
||||
);
|
||||
}
|
||||
|
||||
if (!account_id) {
|
||||
console.log(`ERROR: Journals - Journal - account_id required to create`);
|
||||
console.log(
|
||||
`ERROR: Journals - Journal - account_id required to create`
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -239,10 +406,11 @@ export async function create_ae_obj__journal({
|
||||
if (journal_obj_create_result) {
|
||||
if (try_cache) {
|
||||
// Process the results first
|
||||
const processed_obj_li = await process_ae_obj__journal_props({
|
||||
obj_li: [journal_obj_create_result],
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
const processed_obj_li =
|
||||
await process_ae_obj__journal_props({
|
||||
obj_li: [journal_obj_create_result],
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('Processed object list:', processed_obj_li);
|
||||
}
|
||||
@@ -284,7 +452,9 @@ export async function delete_ae_obj_id__journal({
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** delete_ae_obj_id__journal() *** journal_id=${journal_id}`);
|
||||
console.log(
|
||||
`*** delete_ae_obj_id__journal() *** journal_id=${journal_id}`
|
||||
);
|
||||
}
|
||||
|
||||
ae_promises.delete__journal_obj = await api
|
||||
@@ -302,7 +472,9 @@ export async function delete_ae_obj_id__journal({
|
||||
.finally(async function () {
|
||||
if (try_cache) {
|
||||
if (log_lvl) {
|
||||
console.log(`Attempting to remove IDB entry for journal_id=${journal_id}`);
|
||||
console.log(
|
||||
`Attempting to remove IDB entry for journal_id=${journal_id}`
|
||||
);
|
||||
}
|
||||
await db_journals.journal.delete(journal_id);
|
||||
}
|
||||
@@ -328,7 +500,10 @@ export async function update_ae_obj__journal({
|
||||
log_lvl?: number;
|
||||
}): Promise<ae_Journal | null> {
|
||||
if (log_lvl) {
|
||||
console.log(`*** update_ae_obj__journal() *** journal_id=${journal_id}`, data_kv);
|
||||
console.log(
|
||||
`*** update_ae_obj__journal() *** journal_id=${journal_id}`,
|
||||
data_kv
|
||||
);
|
||||
}
|
||||
|
||||
// Perform the API update
|
||||
@@ -401,7 +576,9 @@ export async function qry__journal({
|
||||
hidden?: 'hidden' | 'all' | 'not_hidden' | undefined; // all, hidden, not_hidden
|
||||
limit?: number;
|
||||
offset?: number;
|
||||
order_by_li?: Record<string, 'ASC' | 'DESC'> | Record<string, 'ASC' | 'DESC'>[];
|
||||
order_by_li?:
|
||||
| Record<string, 'ASC' | 'DESC'>
|
||||
| Record<string, 'ASC' | 'DESC'>[];
|
||||
params?: any;
|
||||
try_cache?: boolean;
|
||||
log_lvl?: number;
|
||||
@@ -417,17 +594,29 @@ export async function qry__journal({
|
||||
if (qry_files === true) {
|
||||
search_query.and.push({ field: 'file_count_all', op: 'gt', value: 0 });
|
||||
} else if (qry_files === false) {
|
||||
search_query.and.push({ field: 'file_count_all', op: 'is', value: null });
|
||||
search_query.and.push({
|
||||
field: 'file_count_all',
|
||||
op: 'is',
|
||||
value: null
|
||||
});
|
||||
}
|
||||
|
||||
if (qry_start_datetime) {
|
||||
search_query.and.push({ field: 'start_datetime', op: 'gt', value: qry_start_datetime });
|
||||
search_query.and.push({
|
||||
field: 'start_datetime',
|
||||
op: 'gt',
|
||||
value: qry_start_datetime
|
||||
});
|
||||
}
|
||||
|
||||
// Add for_obj_id context (Account ID)
|
||||
if (journal_id) {
|
||||
// Assuming journal_id here is actually the account_id as per original usage context
|
||||
search_query.and.push({ field: 'account_id_random', op: 'eq', value: journal_id });
|
||||
search_query.and.push({
|
||||
field: 'account_id_random',
|
||||
op: 'eq',
|
||||
value: journal_id
|
||||
});
|
||||
}
|
||||
|
||||
// Add enabled/hidden filters
|
||||
@@ -457,10 +646,11 @@ export async function qry__journal({
|
||||
if (journal_obj_li_get_result) {
|
||||
if (try_cache) {
|
||||
// Process the results first
|
||||
const processed_obj_li = await process_ae_obj__journal_props({
|
||||
obj_li: journal_obj_li_get_result,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
const processed_obj_li =
|
||||
await process_ae_obj__journal_props({
|
||||
obj_li: journal_obj_li_get_result,
|
||||
log_lvl: log_lvl
|
||||
});
|
||||
if (log_lvl) {
|
||||
console.log('Processed object list:', processed_obj_li);
|
||||
}
|
||||
@@ -486,7 +676,10 @@ export async function qry__journal({
|
||||
});
|
||||
|
||||
if (log_lvl) {
|
||||
console.log('ae_promises.load__journal_obj_li:', ae_promises.load__journal_obj_li);
|
||||
console.log(
|
||||
'ae_promises.load__journal_obj_li:',
|
||||
ae_promises.load__journal_obj_li
|
||||
);
|
||||
}
|
||||
return ae_promises.load__journal_obj_li;
|
||||
}
|
||||
@@ -624,12 +817,16 @@ async function _process_generic_props<T extends Record<string, any>>({
|
||||
const updated = processed_obj.updated_on ?? processed_obj.created_on;
|
||||
const name = processed_obj.name ?? '';
|
||||
|
||||
(processed_obj as any).tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`;
|
||||
(processed_obj as any).tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
|
||||
(processed_obj as any).tmp_sort_1 =
|
||||
`${group}_${priority}_${sort}_${updated}`;
|
||||
(processed_obj as any).tmp_sort_2 =
|
||||
`${group}_${priority}_${sort}_${name}_${updated}`;
|
||||
|
||||
// --- Specific Transformations ---
|
||||
if (specific_processor) {
|
||||
processed_obj = await Promise.resolve(specific_processor(processed_obj));
|
||||
processed_obj = await Promise.resolve(
|
||||
specific_processor(processed_obj)
|
||||
);
|
||||
}
|
||||
|
||||
processed_obj_li.push(processed_obj as T);
|
||||
@@ -656,7 +853,8 @@ export async function process_ae_obj__journal_props({
|
||||
/^[\u200B\u200C\u200D\u200E\u200F\uFEFF]/,
|
||||
''
|
||||
);
|
||||
obj.description_md_html = (await marked.parse(description_cleaned ?? '')) ?? null;
|
||||
obj.description_md_html =
|
||||
(await marked.parse(description_cleaned ?? '')) ?? null;
|
||||
|
||||
obj.cfg_json = obj.cfg_json ?? {};
|
||||
obj.data_json = obj.data_json ?? {};
|
||||
@@ -669,4 +867,4 @@ export async function process_ae_obj__journal_props({
|
||||
return obj;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user