(input: unknown, type: string)
| 1 | import { SchemaEntity } from "./schema"; |
| 2 | |
| 3 | function getIsDataTypeValid(input: unknown, type: string) { |
| 4 | // TODO: all pg types |
| 5 | switch (type) { |
| 6 | case "string": |
| 7 | return typeof input === "string"; |
| 8 | case "number": |
| 9 | return typeof input === "number"; |
| 10 | case "boolean": |
| 11 | return typeof input === "boolean"; |
| 12 | case "uuid": |
| 13 | return typeof input === "string" && input.length === 36; |
| 14 | case "date": |
| 15 | return typeof input === "string" && !!input.match(/^\d{4}-\d{2}-\d{2}$/); |
| 16 | case "datetime": |
| 17 | return ( |
| 18 | typeof input === "string" && |
| 19 | !!input.match(/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}$/) |
| 20 | ); |
| 21 | case "object": |
| 22 | return typeof input === "object"; |
| 23 | case "array": |
| 24 | return Array.isArray(input); |
| 25 | default: |
| 26 | return false; |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | export function validateEntityDataProp( |
| 31 | prop: string, |
no outgoing calls
no test coverage detected