/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
import { astToFunction } from "./conformance-compiler.js";
import { forwardValidationToPeer } from "./peer-forwarding.js";
function createConformanceValidator(schema, supervisor, nextValidator) {
  const validate = astToFunction(schema, supervisor);
  if (!validate && !nextValidator) {
    return void 0;
  }
  return (value, session, location) => {
    const cfg = location.config?.supervision;
    if (cfg?.validate === false) {
      return;
    }
    if (cfg?.conformance !== false) {
      try {
        validate?.(value, session, location);
      } catch (e) {
        if (!forwardValidationToPeer(session, e)) {
          throw e;
        }
      }
    }
    if (value !== void 0) {
      nextValidator?.(value, session, location);
    }
  };
}
export {
  createConformanceValidator
};
//# sourceMappingURL=conformance.js.map
