PY / Core / lib_bejson_provider.py
System
PY
Family
Core
API Density
8
Public API Surface
class BEJSONProviderdef bejson_core_atomic_writedef get_fields_mapdef get_index_schemadef get_paths_schemadef load_bejsondef now_isodef save_bejson
Full Source Implementation
FILE // lib_bejson_provider.py
"""
Library: lib_bejson_provider.py
Family: Core
Jurisdiction: ["BEJSON_LIBRARIES", "PY"]
Status: OFFICIAL
Author: Elton Boehnen
Version: 2.0 OFFICIAL
MFDB Version: 1.31
Format_Creator: Elton Boehnen
Date: 2026-05-18
Description: Data provider interface for abstracted BEJSON storage access.
"""
import os
import json
import datetime
try:
from lib_bejson_core import bejson_core_atomic_write
except ImportError:
def bejson_core_atomic_write(p, d):
tmp = p + ".tmp"
with open(tmp, 'w') as f: json.dump(d, f, indent=2)
os.replace(tmp, p)
class BEJSONProvider:
@staticmethod
def get_paths_schema():
return {"Format": "BEJSON", "Format_Version": "104a", "Format_Creator": "Elton Boehnen", "Schema_Version": "v1.0", "Application_Name": "BEJSON Pad", "Records_Type": ["PathEntry"], "Fields": [{"name": "path_id", "type": "string"}, {"name": "path_type", "type": "string"}, {"name": "path", "type": "string"}, {"name": "label", "type": "string"}, {"name": "created_at", "type": "string"}], "Values": []}
@staticmethod
def get_index_schema():
return {"Format": "BEJSON", "Format_Version": "104db", "Format_Creator": "Elton Boehnen", "Records_Type": ["Category", "Note"], "Fields": [{"name": "Record_Type_Parent", "type": "string"}, {"name": "cat_id", "type": "string", "Record_Type_Parent": "Category"}, {"name": "cat_name", "type": "string", "Record_Type_Parent": "Category"}, {"name": "created_at_cat", "type": "string", "Record_Type_Parent": "Category"}, {"name": "note_id", "type": "string", "Record_Type_Parent": "Note"}, {"name": "note_name", "type": "string", "Record_Type_Parent": "Note"}, {"name": "cat_id_fk", "type": "string", "Record_Type_Parent": "Note"}, {"name": "file_path", "type": "string", "Record_Type_Parent": "Note"}, {"name": "created_at_note", "type": "string", "Record_Type_Parent": "Note"}, {"name": "updated_at", "type": "string", "Record_Type_Parent": "Note"}], "Values": []}
@staticmethod
def load_bejson(path, default_schema):
if os.path.exists(path):
with open(path, 'r') as f: return json.load(f)
return default_schema
@staticmethod
def save_bejson(path, data):
# FIX: Transitioned to atomic write for consistency and safety
bejson_core_atomic_write(path, data)
@staticmethod
def get_fields_map(db): return {f["name"]: i for i, f in enumerate(db["Fields"])}
@staticmethod
def now_iso(): return datetime.datetime.utcnow().strftime("%Y-%m-%dT%H:%M:%SZ")
built from BEJSON HTML3 Libraries 2.0