MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / observeShape

Function observeShape

packages/core/sdk/src/shape-inference.ts:200–219  ·  view source on GitHub ↗
(
  previous: ObservedShape | null,
  value: unknown,
  now: number,
)

Source from the content-addressed store, hash-verified

198
199/** Fold a new observation into an existing record, keeping the result bounded. */
200export const observeShape = (
201 previous: ObservedShape | null,
202 value: unknown,
203 now: number,
204): ObservedShape => {
205 const observed = inferShape(value);
206 let schema = previous === null ? observed : mergeShapes(previous.schema, observed);
207 for (
208 let depth = MAX_DEPTH;
209 depth > 0 && JSON.stringify(schema).length > MAX_SHAPE_JSON_CHARS;
210 depth--
211 ) {
212 schema = shrink(schema, depth);
213 }
214 return {
215 schema,
216 observations: (previous?.observations ?? 0) + 1,
217 updatedAt: now,
218 };
219};

Callers 2

observeFunction · 0.90

Calls 3

inferShapeFunction · 0.85
mergeShapesFunction · 0.85
shrinkFunction · 0.85

Tested by

no test coverage detected