fix(core): clarify account fallback source and pretty-print _json payloads
This commit is contained in:
@@ -3,6 +3,22 @@ import { post_object } from './api_post_object';
|
||||
import { patch_object } from './api_patch_object';
|
||||
import { delete_object } from './api_delete_object';
|
||||
|
||||
const JSON_PRETTY_SPACES = 2;
|
||||
|
||||
function serialize_json_field_pretty(value: unknown) {
|
||||
if (value === null || value === undefined) return value;
|
||||
|
||||
if (typeof value === 'string') {
|
||||
try {
|
||||
return JSON.stringify(JSON.parse(value), null, JSON_PRETTY_SPACES);
|
||||
} catch {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
return JSON.stringify(value, null, JSON_PRETTY_SPACES);
|
||||
}
|
||||
|
||||
/**
|
||||
* --- POST (CREATE) WRAPPERS ---
|
||||
*/
|
||||
@@ -33,13 +49,11 @@ export async function create_ae_obj({
|
||||
// Standard Aether Pattern: Auto-serialize any key ending in _json
|
||||
const cleaned_fields = { ...fields };
|
||||
for (const key in cleaned_fields) {
|
||||
if (
|
||||
key.endsWith('_json') &&
|
||||
cleaned_fields[key] !== null &&
|
||||
typeof cleaned_fields[key] === 'object'
|
||||
) {
|
||||
if (key.endsWith('_json') && cleaned_fields[key] !== null) {
|
||||
if (log_lvl) console.log(`Auto-serializing field: ${key}`);
|
||||
cleaned_fields[key] = JSON.stringify(cleaned_fields[key]);
|
||||
cleaned_fields[key] = serialize_json_field_pretty(
|
||||
cleaned_fields[key]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,12 +112,10 @@ export async function create_nested_obj({
|
||||
// Standard Aether Pattern: Auto-serialize any key ending in _json
|
||||
const cleaned_fields = { ...fields };
|
||||
for (const key in cleaned_fields) {
|
||||
if (
|
||||
key.endsWith('_json') &&
|
||||
cleaned_fields[key] !== null &&
|
||||
typeof cleaned_fields[key] === 'object'
|
||||
) {
|
||||
cleaned_fields[key] = JSON.stringify(cleaned_fields[key]);
|
||||
if (key.endsWith('_json') && cleaned_fields[key] !== null) {
|
||||
cleaned_fields[key] = serialize_json_field_pretty(
|
||||
cleaned_fields[key]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,13 +160,11 @@ export async function update_ae_obj({
|
||||
// Standard Aether Pattern: Auto-serialize any key ending in _json
|
||||
const cleaned_fields = { ...fields };
|
||||
for (const key in cleaned_fields) {
|
||||
if (
|
||||
key.endsWith('_json') &&
|
||||
cleaned_fields[key] !== null &&
|
||||
typeof cleaned_fields[key] === 'object'
|
||||
) {
|
||||
if (key.endsWith('_json') && cleaned_fields[key] !== null) {
|
||||
if (log_lvl > 1) console.log(`Auto-serializing field: ${key}`);
|
||||
cleaned_fields[key] = JSON.stringify(cleaned_fields[key]);
|
||||
cleaned_fields[key] = serialize_json_field_pretty(
|
||||
cleaned_fields[key]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,12 +224,10 @@ export async function update_nested_obj({
|
||||
// Standard Aether Pattern: Auto-serialize any key ending in _json
|
||||
const cleaned_fields = { ...fields };
|
||||
for (const key in cleaned_fields) {
|
||||
if (
|
||||
key.endsWith('_json') &&
|
||||
cleaned_fields[key] !== null &&
|
||||
typeof cleaned_fields[key] === 'object'
|
||||
) {
|
||||
cleaned_fields[key] = JSON.stringify(cleaned_fields[key]);
|
||||
if (key.endsWith('_json') && cleaned_fields[key] !== null) {
|
||||
cleaned_fields[key] = serialize_json_field_pretty(
|
||||
cleaned_fields[key]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,22 @@ import {
|
||||
|
||||
import { get_data_store } from '$lib/ae_api/api_get__data_store';
|
||||
|
||||
const JSON_PRETTY_SPACES = 2;
|
||||
|
||||
function serialize_json_field_pretty(value: any) {
|
||||
if (value === null || value === undefined) return value;
|
||||
|
||||
if (typeof value === 'string') {
|
||||
try {
|
||||
return JSON.stringify(JSON.parse(value), null, JSON_PRETTY_SPACES);
|
||||
} catch {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
return JSON.stringify(value, null, JSON_PRETTY_SPACES);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of lookup objects (V3)
|
||||
* Standardized lookup data like countries, timezones, and subdivisions.
|
||||
@@ -165,7 +181,7 @@ export const create_ae_obj_crud = async function create_ae_obj_crud({
|
||||
if (log_lvl) {
|
||||
console.log(`${key}: ${value}`);
|
||||
}
|
||||
data['data_list'][key] = JSON.stringify(value);
|
||||
data['data_list'][key] = serialize_json_field_pretty(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -276,7 +292,7 @@ export const update_ae_obj_id_crud = async function update_ae_obj_id_crud({
|
||||
if (log_lvl) {
|
||||
console.log(`${key}: ${value}`);
|
||||
}
|
||||
data['data_list'][key] = JSON.stringify(value);
|
||||
data['data_list'][key] = serialize_json_field_pretty(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,12 +27,14 @@ let saving = $state(false);
|
||||
let save_success = $state(false);
|
||||
let confirm_action = $state<string | null>(null);
|
||||
let load_error = $state<string | null>(null);
|
||||
let loaded_from_cache = $state(false);
|
||||
let loaded_from_list_fallback = $state(false);
|
||||
let loaded_from_local_cache = $state(false);
|
||||
|
||||
async function load_account() {
|
||||
loading = true;
|
||||
load_error = null;
|
||||
loaded_from_cache = false;
|
||||
loaded_from_list_fallback = false;
|
||||
loaded_from_local_cache = false;
|
||||
try {
|
||||
account = await load_ae_obj_id__account({
|
||||
api_cfg: $ae_api,
|
||||
@@ -55,7 +57,7 @@ async function load_account() {
|
||||
|
||||
if (account_from_list) {
|
||||
account = account_from_list;
|
||||
loaded_from_cache = true;
|
||||
loaded_from_list_fallback = true;
|
||||
}
|
||||
|
||||
const cached_account = await db_core.account
|
||||
@@ -65,7 +67,7 @@ async function load_account() {
|
||||
|
||||
if (!account && cached_account) {
|
||||
account = cached_account;
|
||||
loaded_from_cache = true;
|
||||
loaded_from_local_cache = true;
|
||||
}
|
||||
|
||||
if (!account) {
|
||||
@@ -221,11 +223,15 @@ async function handle_delete() {
|
||||
</div>
|
||||
</div>
|
||||
{:else if account}
|
||||
{#if loaded_from_cache}
|
||||
{#if loaded_from_list_fallback || loaded_from_local_cache}
|
||||
<div
|
||||
class="card border-warning-500/30 bg-warning-500/5 mb-2 flex items-start gap-3 border p-4 shadow-sm">
|
||||
<p class="text-sm opacity-80">
|
||||
This record loaded from local cache because direct account API access is currently restricted for this session.
|
||||
{#if loaded_from_local_cache}
|
||||
This record loaded from local cache because direct account API access is currently restricted for this session.
|
||||
{:else}
|
||||
This record loaded from the account list fallback because direct account-by-id API access is currently restricted for this session.
|
||||
{/if}
|
||||
</p>
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
@@ -70,7 +70,8 @@ async function handle_save_site() {
|
||||
}
|
||||
});
|
||||
|
||||
// Pretty-print cfg_json so it's human-readable in the DB (TEXT column)
|
||||
// Keep cfg_json human-readable in DB TEXT columns.
|
||||
// Safe here: V3 update_ae_obj only stringifies *_json when the value is an object.
|
||||
data_kv.cfg_json = JSON.stringify(site.cfg_json, null, 2);
|
||||
|
||||
await update_ae_obj__site({
|
||||
|
||||
Reference in New Issue
Block a user