FieldProcessingChain class exported ✓ 100.0%

Last updated: 2026-03-01T23:25:47.106Z

Metrics

LOC: 55 Complexity: 3 Params: 0 Coverage: 100.0% (18/18 lines, 0x executed)

Signature

class FieldProcessingChain

Source Code

export class FieldProcessingChain {
  private _classifiers: FieldClassifier[] = [];

  // ── Classify ─────────────────────────────────────────────────────────────────

  /**
   * Classifiers to run in order — each one is a named, injectable step.
   * The first classifier that returns a confident result wins.
   * Chrome AI (detectAsync) is called only in runAsync / stream.
   *
   * Each call to classify() REPLACES the previous list (no appending).
   */
  classify(...classifiers: FieldClassifier[]): this {
    this._classifiers = classifiers;
    return this;
  }

  // ── Helper ───────────────────────────────────────────────────────────────────

  private applyResult(field: FormField, result: PipelineResult): void {
    field.fieldType = result.type;
    field.detectionMethod = result.method;
    field.detectionConfidence = result.confidence;
    field.detectionDurationMs = result.durationMs;
    field.timings = result.timings;
    field.predictions = result.predictions;
    field.decisionTrace = result.decisionTrace;
  }

  // ── Execution modes ──────────────────────────────────────────────────────────

  /**
   * Async run — awaits every classifier (including Chrome AI) per field,
   * then returns all fields at once.
   */
  async runAsync(fields: FormField[]): Promise<FormField[]> {
    const pipeline = new DetectionPipeline(this._classifiers);
    for (const field of fields) {
      this.applyResult(field, await pipeline.runAsync(field));
    }
    return fields;
  }

  /**
   * Streaming run — yields each FormField immediately after it is classified.
   * Enables real-time UI updates while classification is still in progress.
   */
  async *stream(fields: FormField[]): AsyncGenerator<FormField> {
    const pipeline = new DetectionPipeline(this._classifiers);
    for (const field of fields) {
      this.applyResult(field, await pipeline.runAsync(field));
      yield field;
    }
  }
}

Members

Name Kind Visibility Status Signature
classify method - classify(...classifiers: FieldClassifier[]): : this
applyResult method private - applyResult(field: FormField, result: PipelineResult): : void
runAsync method - runAsync(fields: FormField[]): : Promise<FormField[]>
stream method - stream(fields: FormField[]): : AsyncGenerator<FormField>

Dependencies (Outgoing)

graph LR FieldProcessingChain["FieldProcessingChain"] FormField["FormField"] DetectionPipeline["DetectionPipeline"] FieldClassifier["FieldClassifier"] PipelineResult["PipelineResult"] FieldProcessingChain -->|uses| FormField FieldProcessingChain -->|uses| DetectionPipeline FieldProcessingChain -->|uses| FieldClassifier FieldProcessingChain -->|uses| PipelineResult style FieldProcessingChain fill:#dbeafe,stroke:#2563eb,stroke-width:2px click FieldProcessingChain "100ca2148a515e25.html" click FormField "85cdbded927c91b0.html" click DetectionPipeline "c51ffbb1759babe9.html" click FieldClassifier "a9d6eb547441b869.html" click PipelineResult "e119f576dae70c2a.html"

Impact (Incoming)

graph LR FieldProcessingChain["FieldProcessingChain"] getActiveClassifiers["getActiveClassifiers"] buildClassificationChain["buildClassificationChain"] createField["createField"] getActiveClassifiers -->|uses| FieldProcessingChain buildClassificationChain -.->|instantiates| FieldProcessingChain createField -->|uses| FieldProcessingChain style FieldProcessingChain fill:#dbeafe,stroke:#2563eb,stroke-width:2px click FieldProcessingChain "100ca2148a515e25.html" click getActiveClassifiers "94c3286cfdb569c3.html" click buildClassificationChain "66b48c3d68622e6a.html" click createField "e0ae28ee278495ad.html"
SourceType
getActiveClassifiers uses
buildClassificationChain instantiates
createField uses