• Public
  • Public/Protected
  • All

A m-ld state machine extends the MeldState API for convenience, but note that the state of a machine is inherently mutable. For example, two consecutive asynchronous reads will not necessarily operate on the same state. To work with immutable state, use the read and write method overloads taking a procedure.

Type parameters

  • Q: BaseQuad





  • ask(pattern: Query): Promise<boolean>
  • Shorthand method to test whether or not a query pattern has a solution. No information is returned about the possible query solutions, just whether or not a solution exists.




    • pattern: Query

      a query with a @where pattern to test

    Returns Promise<boolean>

    resolves to true if the query's @where pattern matches data in the domain


  • countQuads(...args: Parameters<Source["match"]>): Promise<number>
  • Parameters

    • Rest ...args: Parameters<Source["match"]>

    Returns Promise<number>


  • Shorthand method for deleting a single Subject by its @id. This will also remove references to the given Subject from other Subjects.


    • id: string

      the Subject @id

    Returns Promise<MeldState>


  • Handle updates from the domain, from the moment this method is called. All data changes are signalled, strictly ordered according to the clone's logical clock. The updates can therefore be correctly used to maintain some other view of data, for example in a user interface or separate database. This will include the notification of 'rev-up' updates after a connect to the domain. To change this behaviour, ignore updates while the clone status is marked as outdated.

    The updates can be received either using the optional handler method, or by async-iterating the returned subscription, e.g.:

    for await (let [update] of clone.follow()) {
      // Do something with the update

    This method is equivalent to calling read with a no-op procedure.


    • Optional handler: UpdateProc

      a procedure to run for every update

    Returns MeldStateSubscription

    a subscription, allowing the caller to unsubscribe the handler


  • Shorthand method for retrieving a single Subject and its properties by its @id, if it exists.


    • id: string

      the Subject @id

    • Rest ...properties: SubjectProperty[]

      the properties to retrieve. If no properties are specified, all available properties of the subject will be returned.

    Returns Promise<GraphSubject | undefined>

    a promise resolving to the requested Subject with the requested properties, or undefined if not found


  • match(subject?: Term | null, predicate?: Term | null, object?: Term | null, graph?: Term | null): Stream<Q>
  • Returns a stream that processes all quads matching the pattern.


    • Optional subject: Term | null

      The optional subject.

    • Optional predicate: Term | null

      The optional predicate.

    • Optional object: Term | null

      The optional object.

    • Optional graph: Term | null

      The optional graph.

    Returns Stream<Q>

    The resulting quad stream.



  • Performs some read procedure on the current state, with notifications of subsequent updates.

    The updates can be received either using the optional handler method, or by async-iterating the returned subscription, e.g.:

    const subs = clone.read(async state => {
      // Do something with the initial state
    for await (let [update] of subs) {
      // Do something with the updates that follow the initial state

    NOTE: if the state procedure throws, it's up to you to handle the rejection; otherwise a global unresolved rejection may occur.

    The states passed to the procedure and the handler are immutable and guaranteed to remain 'live' until the procedure's return Promise resolves or rejects. If iterating, the iterated states are immutable until next, return or throw are called on the generator – if a for await loop is being used, these will be called by Javascript as the loop continues or terminates.

    Type parameters

    • T


    • procedure: StateProc<MeldReadState, T>

      a procedure to run for the current state

    • Optional handler: UpdateProc

      a procedure to run for every update that follows the state in the procedure

    Returns MeldStateSubscription<T>

    a subscription, allowing the caller to unsubscribe the handler

  • Actively reads data from the domain.

    The query executes in response to either subscription to the returned result, or calling .then.

    All results are guaranteed to derive from the current state; however since the results are delivered asynchronously, the current state is not guaranteed to be live in the subscriber. In order to keep this state alive during iteration (for example, to perform a consequential operation), perform the request in the scope of a read procedure instead.

    Type parameters


    • request: R

      the declarative read description

    Returns ReadResult

    read subjects


  • Performs an atomic update to the dataset. The deletes and inserts will be committed in the resolved state, which is expected to also be updatable for further modifications.


    Returns Promise<MeldState>


  • Performs some write procedure on the current state.

    The state passed to the procedure is immutable and is guaranteed to remain 'live' until its write method is called, or the procedure's return Promise resolves or rejects.


    • procedure: StateProc<MeldState>

      a procedure to run against the current state. This procedure is able to modify the given state, incrementally using its write method

    Returns Promise<MeldState>

  • Actively writes data to the domain.

    Type parameters

    • W

      one of the Write types


    • request: W

      the declarative write description

    Returns Promise<MeldState>

    the next state of the domain, changed by this write operation only


  • Constructor
  • Property
  • Method
  • Property
  • Method
  • Inherited property
  • Inherited method
  • Static property
  • Static method
  • Protected method

Generated using TypeDoc. Delivered by Vercel. @m-ld/m-ld - v0.10.0 Source code licensed MIT. Privacy policy