MCPcopy Create free account
hub / github.com/clientdb/clientdb / getIsDataTypeValid

Function getIsDataTypeValid

engine/schema/validate.ts:3–28  ·  view source on GitHub ↗
(input: unknown, type: string)

Source from the content-addressed store, hash-verified

1import { SchemaEntity } from "./schema";
2
3function 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
30export function validateEntityDataProp(
31 prop: string,

Callers 1

validateEntityDataPropFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected