MCPcopy
hub / github.com/tinyplex/tinybase / unwrapSchema

Function unwrapSchema

src/schematizers/schematizer-effect/index.ts:25–50  ·  view source on GitHub ↗
(
  schema: TypeNode,
  defaultValue?: any,
  allowNull?: boolean,
)

Source from the content-addressed store, hash-verified

23type TypeNode = any;
24
25const unwrapSchema = (
26 schema: TypeNode,
27 defaultValue?: any,
28 allowNull?: boolean,
29): [any, any, boolean] => {
30 const ast = schema.ast || schema;
31 const type = ast._tag;
32 if (type === UNION) {
33 const types = ast.types;
34 const nonNullType = arrayFind(
35 types,
36 (t: TypeNode) => !(t._tag === LITERAL && isNull(t.literal)),
37 );
38 return [
39 {[TYPE]: getSimpleType(nonNullType)},
40 defaultValue,
41 allowNull ||
42 !!arrayFind(
43 types,
44 (t: TypeNode) => t._tag === LITERAL && isNull(t.literal),
45 ),
46 ];
47 }
48
49 return [{[TYPE]: getSimpleType(ast)}, defaultValue, allowNull || false];
50};
51
52const getSimpleType = (ast: TypeNode): string => {
53 const tag = ast?._tag;

Callers

nothing calls this directly

Calls 3

arrayFindFunction · 0.90
isNullFunction · 0.90
getSimpleTypeFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…