Quick snapshot again as Gemini is working.
This commit is contained in:
@@ -880,122 +880,103 @@ let properties_to_save = [
|
||||
];
|
||||
|
||||
|
||||
// Updated 2025-05-09
|
||||
export async function process_ae_obj__journal_props(
|
||||
{
|
||||
// obj_type,
|
||||
obj_li,
|
||||
log_lvl = 0,
|
||||
}: {
|
||||
// obj_type: string;
|
||||
obj_li: any[];
|
||||
log_lvl?: number;
|
||||
}
|
||||
) {
|
||||
if (log_lvl) {
|
||||
console.log(`*** process_ae_obj__journal_props() ***`, obj_li);
|
||||
}
|
||||
/**
|
||||
* NON-EXPORTED LOCAL HELPER
|
||||
* Processes a list of Aether objects by applying common and specific transformations.
|
||||
*/
|
||||
async function _process_generic_props<T extends Record<string, any>>({
|
||||
obj_li,
|
||||
obj_type,
|
||||
log_lvl = 0,
|
||||
specific_processor
|
||||
}: {
|
||||
obj_li: T[];
|
||||
obj_type: string;
|
||||
log_lvl?: number;
|
||||
specific_processor?: (obj: T) => Promise<T> | T;
|
||||
}): Promise<T[]> {
|
||||
if (log_lvl > 0) {
|
||||
console.log(
|
||||
`*** _process_generic_props: Processing ${obj_li.length} objects of type "${obj_type}" ***`
|
||||
);
|
||||
}
|
||||
|
||||
if (!obj_li || obj_li.length === 0) {
|
||||
if (log_lvl) {
|
||||
console.log('No objects to process.');
|
||||
}
|
||||
return [];
|
||||
}
|
||||
if (!obj_li || obj_li.length === 0) {
|
||||
if (log_lvl > 0) console.log('No objects to process.');
|
||||
return [];
|
||||
}
|
||||
|
||||
const processed_obj_li = [];
|
||||
const processed_obj_li: T[] = [];
|
||||
|
||||
for (const obj of obj_li) {
|
||||
// const processed_obj = { ...obj };
|
||||
for (const original_obj of obj_li) {
|
||||
let processed_obj = { ...original_obj };
|
||||
|
||||
// Process the properties as needed
|
||||
let description = obj.description ?? '';
|
||||
// remove the most common zerowidth characters from the start of the file
|
||||
let description_cleaned: string = description.replace(/^[\u200B\u200C\u200D\u200E\u200F\uFEFF]/,"");
|
||||
let description_md_html: null|string = await marked.parse(description_cleaned ?? '') ?? null;
|
||||
// let description_md_html_alt: null|string = await marked.parse(description_cleaned ?? '', { gfm: false }) ?? null;
|
||||
// --- Common Transformations ---
|
||||
|
||||
let processed_obj = {
|
||||
id: obj.journal_id_random,
|
||||
journal_id: obj.journal_id_random,
|
||||
// 1. Standardize ID and other '_random' fields
|
||||
// The API often returns fields like 'person_id_random', which need to be aliased to 'person_id'.
|
||||
for (const key in processed_obj) {
|
||||
if (key.endsWith('_random')) {
|
||||
const newKey = key.slice(0, -7); // Remove '_random' suffix
|
||||
processed_obj[newKey] = processed_obj[key];
|
||||
}
|
||||
}
|
||||
// Ensure 'id' is set from '[obj_type]_id_random'
|
||||
const randomIdKey = `${obj_type}_id_random`;
|
||||
if (processed_obj[randomIdKey]) {
|
||||
processed_obj.id = processed_obj[randomIdKey];
|
||||
}
|
||||
|
||||
code: obj.code,
|
||||
// 2. Create common computed properties for client-side sorting.
|
||||
const group = processed_obj.group ?? '0';
|
||||
const priority = processed_obj.priority ? 1 : 0;
|
||||
const sort = processed_obj.sort ?? '0';
|
||||
const updated = processed_obj.updated_on ?? processed_obj.created_on;
|
||||
const name = processed_obj.name ?? '';
|
||||
|
||||
for_type: obj.for_type,
|
||||
for_id: obj.for_id,
|
||||
processed_obj.tmp_sort_1 = `${group}_${priority}_${sort}_${updated}`;
|
||||
processed_obj.tmp_sort_2 = `${group}_${priority}_${sort}_${name}_${updated}`;
|
||||
|
||||
type_code: obj.type_code,
|
||||
// --- Specific Transformations ---
|
||||
if (specific_processor) {
|
||||
processed_obj = await Promise.resolve(specific_processor(processed_obj));
|
||||
}
|
||||
|
||||
account_id: obj.account_id_random,
|
||||
person_id: obj.person_id_random,
|
||||
processed_obj_li.push(processed_obj as T);
|
||||
}
|
||||
|
||||
name: obj.name,
|
||||
short_name: obj.short_name,
|
||||
summary: obj.summary,
|
||||
outline: obj.outline,
|
||||
return processed_obj_li;
|
||||
}
|
||||
|
||||
description: obj.description,
|
||||
description_md_html: description_md_html, // Use the markdown parser to generate HTML
|
||||
description_html: obj.description_html,
|
||||
description_json: obj.description_json,
|
||||
// Updated 2025-11-13
|
||||
export async function process_ae_obj__journal_props({
|
||||
obj_li,
|
||||
log_lvl = 0
|
||||
}: {
|
||||
obj_li: any[];
|
||||
log_lvl?: number;
|
||||
}) {
|
||||
return _process_generic_props({
|
||||
obj_li,
|
||||
obj_type: 'journal',
|
||||
log_lvl,
|
||||
specific_processor: async (obj) => {
|
||||
const description = obj.description ?? '';
|
||||
const description_cleaned: string = description.replace(
|
||||
/^[\u200B\u200C\u200D\u200E\u200F\uFEFF]/,
|
||||
''
|
||||
);
|
||||
obj.description_md_html = (await marked.parse(description_cleaned ?? '')) ?? null;
|
||||
|
||||
// start_datetime: obj.start_datetime,
|
||||
// end_datetime: obj.end_datetime,
|
||||
timezone: obj.timezone,
|
||||
obj.cfg_json = obj.cfg_json ?? {};
|
||||
obj.data_json = obj.data_json ?? {};
|
||||
|
||||
alert: obj.alert,
|
||||
alert_msg: obj.alert_msg,
|
||||
obj.tmp_sort_3 = `${obj.group ?? '0'}_${obj.priority ? 1 : 0}_${obj.sort ?? '0'}_${
|
||||
obj.name
|
||||
}_${obj.updated_on ?? obj.created_on}`;
|
||||
obj.combined_passcode = `${obj.passcode ?? ''}:${obj.private_passcode ?? ''}`;
|
||||
|
||||
sort_by: obj.sort_by,
|
||||
sort_by_desc: obj.sort_by_desc,
|
||||
|
||||
cfg_json: obj.cfg_json ?? {},
|
||||
|
||||
data_json: obj.data_json ?? {},
|
||||
|
||||
// ux_mode: obj.ux_mode,
|
||||
|
||||
// This only allows for basic access to the data.
|
||||
passcode_read: obj.passcode_read, // For LLM (AI) generated summary...???
|
||||
passcode_read_expire: obj.passcode_read_expire,
|
||||
passcode_write: obj.passcode_write,
|
||||
passcode_write_expire: obj.passcode_write_expire,
|
||||
|
||||
passcode: obj.passcode, // For Journal Entry encryption password
|
||||
passcode_timeout: obj.passcode_timeout,
|
||||
|
||||
private_passcode: obj.private_passcode, // Combine with Journal passcode to encrypt and decrypt Entries
|
||||
|
||||
auth_key: obj.auth_key, // For Journal authorization without sign in
|
||||
|
||||
enable: obj.enable,
|
||||
hide: obj.hide,
|
||||
priority: obj.priority,
|
||||
sort: obj.sort,
|
||||
group: obj.group,
|
||||
notes: obj.notes,
|
||||
created_on: obj.created_on,
|
||||
updated_on: obj.updated_on,
|
||||
|
||||
// Generated fields for sorting locally only
|
||||
tmp_sort_1: `${obj.group ?? '0'}_${obj.priority ? 1 : 0}_${obj.sort ?? '0'}_${obj.updated_on}_${obj.created_on}`,
|
||||
tmp_sort_2: `${obj.group ?? '0'}_${obj.priority ? 1 : 0}_${obj.sort ?? '0'}_${obj.updated_on ?? obj.created_on}`,
|
||||
tmp_sort_3: `${obj.group ?? '0'}_${obj.priority ? 1 : 0}_${obj.sort ?? '0'}_${obj.name}_${obj.updated_on ?? obj.created_on}`,
|
||||
// tmp_sort_1: `${obj.original_datetime}_${obj.group}_${obj.priority}_${obj.sort}`,
|
||||
// tmp_sort_2: `${obj.group}_${obj.original_datetime}_${obj.priority}_${obj.sort}`,
|
||||
|
||||
combined_passcode: `${obj.passcode}:${obj.private_passcode}`, // Combined Journal passcode and Journal private passcode to encrypt and decrypt Entries
|
||||
|
||||
// From SQL view
|
||||
journal_entry_count: obj.journal_entry_count,
|
||||
|
||||
// A key value list of the others
|
||||
// journal_other_kv: obj.journal_other_kv,
|
||||
// journal_other_li: obj.journal_other_li,
|
||||
};
|
||||
|
||||
processed_obj_li.push(processed_obj);
|
||||
}
|
||||
|
||||
return processed_obj_li;
|
||||
return obj;
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user