Options
All
  • Public
  • Public/Protected
  • All
Menu

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 type http://js.m-ld.org/CommonJSExport. In this case the extension subject (or a subclass) should be instantiated directly using {@link OrmUpdating#get}, and the singleton object obtained with singleton, e.g. with data:

    {
     "@id": "myCustomSingleton",
     "@type": "http://js.m-ld.org/CommonJSExport",
     "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 ExtensionSubject<MyExtType>({ src, orm });
    const ext: MyExtType = extType.singleton;
    
  2. To load an instance from a graph subject having a type that is itself of type http://js.m-ld.org/CommonJSExport. 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",
       "@type": "http://js.m-ld.org/CommonJSExport",
       "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 });
    
experimental

Type parameters

  • T

    the expected instance type

Hierarchy

Index

Constructors

Accessors

Methods

Constructors

constructor

Accessors

singleton

  • get singleton(): T
  • see

    OrmSubject.updated

    Returns T

    an instance of the loaded Javascript class

Methods

Protected setUpdated

  • setUpdated(result: unknown | Promise<unknown>): void

Static declare

  • declare(id: Iri | undefined, moduleId: string, className: string): 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):

    clone.write(ExtensionSubject.declare(
      'myCustomClass',
      'my-custom-module',
      'MyExtClass'
    ));
    

    Parameters

    • id: Iri | undefined
    • moduleId: string

      the CommonJS module (must be accessible using require)

    • className: string

      the constructor name exported by the module

    Returns Subject

Static instance

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

    throws

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

    Type parameters

    Parameters

    Returns Promise<T>

Legend

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

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