MCPcopy Create free account
hub / github.com/Effect-TS/effect / validate

Function validate

packages/effect/src/Schema.ts:1303–1322  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

1301 const parseOptions: SchemaAST.ParseOptions = { errors: "all", ...options?.parseOptions }
1302 const formatter = SchemaIssue.makeFormatterStandardSchemaV1(options)
1303 const validate: StandardSchemaV1<S["Encoded"], S["Type"]>["~standard"]["validate"] = (value: unknown) => {
1304 const scheduler = new Scheduler.MixedScheduler("sync")
1305 const fiber = Effect.runFork(
1306 Effect.match(decodeUnknownEffect(value, parseOptions), {
1307 onFailure: formatter,
1308 onSuccess: (value): StandardSchemaV1.Result<S["Type"]> => ({ value })
1309 }),
1310 { scheduler }
1311 )
1312 fiber.currentDispatcher?.flush()
1313 const exit = fiber.pollUnsafe()
1314 if (exit) {
1315 return makeStandardResult(exit)
1316 }
1317 return new Promise((resolve) => {
1318 fiber.addObserver((exit) => {
1319 resolve(makeStandardResult(exit))
1320 })
1321 })
1322 }
1323 if ("~standard" in self) {
1324 const out = self as any
1325 if ("validate" in out["~standard"]) return out

Callers

nothing calls this directly

Calls 6

makeStandardResultFunction · 0.85
pollUnsafeMethod · 0.80
addObserverMethod · 0.80
decodeUnknownEffectFunction · 0.70
resolveFunction · 0.70
flushMethod · 0.65

Tested by

no test coverage detected