( row: Record<string, unknown>, idKey: PropertyKey )
| 43 | {} |
| 44 | |
| 45 | /** @internal */ |
| 46 | export const parseRow = <Encoded extends FieldValues>( |
| 47 | row: { id: string; _etag: string | null; data: string }, |
| 48 | idKey: PropertyKey, |
| 49 | defaultValues: Partial<Encoded> |
| 50 | ): PersistenceModelType<Encoded> => { |
| 51 | const data = (typeof row.data === "string" ? JSON.parse(row.data) : row.data) as object |
| 52 | return { ...defaultValues, ...data, [idKey]: row.id, _etag: row._etag ?? undefined } as PersistenceModelType<Encoded> |
| 53 | } |
| 54 | |
| 55 | const parseSelectRow = ( |
| 56 | row: Record<string, unknown>, |
| 57 | idKey: PropertyKey |
| 58 | ): any => { |
| 59 | const result: Record<string, unknown> = {} |
| 60 | for (const [key, value] of Object.entries(row)) { |
| 61 | if (key === "id") { |
| 62 | result[idKey as string] = value |
| 63 | result["id"] = value |
| 64 | } else if (typeof value === "string") { |
| 65 | try { |
| 66 | result[key] = JSON.parse(value) |
| 67 | } catch { |
| 68 | result[key] = value |
no test coverage detected
searching dependent graphs…