Options
All
  • Public
  • Public/Protected
  • All
Menu

An Object-Resource Mapping (ORM) Subject is a Javascript class used to reflect graph nodes in a m-ld domain.

The constructor of an ORM subject should accept a GraphSubject from which derive its initial state. In the case of a new subject, which does not yet exist in the domain, this will only contain an @id (i.e. it's a Reference), so the constructor may also accept other values for initialising properties.

Local properties properties are then mapped to graph properties (edges) by calling initSrcProperties in the constructor. This ensures that any local changes to the object property values are tracked, and can be committed to the graph later using commit (usually called for a batch of subjects from OrmDomain.commit). E.g.

class Flintstone extends OrmSubject {
  @property(JsType.for(String))
  name: string;
  @property(JsType.for(Optional, Number))
  height?: number;

  constructor(src: GraphSubject) {
    super(src);
    this.initSrcProperties(src);
  }
}

Note that an ORM subject constructor should only ever be called by the passed construct callback of OrmUpdating.get, so that the subject is correctly registered with the ORM domain.

see

OrmDomain

experimental

Hierarchy

Index

Constructors

Protected constructor

Properties

Readonly src

Static @type

@type: JsProperty<unknown[], String> = new JsProperty('@type', JsType.for(Array, String))

Utility property definition for the JSON-LD @type key

Accessors

deleted

  • get deleted(): boolean
  • true if this subject does not exist in the domain

    Returns boolean

updated

  • get updated(): this | Promise<this>
  • Resolves when this subject's graph is up-to-date with the domain

    Returns this | Promise<this>

Methods

commit

  • Gathers all changes in the subject since the last update from state, returns them as a m-ld update for applying to the domain, and reverts them in anticipation of the resultant echoed update (which may differ due to the application of constraints).

    Returns Update

initSrcList

  • initSrcList<T>(src: GraphSubject, type: AtomType<T>, list: { length: number }, access: { get: (i: number) => ValueConstructed<T>; set: (i: number, v: ValueConstructed<T>) => unknown | Promise<unknown> }): void
  • Call from a subclass constructor to initialise the mapping between the graph and this subject's list items.

    Type parameters

    • T

    Parameters

    • src: GraphSubject

      a List graph subject to initialise the list from

    • type: AtomType<T>

      JSON-LD type of items in the list

    • list: { length: number }

      an array-like object having:

      1. a mutable length, which will be set during list updates
      2. numeric indexes, which will only be used to query for existence
      • [i: number]: unknown
      • length: number
    • access: { get: (i: number) => ValueConstructed<T>; set: (i: number, v: ValueConstructed<T>) => unknown | Promise<unknown> }

      will be called to get & set JSON-LD values for items in the list

      • get: (i: number) => ValueConstructed<T>
          • (i: number): ValueConstructed<T>
          • Parameters

            • i: number

            Returns ValueConstructed<T>

      • set: (i: number, v: ValueConstructed<T>) => unknown | Promise<unknown>
          • (i: number, v: ValueConstructed<T>): unknown | Promise<unknown>
          • Parameters

            • i: number
            • v: ValueConstructed<T>

            Returns unknown | Promise<unknown>

    Returns void

initSrcProperties

  • Call from a subclass constructor to initialise the mapping between the graph and this subject's properties, which have been declared with the {@link property} annotation in Typescript. Additional runtime property access metadata can be provided in the access parameter.

    Parameters

    • src: GraphSubject

      the initial graph subject – used for its property values

    • Default value access: {} = {}

      custom property access information

      • [local: string]: Any

    Returns void

initSrcProperty

  • initSrcProperty<T, S, O>(src: GraphSubject, local: (string & keyof this) | ObjKey<O>, property: JsProperty<T, S>, access?: Any<T, S>): void
  • Call from a subclass constructor to initialise the mapping between the graph and this subject's property. This method is for use in Javascript, and in scenarios where the structure of this ORM subject does not reflect the graph representation – for example, an aggregation member reflecting data from its parent graph subject.

    throws

    {RangeError} if the property has already been initialised

    Type parameters

    • T

    • S

    • O

    Parameters

    • src: GraphSubject

      the initial graph subject – only used for its property value

    • local: (string & keyof this) | ObjKey<O>

      the local property name. If the type in the graph cannot be cast to the property type, {@link #updated} will be rejected.

    • property: JsProperty<T, S>

      the property definition

    • Optional access: Any<T, S>

      custom property access information

    Returns void

onPropertiesUpdated

  • Called by the ORM domain when the subject's properties have been fully updated. The deleted flag will be set. Any reference properties or other asynchronous dependencies may not yet be loaded (may be 'faults').

    Parameters

    Returns void

Protected onPropertyUpdated

  • onPropertyUpdated(property: SubjectProperty, result: unknown | Promise<unknown>): void
  • Called when a graph subject (src) property is being updated.

    Parameters

    • property: SubjectProperty

      The property that is being updated.

    • result: unknown | Promise<unknown>

      If any property is asynchronously updated, the final value will only be definitively set when this promise resolves.

    Returns void

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