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

Function makeIs

packages/effect/src/SchemaParser.ts:139–174  ·  view source on GitHub ↗
(ast: SchemaAST.AST)

Source from the content-addressed store, hash-verified

137}
138
139function makeIs<T>(ast: SchemaAST.AST): <I>(input: I) => input is I & T {
140 if (!CompilerRegistry.compilerAdaptersEnabled) {
141 const parser = asExit(run<T, never>(ast))
142 return <I>(input: I): input is I & T => {
143 const exit = parser(input, SchemaAST.defaultParseOptions)
144 if (Exit.isSuccess(exit)) return true
145 InternalSchemaCause.getSchemaIssueOrThrow(
146 exit.cause,
147 "Type guard adapter can only return false for schema issues"
148 )
149 return false
150 }
151 }
152 const entry = CompilerRegistry.resolve(ast)
153 const guard = entry.is
154 if (guard !== undefined) {
155 return <I>(input: I): input is I & T => {
156 try {
157 return guard(input, SchemaAST.defaultParseOptions)
158 } catch (error) {
159 InternalSchemaCause.getSchemaIssueOrThrow(
160 Cause.die(error),
161 "Type guard adapter can only return false for schema issues"
162 )
163 return false
164 }
165 }
166 }
167 const parser = entry.parser
168 return <I>(input: I): input is I & T => {
169 const exit = Effect.runSyncExit(parserResult<T, never>(parser(input, SchemaAST.defaultParseOptions), input))
170 if (Exit.isSuccess(exit)) return true
171 InternalSchemaCause.getSchemaIssueOrThrow(exit.cause, "Type guard adapter can only return false for schema issues")
172 return false
173 }
174}
175
176/** @internal */
177export function _is<T>(ast: SchemaAST.AST) {

Callers 1

guardFunction · 0.85

Calls 6

asExitFunction · 0.85
parserResultFunction · 0.85
resolveMethod · 0.80
runFunction · 0.70
parserFunction · 0.70
guardFunction · 0.70

Tested by

no test coverage detected