All checks were successful
Deploy mindnet to llm-node / deploy (push) Successful in 3s
23 lines
824 B
Python
23 lines
824 B
Python
from __future__ import annotations
|
|
import json
|
|
import os
|
|
from functools import lru_cache
|
|
from jsonschema import Draft202012Validator, RefResolver
|
|
|
|
SCHEMAS_DIR = os.getenv("SCHEMAS_DIR", os.path.join(os.path.dirname(os.path.dirname(__file__)), "..", "schemas"))
|
|
|
|
@lru_cache(maxsize=16)
|
|
def load_schema(name: str) -> dict:
|
|
# name: "note.schema.json" | "chunk.schema.json" | "edge.schema.json"
|
|
path = os.path.join(SCHEMAS_DIR, name)
|
|
if not os.path.isfile(path):
|
|
raise FileNotFoundError(f"Schema not found: {path}")
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
return json.load(f)
|
|
|
|
@lru_cache(maxsize=16)
|
|
def get_validator(name: str) -> Draft202012Validator:
|
|
schema = load_schema(name)
|
|
resolver = RefResolver.from_schema(schema)
|
|
return Draft202012Validator(schema, resolver=resolver)
|