MCPcopy Create free account
hub / github.com/effect-app/libs / getParser

Method getParser

repos/effect/packages/effect/src/SchemaAST.ts:2065–2239  ·  view source on GitHub ↗

@internal

(recur: (ast: AST) => SchemaParser.Parser)

Source from the content-addressed store, hash-verified

2063 * An `Objects` node with no properties and no index signatures performs only a
2064 * non-nullish check: it accepts any value except `null` and `undefined`,
2065 * including primitive values.
2066 *
2067 * **Gotchas**
2068 *
2069 * Duplicate property names throw at construction time.
2070 *
2071 * **Example** (Inspecting a struct AST)
2072 *
2073 * ```ts import.meta.vitest
2074 * import { Schema, SchemaAST } from "effect"
2075 *
2076 * const schema = Schema.Struct({ name: Schema.String })
2077 * const ast = schema.ast
2078 *
2079 * if (SchemaAST.isObjects(ast)) {
2080 * ast.propertySignatures.map((ps) => [ps.name, ps.type._tag]) // => [["name", "String"]]
2081 * }
2082 * ```
2083 *
2084 * @see {@link isObjects}
2085 * @see {@link PropertySignature}
2086 * @see {@link IndexSignature}
2087 * @see {@link Arrays}
2088 * @category models
2089 * @since 4.0.0
2090 */
2091export class Objects extends Base {
2092 readonly _tag = "Objects"
2093 readonly propertySignatures: ReadonlyArray<PropertySignature>
2094 readonly indexSignatures: ReadonlyArray<IndexSignature>
2095 readonly encodingChecks: Checks | undefined
2096
2097 constructor(
2098 propertySignatures: ReadonlyArray<PropertySignature>,
2099 indexSignatures: ReadonlyArray<IndexSignature>,
2100 annotations?: Schema.Annotations.Annotations,
2101 checks?: Checks,
2102 encoding?: Encoding,
2103 context?: Context,
2104 encodingChecks?: Checks
2105 ) {
2106 super(annotations, checks, encoding, context)
2107 this.propertySignatures = propertySignatures
2108 this.indexSignatures = indexSignatures
2109 this.encodingChecks = encodingChecks
2110
2111 // Duplicate property signatures
2112 const duplicates = propertySignatures.map((ps) => ps.name).filter((name, i, arr) => arr.indexOf(name) !== i)
2113 if (duplicates.length > 0) {
2114 throw new Error(`Duplicate identifiers: ${JSON.stringify(duplicates)}. ts(2300)`)
2115 }
2116 }
2117 /** @internal */
2118 getParser(
2119 compile: SchemaParser.Compiler,
2120 compileConstructorDefault: SchemaParser.Compiler = compile
2121 ): SchemaParser.Parser {
2122 // oxlint-disable-next-line @typescript-eslint/no-this-alias

Callers

nothing calls this directly

Calls 13

effectIsExitFunction · 0.90
fromRefinementFunction · 0.85
wrapPropertyKeyIssueFunction · 0.85
resolveConcurrencyFunction · 0.85
getIndexSignatureKeysFunction · 0.85
pushMethod · 0.80
someMethod · 0.80
recurFunction · 0.70
addMethod · 0.65
combineMethod · 0.65
setMethod · 0.65
hasMethod · 0.45

Tested by

no test coverage detected