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]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user