MCPcopy Create free account
hub / github.com/ShipSecAI/studio / unwrapToObject

Function unwrapToObject

packages/component-sdk/src/schema-validation.ts:260–294  ·  view source on GitHub ↗
(
  schema: z.ZodTypeAny
)

Source from the content-addressed store, hash-verified

258}
259
260function unwrapToObject(
261 schema: z.ZodTypeAny
262): z.ZodObject<any, any> | null {
263 let current = schema;
264
265 while (true) {
266 const def = (current as any)._def as ZodDef | undefined;
267 const typeName = getDefType(def);
268
269 if (!def) {
270 return null;
271 }
272
273 if (typeName === 'object') {
274 return current as z.ZodObject<any, any>;
275 }
276
277 if (typeName === 'optional' || typeName === 'nullable' || typeName === 'default') {
278 current = def.innerType;
279 continue;
280 }
281
282 if (typeName === 'effects') {
283 current = def.schema;
284 continue;
285 }
286
287 if (typeName === 'pipe') {
288 current = def.out ?? def.schema ?? def.innerType ?? def.in ?? current;
289 continue;
290 }
291
292 return null;
293 }
294}
295
296/**
297 * Check if schema is z.any() or z.unknown()

Callers 2

validateComponentSchemaFunction · 0.70
validateParameterSchemaFunction · 0.70

Calls 1

getDefTypeFunction · 0.70

Tested by

no test coverage detected