Convert a Python `value` to an IndexedDB-compatible format. Values are serialized using Flatted (for circular reference support) with type information to enable proper deserialization. It returns a JSON string representing the serialized value. Will raise a TypeError if the va
(value)
| 55 | |
| 56 | |
| 57 | def _convert_to_idb(value): |
| 58 | """ |
| 59 | Convert a Python `value` to an IndexedDB-compatible format. |
| 60 | |
| 61 | Values are serialized using Flatted (for circular reference support) |
| 62 | with type information to enable proper deserialization. It returns a |
| 63 | JSON string representing the serialized value. |
| 64 | |
| 65 | Will raise a TypeError if the value type is not supported. |
| 66 | """ |
| 67 | if is_none(value): |
| 68 | return _stringify(["null", 0]) |
| 69 | if isinstance(value, (bool, float, int, str, list, dict, tuple)): |
| 70 | return _stringify(["generic", value]) |
| 71 | if isinstance(value, bytearray): |
| 72 | return _stringify(["bytearray", list(value)]) |
| 73 | if isinstance(value, memoryview): |
| 74 | return _stringify(["memoryview", list(value)]) |
| 75 | raise TypeError(f"Cannot serialize type {type(value).__name__} for storage.") |
| 76 | |
| 77 | |
| 78 | def _convert_from_idb(value): |