Setu-TS
    Preparing search index...

    Class MemoryAdapter

    In-memory implementation of IDatabaseAdapter.

    Stores entities in plain Map structures, supporting basic CRUD, filtering, sorting, pagination, and transaction semantics.

    0.1.0

    Implements

    Index
    transactionIsolationLevels: readonly TransactionIsolationLevel[] = ...

    Portable isolation levels this adapter can honestly provide.

    • Parameters

      • entity: string

        Entity name

      • primaryKey: string | readonly string[] = 'id'

        Primary key field(s), defaults to ['id']

      Returns IDataSource

      a non-transactional data source reading and writing the committed store directly. Initializing the store here (rather than on first read) is what fixes the primary key for the entity before any query runs.

    • Core findPage implementation shared between the non-transactional data source and the transaction overlay. The getRecords thunk lets the two callers — the committed store and the per-tx overlay — each supply their visible row set without duplicating the cursor-handling logic.

      Pipeline:

      1. Decode the incoming cursor. When absent, the walk starts at page one. When malformed, reject by name.
      2. When present, verify the sort fingerprint so a cross-sort cursor is refused rather than served a silently wrong page.
      3. Build the portable keyset predicate with keysetPredicate, conjoin it with the caller's own filter (when present), and apply where / filter / orderBy in the same order as findAll.
      4. Fetch limit + 1 rows (the one-extra-row probe): if more than limit are returned there IS a next page and the last returned row yields the next cursor; otherwise the page is terminal and nextCursor is null.
      5. When a projection is active, the key columns are added to the internal select so they participate in the probe and are available for cursor minting; they are stripped from the returned rows so the caller's projection is what comes back — plan §8 risk.

      decoded.orderedValues carries the value of EVERY ordered field (in orderBy order) from the last row of the previous page — not just key column values. This is what keysetPredicate indexes by position to build the "row after this one" comparison.

      Parameters

      • entity: string

        Entity name

      • query: NormalizedQuery

        Normalized page query (carries cursor, filter, orderBy, limit, and select)

      • getRecords: () => Record<string, unknown>[]

        Thunk supplying the visible rows at call time

      Returns Promise<PageResult>

      A PageResult carrying rows and the nextCursor

      When the token is malformed or the fingerprint does not match the current sort

    • Returns the internal store for an entity, creating it lazily.

      Parameters

      • entity: string

        Entity name

      • primaryKey: string | readonly string[] = 'id'

        Primary key field(s), defaults to ['id']

      Returns EntityStore

      The entity store

    • Insert a new entity. Generates key values if absent.

      Parameters

      • entity: string

        Entity name

      • data: Partial<Record<string, unknown>>

        Entity data

      Returns Promise<Record<string, unknown>>

      The inserted entity; rejects when a caller-supplied primary key is already carried by a stored row

    • Liveness probe (M95b §3.5): the process IS the backend, so the store is reachable exactly while this adapter is connected. Honest, not a special case — without it the indicator would omit reachable for the one backend it can actually vouch for.

      It reports MemoryAdapter.isReady rather than an unconditional true (M95b review): "is the backend reachable" and "am I connected to it" are the same question for an in-process store, and a probe that answered true for a disconnected adapter would model, for every third-party implementor reading this as the reference, the one pattern that makes a liveness probe lie.

      Returns Promise<boolean>

    • Update an existing entity by primary key, merging fields.

      Parameters

      • entity: string

        Entity name

      • id: EntityKey

        Primary key value (scalar or composite record)

      • data: Partial<Record<string, unknown>>

        Fields to merge

      Returns Promise<Record<string, unknown>>

      The updated entity

      If the entity does not exist