Options
All
  • Public
  • Public/Protected
  • All
Menu

The experimental Object-Resource Mapping (ORM) layer is a set of constructs to support idiomatic use of object-oriented Javascript with the core m-ld API. Instead of programming with reads and writes to the domain graph, you manipulate Javascript objects that reflect the domain.

🧪 ORM is currently used internally in extensions and has not yet been tested in an application. If it sounds just like what you're looking to do in your application, please let us know!

An ORM domain object is a top-level container for a mutable graph of "subjects" in-memory, where subjects are instances of Javascript classes, and graph edges are straightforward class properties.

Since read operations like traversal of graph edges are asynchronous in m-ld, an ORM domain can be in an "updating" state, in which some edge may not be fully loaded (sometimes called a "fault"). This mode is entered using the updating method. It gives access to an OrmUpdating state, from which graph content can be loaded. An updating state is required to create new subject instances attached to the domain object (also since their properties may need loading).

Mutations of the graph by the app MUST NOT be done in an updating state (a subject property that is not yet loaded could have an unexpected value of undefined or empty; and the app mutation may be overridden by an asynchronous load). An exception to this is setting the initial properties of a new subject. Changes to a subject, or to the whole ORM domain, can be committed to a writeable m-ld state.

see

OrmSubject

experimental

Hierarchy

  • OrmDomain

Implements

Index

Constructors

constructor

Properties

Readonly app

app: MeldApp

Readonly config

config: MeldConfig

Readonly context

context: MeldContext

Readonly scope

scope: OrmScope

Global scope for the domain

Methods

commit

  • Obtain an update that captures every mutation made by the app to the domain since the domain was last updated. The update should be immediately written to the m-ld engine. This method also REVERTS the mutations made in the app code. This is because the updates will be very quickly re-applied, having been processed by the m-ld engine, in the next update cycle.

    Returns Update

createScope

  • createScope(): OrmScope
  • A scope allows a code module such as an extension to avoid seeing some other module's ORM classes when asking for a subject instance. This can be important if the module's subject scope intersects with another module's. Note that in such circumstances it's probably a good idea to use module-specific properties, to avoid interference.

    Returns OrmScope

upToDate

  • upToDate(): Promise<unknown>
  • Allows the caller to wait for any active updating state to go out of scope, so that the app is free to mutate ORM subjects without risk of faults. This method can be used to protect any code that is called asynchronously, such as an event handler in a user interface.

    Returns Promise<unknown>

updating

  • Call to obtain an updating state of the domain, to be used to create or load ORM subjects.

    Type parameters

    • T

    Parameters

    • state: MeldReadState

      a readable m-ld core API state

    • proc: (orm: OrmUpdating) => T | Promise<T>

      a procedure that uses the updating state – the given updating state is guaranteed to remain valid until the returned promise settles.

    Returns Promise<T>

Legend

  • 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.1-edge.4 Source code licensed MIT. Privacy policy