When I switched to saving sessions in the db, I lost the ability to parse JSON columns. The db session store's postProcessResponse is very different from app.js that includes formatRecord with JSON column parsing. Making the switch to db session storage caused uncaught regressions.
Session store's version (lib/setup/session.js:55-73) — only handles .toJSON():
options.postProcessResponse = function(result) {
if (Array.isArray(result)) {
return result.map(row => {
for (column in row) {
if (row[column] && row[column].toJSON) {
row[column] = row[column].toJSON();
}
}
return row;
});
} else {
for (column in result) {
if (result[column] && result[column].toJSON) {
result[column] = result[column].toJSON();
}
}
return result;
}
};
App's full version (lib/core/app.js:396-494) — handles JSON parsing, date formatting, .toJSON(), and nulls:
const formatRecord = (record, meta) => {
for (column in record) {
if (record[column] != null) {
if (meta.has(column)) {
const info = meta.get(column);
if (['json', 'object', 'array'].includes(info.type)) {
if (typeof record[column] == 'string') {
try {
record[column] = JSON.parse(record[column]);
} catch (err) {
console.warn(err);
}
}
}
if (info.type == 'date') {
// date formatting logic...
}
if (info.type == 'time') {
// time formatting logic...
}
} else {
// auto-detect datetime strings...
}
if (record[column] == undefined) {
record[column] = null;
} else if (record[column].toJSON) {
record[column] = record[column].toJSON();
}
}
}
return record;
};
options.postProcessResponse = function (result, queryContext) {
const meta = new Map();
if (Array.isArray(queryContext)) {
for (let item of queryContext) {
if (item.name && item.type) {
meta.set(item.name, item);
}
}
}
if (Array.isArray(result)) {
return result.map((record) => formatRecord(record, meta));
} else {
return formatRecord(result, meta);
}
};
The critical difference: the app's version accepts queryContext (the meta array from the server action), builds a Map of column types, and calls JSON.parse() on columns typed as json/object/array. The session store's version ignores queryContext entirely and only calls .toJSON().