Hyperlinkv0.8.0-beta.28

SchemaAST

SchemaAST.Filterclasseffect/SchemaAST.ts:2906
Filter<E>

Represents a single validation check attached to an AST node.

Details

  • run — the validation function. Returns undefined on success, or an Issue on failure.
  • annotations — optional filter-level metadata (expected message, meta tags, arbitrary constraint hints).
  • aborted — when true, parsing stops immediately after this filter fails (no further checks run).

Use .annotate() to add metadata and .abort() to mark as aborting. Combine with another check via .and() to form a FilterGroup.

export class Filter<in E> extends Pipeable.Class {
  readonly _tag = "Filter"
  readonly run: (input: E, self: AST, options: ParseOptions) => SchemaIssue.Issue | undefined
  readonly annotations: Schema.Annotations.Filter | undefined
  /**
   * Whether the parsing process should be aborted after this check has failed.
   */
  readonly aborted: boolean

  constructor(
    run: (input: E, self: AST, options: ParseOptions) => SchemaIssue.Issue | undefined,
    annotations: Schema.Annotations.Filter | undefined = undefined,
    /**
     * Whether the parsing process should be aborted after this check has failed.
     */
    aborted: boolean = false
  ) {
    super()
    this.run = run
    this.annotations = annotations
    this.aborted = aborted
  }
  annotate(annotations: Schema.Annotations.Filter): Filter<E> {
    return new Filter(this.run, { ...this.annotations, ...annotations }, this.aborted)
  }
  abort(): Filter<E> {
    return new Filter(this.run, this.annotations, true)
  }
  and(other: Check<E>, annotations?: Schema.Annotations.Filter): FilterGroup<E>
  and(other: Check<E>, annotations?: Schema.Annotations.Filter): FilterGroup<E> {
    return new FilterGroup([this, other], annotations)
  }
}
Referenced by 7 symbols