Interface Type<T>

Interface describing the Type, i.e., static constructable context, of classes extending the abstract Model base class.

interface Type<T> {
    commit<T>(this, operation, variables?): Observable<unknown>;
    new Typenew (...args): T;
    deleteAll<T>(this, uuids): Observable<unknown>;
    deleteOne<T>(this, uuid): Observable<unknown>;
    findAll<T>(this, filter, graph): Observable<Results<T>>;
    findOne<T>(this, shape, graph): Observable<T>;
    prototype: T;
    saveAll<T>(this, models, graph): Observable<T[]>;
    saveOne<T>(this, model, graph): Observable<T>;
    serialize<T>(this, model, shallow?): undefined | Shape<T>;
    treemap<T>(this, model, shallow?): undefined | Graph<T>;
    unravel<T>(this, graph): string;
    valuate<T>(this, model, field): unknown;
}

Type Parameters

Hierarchy

Constructors

  • Overridden and concretized constructor signature.

    Parameters

    • Rest ...args: Shape<Model<any>>[]

      The default class constructor rest parameter.

    Returns T

Properties

prototype: T

Overridden prototype signature.

Methods

  • Static commit method. Calling this method on a class extending the abstract Model base class, while supplying an operation and all its embedded variables, will dispatch the Querier.Operation to the respective Model repository through the highest priority Querier or, if no Querier is compatible, an error is thrown. This method is the entry point for all Model-related data transferral and is internally called by all other distinct methods of the Model.

    Type Parameters

    Parameters

    Returns Observable<unknown>

    An Observable of the commitmed operation.

    Throws

    An Observable ReferenceError on incompatibility.

    Example

    commit a query-type operation:

    import { ExampleModel } from './example-model';

    ExampleModel.commit(`query queryExample(variable: $variable) {
    result {
    field
    }
    }`, {
    variable: 'value'
    }).subscribe(console.log);
  • Static deleteAll method. Calling this method on a class extending the Model, while supplying an array of uuids, will dispatch the deletion of all Model instances identified by these UUIDs to the respective Model repository by internally calling commit with suitable arguments. Through this method, bulk-deletions from the respective Model repository can be achieved.

    Type Parameters

    Parameters

    • this: Model.Type<T>

      The explicit static polymorphic this parameter.

    • uuids: string[]

      An array of uuids of Models to be deleted.

    Returns Observable<unknown>

    An Observable of the deletion.

    Example

    Drop all model instances by UUIDs:

    import { ExampleModel } from './example-model';

    ExampleModel.deleteAll([
    'b050d63f-cede-46dd-8634-a80d0563ead8',
    'a0164132-cd9b-4859-927e-ba68bc20c0ae',
    'b3fca31e-95cd-453a-93ae-969d3b120712'
    ]).subscribe(console.log);
  • Static deleteOne method. Calling this method on a class extending the Model, while supplying an uuid, will dispatch the deletion of the Model instance identified by this UUID to the respective repository by internally calling the commit operation with suitable arguments. Through this method, the deletion of a single Model instance from the respective Model repository can be achieved.

    Type Parameters

    Parameters

    • this: Model.Type<T>

      The explicit static polymorphic this parameter.

    • uuid: string

      The uuid of the Model instance to be deleted.

    Returns Observable<unknown>

    An Observable of the deletion.

    Example

    Drop one model instance by UUID:

    import { ExampleModel } from './example-model';

    ExampleModel.deleteOne(
    '18f3aa99-afa5-40f4-90c2-71a2ecc25651'
    ).subscribe(console.log);
  • Static findAll method. Calling this method on a class extending the abstract Model base class, while supplying a filter to match Model instances by and a graph containing the fields to be included in the result, will dispatch a lookup operation to the respective repository by internally calling the commit operation with suitable arguments. Through this method, the bulk-lookup of Model instances from the respective Model repository can be achieved.

    Type Parameters

    Parameters

    Returns Observable<Results<T>>

    An Observable of the find operation.

    Example

    Lookup all UUIDs for model instances modified between two dates:

    import { ExampleModel } from './example-model';

    ExampleModel.findAll({
    expression: {
    conjunction: {
    operands: [
    {
    entity: {
    operator: 'GREATER_OR_EQUAL',
    path: 'modified',
    value: new Date('2021-01-01')
    }
    },
    {
    entity: {
    operator: 'LESS_OR_EQUAL',
    path: 'modified',
    value: new Date('2021-12-12')
    }
    }
    ],
    operator: 'AND'
    }
    }
    }, [
    'uuid',
    'field'
    ]).subscribe(console.log);
  • Static findOne method. Calling this method on a class extending the abstract Model base class, while supplying the shape to match the Model instance by and a graph describing the fields to be included in the result, will dispatch the lookup operation to the respective repository by internally calling the commit operation with suitable arguments. Through this method, the retrieval of one specific Model instance from the respective Model repository can be achieved.

    Type Parameters

    Parameters

    Returns Observable<T>

    An Observable of the find operation.

    Example

    Lookup one model instance by UUID:

    import { ExampleModel } from './example-model';

    ExampleModel.findOne({
    id: '2cfe7609-c4d9-4e4f-9a8b-ad72737db48a'
    }, [
    'uuid',
    'modified',
    'field'
    ]).subscribe(console.log);
  • Static saveAll method. Calling this method on a class extending the abstract Model base class, while supplying a list of models which to save and a graph describing the fields to be returned in the result, will dispatch the save operation to the respective Model repository by internally calling the commit operation with suitable arguments. Through this method, bulk-persistance of Model instances from the respective Model repository can be achieved.

    Type Parameters

    Parameters

    • this: Model.Type<T>

      The explicit static polymorphic this parameter.

    • models: T[]

      An array of Models to be saved.

    • graph: Graph<T>

      The Model.Graph of fields to be returned.

    Returns Observable<T[]>

    An Observable of the save operation.

    Example

    Persist multiple Models:

    import { ExampleModel } from './example-model';

    ExampleModel.saveAll([
    new ExampleModel({ field: 'example_1' }),
    new ExampleModel({ field: 'example_2' }),
    new ExampleModel({ field: 'example_3' })
    ], [
    'uuid',
    'modified',
    'field'
    ]).subscribe(console.log);
  • Static saveOne method. Calling this method on a class extending the abstract Model base class, while supplying a model which to save and a graph describing the fields to be returned in the result, will dispatch the save operation to the respective Model repository by internally calling the commit operation with suitable arguments. Through this method, persistance of one specific Model instance from the respective Model repository can be achieved.

    Type Parameters

    Parameters

    Returns Observable<T>

    An Observable of the save operation.

    Example

    Persist a model:

    import { ExampleModel } from './example-model';

    ExampleModel.saveOne(new ExampleModel({ field: 'example' }), [
    'uuid',
    'modified',
    'field'
    ]).subscribe(console.log);
  • Static serialize method. Calling this method on a class extending the Model, while supplying a model which to serialize and optionally enabling shallow serialization, will return the serialized Model.Shape of the Model, i.e., a plain JSON representation of all Model fields, or undefined, if the supplied model does not contain any fields or values. By serializing shallowly, only such properties defined on the supplied model are included (which means, all one-to-one and one-to-many associations are ignored). Through this method, the serialization of one specific Model instance from the respective Model repository can be achieved.

    Type Parameters

    Parameters

    • this: Model.Type<T>

      The explicit static polymorphic this parameter.

    • model: T

      The Model which is to be serialized.

    • shallow: boolean = false

      Whether to serialize the Model shallowly.

    Returns undefined | Shape<T>

    The Model.Shape of the Model or undefined.

    Example

    serialize a model:

    import { ExampleModel } from './example-model';

    const model = new ExampleModel({ field: 'example' });
    const shape = ExampleModel.serialize(model);
    console.log(shape); // { field: 'example' }
  • Static treemap method. Calling this method on a class extending the abstract Model base class, while supplying a model which to treemap and optionally enabling shallow treemapping, will return a Model.Graph describing the fields which are declared and defined on the supplied model, or undefined, if the supplied model does not contain any fields or values. By treemapping shallowly, only properties defined on the supplied model are included (which means, all one-to-one and one-to-many associations are ignored). Through this method, the Model.Graph for one specific Model instance from the respective Model repository can be retrieved.

    Type Parameters

    Parameters

    • this: Model.Type<T>

      The explicit static polymorphic this parameter.

    • model: T

      The Model which is to be treemapped.

    • shallow: boolean = false

      Whether to treemap the Model shallowly.

    Returns undefined | Graph<T>

    The Model.Graph of the Model or undefined.

    Example

    treemap a Model:

    import { ExampleModel } from './example-model';

    const model = new ExampleModel({ field: 'example' });
    const graph = ExampleModel.treemap(model);
    console.log(graph); // ['field']
  • Static unravel method. Calling this method on a class extending the abstract Model base class, while supplying a graph describing the fields which to unravel, will return the Model.Graph as raw string. Through this method, the Model.Graph for one specific Model instance from the respective Model repository can be unraveled into a raw string. This unraveled Model.Graph can then be consumed by, e.g., the commit method.

    Type Parameters

    Parameters

    Returns string

    The unraveled Model.Graph as raw string.

    Example

    unravel a Model.Graph:

    import { ExampleModel } from './example-model';

    const unraveled = ExampleModel.unravel([
    'uuid',
    'modified',
    'field'
    ]);

    console.log(unraveled); // '{id modified field}'
  • Static valuate method. Calling this method on a class extending the abstract Model base class, while supplying a model and a field which to valuate, will return the preprocessed value (e.g., primitive representation of JavaScript Dates) of the supplied field of the supplied model. Through this method, the preprocessed field value of one specific Model instance from the respective Model repository can be retrieved.

    Type Parameters

    Parameters

    Returns unknown

    The valuated field value.

    Example

    valuate a field:

    import { ExampleModel } from './example-model';

    const model = new ExampleModel({ created: new Date(0) });
    const value = ExampleModel.valuate(model, 'created');
    console.log(value); // '1970-01-01T00:00:00.000+00:00'

Generated using TypeDoc