Serializes metadata field values for storage in Redis based on field type.
Converts JavaScript values to the appropriate format for Redis storage:
serializeMetadataField(fieldSchema: MetadataFieldSchema, fieldValue: unknown): string | number| Name | Type | Description |
|---|---|---|
fieldSchema* | MetadataFieldSchema | The metadata field schema definition |
fieldValue* | unknown | The value to serialize |
const tagSchema = { name: "category", type: "tag" as const };
serializeMetadataField(tagSchema, ["electronics", "gadgets"]);
// Returns: "electronics|gadgets"
const geoSchema = { name: "location", type: "geo" as const };
serializeMetadataField(geoSchema, [-122.4194, 37.7749]);
// Returns: "-122.4194,37.7749"
const geoshapeSchema = { name: "area", type: "geoshape" as const };
serializeMetadataField(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 };
serializeMetadataField(numericSchema, new Date("2023-01-01"));
// Returns: 1672531200 (Unix epoch timestamp in seconds)
serializeMetadataField(numericSchema, 42);
// Returns: 42