Deserializes metadata field values from Redis storage based on field type.
Converts Redis-stored values back to JavaScript types:
Note: Numeric fields are returned as numbers. If you stored a Date object as a Unix epoch
timestamp, you'll need to manually convert it back to a Date object if needed:
new Date(numericValue * 1000)
deserializeMetadataField(fieldSchema: MetadataFieldSchema, fieldValue: unknown): unknown| Name | Type | Description |
|---|---|---|
fieldSchema* | MetadataFieldSchema | The metadata field schema definition |
fieldValue* | unknown | The value from Redis to deserialize |
const tagSchema = { name: "category", type: "tag" as const };
deserializeMetadataField(tagSchema, "electronics|gadgets");
// Returns: ["electronics", "gadgets"]
const geoSchema = { name: "location", type: "geo" as const };
deserializeMetadataField(geoSchema, "-122.4194,37.7749");
// Returns: [-122.4194, 37.7749]
const geoshapeSchema = { name: "area", type: "geoshape" as const };
deserializeMetadataField(geoshapeSchema, "POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))");
// Returns: "POLYGON((0 0, 0 10, 10 10, 10 0, 0 0))"
const numericSchema = { name: "created_at", type: "numeric" as const };
deserializeMetadataField(numericSchema, "1672531200");
// Returns: 1672531200 (number)
// To convert to Date: new Date(1672531200 * 1000)
deserializeMetadataField(numericSchema, "42");
// Returns: 42