• Public
  • Public/Protected
  • All

An extension subject defines a way to declare that subjects in the domain should be represented by a certain Javascript class.

Extension subjects can be declared using declare, and are used in one of two modes:

  1. To load a singleton from a graph subject having a property http://js.m-ld.org/#require. In this case a SingletonExtensionSubject (or a subclass) should be instantiated directly using {@link OrmUpdating#get}, and the singleton object obtained with singleton, e.g. with data:

     "@id": "myCustomSingleton",
     "http://js.m-ld.org/#require": "my-custom-module",
     "http://js.m-ld.org/#class": "MyExtClass"

    The single custom instance for this class might be loaded with:

    const extType = orm.get('myCustomSingleton',
     src => new SingletonExtensionSubject<MyExtType>({ src, orm });
    const ext: MyExtType = extType.singleton;
  2. To load an instance from a graph subject that itself has the property type http://js.m-ld.org/#require. This indirection allows for many graph subjects to have custom type without re-declaring the module & export. The instance method is provided to load the instance, e.g. with data:

     "@id": "myCustomInstance",
     "@type": {
       "@id": "myCustomClass",
       "http://js.m-ld.org/#require": "my-custom-module",
       "http://js.m-ld.org/#class": "MyExtClass"

    A custom instance for this class might be loaded with:

    const ext: MyExtType = orm.get('myCustomInstance',
     src => ExtensionSubject.instance<MyExtType>({ src, orm });

Type parameters




Protected constructor


Static @type

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

Utility property definition for CommonJs require key

Static Protected factoryProps

factoryProps: SubjectProperty[] = ['moduleType', 'cjsModule', 'esmModule', 'className']


Protected factory

  • get factory(): Promise<{}>
  • Returns Promise<{}>


Protected instance

  • Override to provide custom post-initialisation behaviour




    Returns Promise<T>

    an instance of the loaded Javascript class

Protected invalidate

  • invalidate(): void
  • Returns void

Protected newInstance

  • Override to provide custom pre-initialisation behaviour


    Returns Promise<T>

Protected onPropertyUpdated

  • onPropertyUpdated(property: SubjectProperty, result: unknown | Promise<unknown>): void

Static declare

  • declare(id: Iri | undefined, requireId: string | undefined, importId: string | undefined, className: string, properties?: Subject): Subject
  • Extension subject declaration. Insert into the domain data to register a module export to be instantiated by an extension subject.

    For example (assuming a m-ld clone object):



    • id: Iri | undefined
    • requireId: string | undefined

      the CommonJS module, must be accessible using require

    • importId: string | undefined

      the ECMAScript module, must be accessible using import

    • className: string

      the constructor name exported by the module

    • Optional properties: Subject

      additional properties

    Returns Subject

Static instance

  • Obtain an instance of a custom class declared in the data as the type of the given graph subject.


    TypeError if the given graph subject does not have an extension type

    Type parameters

    • T


    Returns Promise<T>


  • 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