Documentation
    Preparing search index...

    Class OKFBackendAdapter

    File-based persistence adapter conforming to the Open Knowledge Format (OKF) standard. Serializes entities into flat directory layouts, optionally delegating to a Storage Adapter.

    Hierarchy (View Summary)

    Index

    Constructors

    Properties

    _alias: string = ''
    _middlewares: BM[] = []
    _params: BackendParameters = {}
    dataDir: string
    storage: AbstractStorageAdapter | null = null
    PKEY_IDENTIFIER: any = 'id'

    The string identifier for primary keys, mapped to 'id' by default.

    Accessors

    • get alias(): string

      Returns string

    • set alias(alias: string): void

      Parameters

      • alias: string

      Returns void

    Methods

    • Resolves the canonical database path for a record, respecting standard collection structures and hierarchical subcollection configurations.

      Parameters

      Returns string

    • Helper to flatten filters into a simple array.

      Parameters

      Returns Filter[]

    • Processes raw data entries to convert relational reference objects into native database foreign key IDs if the adapter has been configured with useNativeForeignKeys = true.

      Parameters

      • data: any[]

      Returns any[]

    • Parameters

      • stream: Readable

      Returns Promise<string>

    • Attaches a new middleware to the adapter's execution pipeline. Middlewares are triggered before or after database actions.

      Parameters

      • middleware: BM

        The instantiated middleware to attach.

      Returns void

      If a middleware with the same class name is already attached.

    • Executes an aggregation operation (sum, avg, distinct, min, max, count) on a query. The default implementation fetches all matching records and performs in-memory aggregation. Specific database adapters should override this to perform native query aggregation.

      Parameters

      • query: Query<any>

        The Query instance defining the collection and filters.

      • operation: "sum" | "avg" | "distinct" | "min" | "max" | "count"

        The aggregate operation.

      • Optionalproperty: string

        The name of the property to aggregate.

      Returns Promise<any>

      A promise resolving to the aggregated result.

    • Recursively removes the directory associated with a collection.

      Parameters

      • collection: string

        The collection folder path to clear.

      Returns Promise<void>

    • Removes a middleware from the pipeline by its class name.

      Parameters

      • middlewareClassName: string

        The exact name of the middleware class to remove.

      Returns void

    • Parameters

      • content: string
      • relativePath: string

      Returns any

    • Evaluates active query filters against a single DataObject instance in memory. Supports advanced operator comparisons (equals, contains, containsAny, etc.).

      Parameters

      Returns boolean

      true if the object matches all criteria, false otherwise.

    • Orchestrates the sequential execution of all attached middlewares for a given action.

      Parameters

      • dataObject: DataObjectClass<any>

        The payload traversing the middlewares.

      • action: BackendAction

        The context (READ, CREATE, UPDATE, DELETE).

      • timing: "before" | "after" = 'before'

        Whether to run the before or after pipeline.

      • Optionalparams: MiddlewareParams

        Optional parameters passed down to the middlewares.

      Returns Promise<DataObjectClass<any>>

      A promise resolving to the potentially mutated DataObject.

    • Parses markdown body to extract all internal hyperlinks (Obsidian-style [[WikiLinks]] or markdown Label links).

      Parameters

      • body: string

        The markdown text content.

      Returns string[]

      Array of unique target slugs or paths.

    • Parameters

      • collection: string
      • filename: string

      Returns Promise<string | null>

    • Generates the SQL up and down statements to create a collection table.

      Returns { downSql: string; upSql: string }

    • Generates the SQL up and down statements to apply a schema delta to a collection.

      Returns { downSql: never[]; upSql: never[] }

    • Helper method to extract the destination collection name from a DataObject.

      Parameters

      Returns string | undefined

      The resolved collection string.

    • Parameters

      • ref: string
      • Optionalmime: string

      Returns { bucket: string; mime: string | undefined; name: string; ref: string }

    • Resolves the relative storage path matching the OKF collection and metadata hierarchy. For telemetry: telemetry/YYYY-MM-DD/{type}/{HHMMSS}-{millis}-{bassinId}.json For other: {collection}/{uid}.json

      Parameters

      • dao: DataObjectClass<any>

        The data object model being persisted.

      • uid: string

        The unique identifier of the record.

      Returns string

      The relative file path string.

    • Retrieves a specific configuration parameter.

      Parameters

      • key: BackendParametersKeys

        The parameter key to fetch.

      Returns any

      The value associated with the key, or undefined.

    • Returns true if a given middleware is attached

      Parameters

      • className: string

      Returns boolean

      boolean

    • Outputs an adapter-level diagnostic message to the console if debug mode is enabled.

      Parameters

      • message: string

        The textual content to log.

      Returns void

      Use Backend.debug() or Backend.log() (which itself is deprecated in favor of specific levels) instead.

    • Executes a raw query on the backend. Only supported by SQL adapters.

      Parameters

      • sql: string
      • Optionalparams: any[]

      Returns Promise<any>

    • Parameters

      • collection: string

      Returns Promise<void>

    • Resolves incoming backlinks pointing to the target UID by scanning the collection.

      Parameters

      • collection: string

        The collection name.

      • targetUid: string

        The UID of the target document.

      Returns Promise<{ category: string; id: string; title: string }[]>

      Array of backlink references { id, title, category }.

    • Parameters

      Returns string

    • Overrides or adds a backend configuration parameter dynamically.

      Parameters

      • key: BackendParametersKeys

        The parameter key to modify.

      • value: any

        The new value to assign.

      Returns void