unacy / detectMetadataKind
Function: detectMetadataKind()
function detectMetadataKind(meta): "primitive" | "enum" | "class" | "tuple" | "record" | "unknown";Defined in: packages/core/src/utils/validation.ts:434
Detect the kind of a metadata object by inspecting its type field.
Resolution priority: primitive → class → tuple → record → enum. Returns 'unknown' when the value is not a recognised metadata shape.
Parameters
| Parameter | Type | Description |
|---|---|---|
meta | unknown | Metadata object to categorise |
Returns
"primitive" | "enum" | "class" | "tuple" | "record" | "unknown"
The detected kind string
Remarks
Resolution priority order: primitive → class → tuple → record → enum → unknown. This ordering is important: a class constructor would otherwise match the object check, and a tuple schema (array) would match the record check, so the dispatcher checks the more specific types first.
Example
detectMetadataKind({ name: 'Celsius', type: 'number' }); // 'primitive'
detectMetadataKind({ name: 'Point', type: { x: 'number', y: 'number' } }); // 'record'
detectMetadataKind({ name: 'RGB', type: ['number', 'number', 'number'] }); // 'tuple'
detectMetadataKind({ name: 'Direction', type: Direction }); // 'enum' (if Direction is an enum)Use When
You need to dynamically dispatch on the kind of a metadata object at runtime (e.g., in serialisers or schema generators built on top of unacy).