import "compare-utf8";
const throwFilterOutput = {
  *push(_change) {
    throw new Error("Output not set");
  },
  *filter(_node) {
    throw new Error("Output not set");
  },
  beginFilter() {
  },
  endFilter() {
  }
};
class FilterStart {
  #input;
  #output = throwFilterOutput;
  constructor(input) {
    this.#input = input;
    input.setOutput(this);
  }
  setFilterOutput(output) {
    this.#output = output;
  }
  destroy() {
    this.#input.destroy();
  }
  getSchema() {
    return this.#input.getSchema();
  }
  *push(change) {
    yield* this.#output.push(change, this);
  }
  *fetch(req) {
    this.#output.beginFilter();
    try {
      for (const node of this.#input.fetch(req)) {
        if (node === "yield") {
          yield node;
          continue;
        }
        if (yield* this.#output.filter(node)) {
          yield node;
        }
      }
    } finally {
      this.#output.endFilter();
    }
  }
}
class FilterEnd {
  #start;
  #input;
  #output = throwFilterOutput;
  constructor(start, input) {
    this.#start = start;
    this.#input = input;
    input.setFilterOutput(this);
  }
  *fetch(req) {
    for (const node of this.#start.fetch(req)) {
      yield node;
    }
  }
  beginFilter() {
  }
  endFilter() {
  }
  *filter(_node) {
    return true;
  }
  setOutput(output) {
    this.#output = output;
  }
  destroy() {
    this.#input.destroy();
  }
  getSchema() {
    return this.#input.getSchema();
  }
  *push(change) {
    yield* this.#output.push(change, this);
  }
}
function buildFilterPipeline(input, delegate, pipeline) {
  const filterStart = new FilterStart(input);
  delegate.addEdge(input, filterStart);
  const middle = pipeline(filterStart);
  delegate.addEdge(filterStart, middle);
  const filterEnd = new FilterEnd(filterStart, middle);
  delegate.addEdge(middle, filterEnd);
  return filterEnd;
}
export {
  FilterEnd,
  FilterStart,
  buildFilterPipeline,
  throwFilterOutput
};
//# sourceMappingURL=filter-operators.js.map
