fix: add a JSON-parseable field, make small data tweaks, and add commentary on JSON fields
This commit is contained in:
@@ -567,6 +567,8 @@ export async function debugSettingsData(did?: string): Promise<void> {
|
|||||||
* - Web SQLite (wa-sqlite/absurd-sql): Auto-parses JSON strings to objects
|
* - Web SQLite (wa-sqlite/absurd-sql): Auto-parses JSON strings to objects
|
||||||
* - Capacitor SQLite: Returns raw strings that need manual parsing
|
* - Capacitor SQLite: Returns raw strings that need manual parsing
|
||||||
*
|
*
|
||||||
|
* Maybe consolidate with PlatformServiceMixin._parseJsonField
|
||||||
|
*
|
||||||
* @param value The value to parse (could be string or already parsed object)
|
* @param value The value to parse (could be string or already parsed object)
|
||||||
* @param defaultValue Default value if parsing fails
|
* @param defaultValue Default value if parsing fails
|
||||||
* @returns Parsed object or default value
|
* @returns Parsed object or default value
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ export type Contact = {
|
|||||||
// When adding a property:
|
// When adding a property:
|
||||||
// - Consider whether it should be added when exporting & sharing contacts, eg. DataExportSection
|
// - Consider whether it should be added when exporting & sharing contacts, eg. DataExportSection
|
||||||
// - If it's a boolean, it should be converted from a 0/1 integer in PlatformServiceMixin._mapColumnsToValues
|
// - If it's a boolean, it should be converted from a 0/1 integer in PlatformServiceMixin._mapColumnsToValues
|
||||||
|
// - If it's a JSON string, it should be converted to an object/array in PlatformServiceMixin._mapColumnsToValues
|
||||||
|
//
|
||||||
|
|
||||||
did: string;
|
did: string;
|
||||||
contactMethods?: Array<ContactMethod>;
|
contactMethods?: Array<ContactMethod>;
|
||||||
|
|||||||
@@ -14,6 +14,12 @@ export type BoundingBox = {
|
|||||||
* New entries that are boolean should also be added to PlatformServiceMixin._mapColumnsToValues
|
* New entries that are boolean should also be added to PlatformServiceMixin._mapColumnsToValues
|
||||||
*/
|
*/
|
||||||
export type Settings = {
|
export type Settings = {
|
||||||
|
//
|
||||||
|
// When adding a property:
|
||||||
|
// - If it's a boolean, it should be converted from a 0/1 integer in PlatformServiceMixin._mapColumnsToValues
|
||||||
|
// - If it's a JSON string, it should be converted to an object/array in PlatformServiceMixin._mapColumnsToValues
|
||||||
|
//
|
||||||
|
|
||||||
// default entry is keyed with MASTER_SETTINGS_KEY; other entries are linked to an account with account ID
|
// default entry is keyed with MASTER_SETTINGS_KEY; other entries are linked to an account with account ID
|
||||||
id?: string | number; // this is erased for all those entries that are keyed with accountDid
|
id?: string | number; // this is erased for all those entries that are keyed with accountDid
|
||||||
|
|
||||||
|
|||||||
@@ -315,7 +315,7 @@ export function didInfoForContact(
|
|||||||
return { displayName: "You", known: true };
|
return { displayName: "You", known: true };
|
||||||
} else if (contact) {
|
} else if (contact) {
|
||||||
return {
|
return {
|
||||||
displayName: contact.name || "Contact With No Name",
|
displayName: contact.name || "Contact Without a Name",
|
||||||
known: true,
|
known: true,
|
||||||
profileImageUrl: contact.profileImageUrl,
|
profileImageUrl: contact.profileImageUrl,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ export async function testServerRegisterUser() {
|
|||||||
|
|
||||||
// Make a payload for the claim
|
// Make a payload for the claim
|
||||||
const vcPayload = {
|
const vcPayload = {
|
||||||
sub: "RegisterAction",
|
sub: identity0.did,
|
||||||
vc: {
|
vc: {
|
||||||
"@context": ["https://www.w3.org/2018/credentials/v1"],
|
"@context": ["https://www.w3.org/2018/credentials/v1"],
|
||||||
type: ["VerifiableCredential"],
|
type: ["VerifiableCredential"],
|
||||||
|
|||||||
@@ -275,16 +275,22 @@ export const PlatformServiceMixin = {
|
|||||||
|
|
||||||
// Convert SQLite integer booleans to JavaScript booleans
|
// Convert SQLite integer booleans to JavaScript booleans
|
||||||
if (
|
if (
|
||||||
|
// settings
|
||||||
column === "isRegistered" ||
|
column === "isRegistered" ||
|
||||||
column === "finishedOnboarding" ||
|
column === "finishedOnboarding" ||
|
||||||
column === "filterFeedByVisible" ||
|
column === "filterFeedByVisible" ||
|
||||||
column === "filterFeedByNearby" ||
|
column === "filterFeedByNearby" ||
|
||||||
|
column === "hasBackedUpSeed" ||
|
||||||
column === "hideRegisterPromptOnNewContact" ||
|
column === "hideRegisterPromptOnNewContact" ||
|
||||||
column === "showContactGivesInline" ||
|
column === "showContactGivesInline" ||
|
||||||
column === "showGeneralAdvanced" ||
|
column === "showGeneralAdvanced" ||
|
||||||
column === "showShortcutBvc" ||
|
column === "showShortcutBvc" ||
|
||||||
column === "warnIfProdServer" ||
|
column === "warnIfProdServer" ||
|
||||||
column === "warnIfTestServer"
|
column === "warnIfTestServer" ||
|
||||||
|
// contacts
|
||||||
|
column === "iViewContent" ||
|
||||||
|
column === "registered" ||
|
||||||
|
column === "seesMe"
|
||||||
) {
|
) {
|
||||||
if (value === 1) {
|
if (value === 1) {
|
||||||
value = true;
|
value = true;
|
||||||
@@ -294,13 +300,9 @@ export const PlatformServiceMixin = {
|
|||||||
// Keep null values as null
|
// Keep null values as null
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle JSON fields like contactMethods
|
// Convert SQLite JSON strings to objects/arrays
|
||||||
if (column === "contactMethods" && typeof value === "string") {
|
if (column === "contactMethods" || column === "searchBoxes") {
|
||||||
try {
|
value = this._parseJsonField(value, []);
|
||||||
value = JSON.parse(value);
|
|
||||||
} catch {
|
|
||||||
value = [];
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
obj[column] = value;
|
obj[column] = value;
|
||||||
@@ -310,10 +312,13 @@ export const PlatformServiceMixin = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Self-contained implementation of parseJsonField
|
* Safely parses JSON strings with fallback to default value.
|
||||||
* Safely parses JSON strings with fallback to default value
|
* Handles different SQLite implementations:
|
||||||
|
* - Web SQLite (wa-sqlite/absurd-sql): Auto-parses JSON strings to objects
|
||||||
|
* - Capacitor SQLite: Returns raw strings that need manual parsing
|
||||||
*
|
*
|
||||||
* Consolidate this with src/libs/util.ts parseJsonField
|
* See also src/db/databaseUtil.ts parseJsonField
|
||||||
|
* and maybe consolidate
|
||||||
*/
|
*/
|
||||||
_parseJsonField<T>(value: unknown, defaultValue: T): T {
|
_parseJsonField<T>(value: unknown, defaultValue: T): T {
|
||||||
if (typeof value === "string") {
|
if (typeof value === "string") {
|
||||||
|
|||||||
Reference in New Issue
Block a user