Class MeshOSAbstract

MeshOS is an abstract base class for schema-driven entity management within the Mesh network. It provides a foundation for defining custom entities. By subclassing MeshOS, you can create entities with specific schemas and behaviors, enabling structured data storage, retrieval, and transactional workflows.

Standard CRUD methods are included and use your provided schema to fields to return in the response: create, retrieve, update, delete.

Search methods are included and use your provided schema to fields to return in the response: count, find, aggregate.

Implement other methods as needed for the entity's functionality; For example, subclass/override methods like create to also spawn a transactional workflow

import { MeshOS } from '@hotmeshio/hotmesh';
import { Types } from '@hotmeshio/hotmesh';
import { schema } from './schema'; // Import your schema
import * as workflows from './workflows';

class Widget extends MeshOS {

//Subclass the `connect` method to connect workers and
// hooks (optional) when the container starts
async connect() {
await this.meshData.connect({
entity: this.getEntity(),
//the `target widget workflow` runs as a transaction
target: function() {
return { hello: 'world' };
},
options: {
namespace: this.getNamespace(),
taskQueue: this.getTaskQueue(),
},
});
}

// subclass the `create` method to start a transactional
// workflow; use the options/search field to set default
// record data `{ ...input}` and invoke the `target widget workflow`
async create(input: Types.StringAnyType): Promise<Types.StringStringType> {
return await this.meshData.exec<Types.StringStringType>({
entity: this.getEntity(),
args: [{ ...input }],
options: {
id: input.id,
ttl: '6 months',
taskQueue: this.getTaskQueue(),
namespace: this.getNamespace(),
search: { data: { ...input }},
},
});
}
}

The schema defines the data model for your entity and is used for indexing and searching within the mesh network. Each field in the schema specifies the data type, whether it's required, and other indexing options.

Here's an example of a schema (schema.ts):

import { Types } from '@hotmeshio/hotmesh';

export const schema: Types.WorkflowSearchSchema = {
/**
* Unique identifier for the widget, including the entity prefix.
*/
id: {
type: 'TAG',
primitive: 'string',
required: true,
examples: ['H56789'],
},
/**
* entity type
*/
$entity: {
type: 'TAG',
primitive: 'string',
required: true,
examples: ['widget'],
},
/**
* Field indicating whether the widget is active ('y') or pruned ('n').
*/
active: {
type: 'TAG',
primitive: 'string',
required: true,
examples: ['y', 'n'],
},
// ... other fields as needed
};

In your entity class (Widget), you use this schema in the getSearchOptions method to define how your entity's data is indexed and searched.

Constructors

  • Instances of MeshOS are typically initialized as a set, using a manifest.json file that describes statically the fully set names, passwords, entities, etc. The static init method is invoked to start this process (typically at server startup).

    Parameters

    Returns MeshOS

Properties

connected: boolean = false
entity: string
meshData: MeshData
namespace: string
taskQueue: string
workflow: {} = {}
classes: Record<string, typeof MeshOS> = {}
databases: Record<string, DB> = {}
entities: Record<string, Entity> = {}
logger: ILogger = ...
namespaces: Namespaces = {}
profiles: Profiles = {}
schemas: Record<string, WorkflowSearchSchema> = {}

Methods

  • Aggregate matching entities

    Parameters

    • filter: {
          field: string;
          is:
              | "="
              | ">="
              | "<="
              | "[]";
          value: string;
      }[] = []
    • apply: {
          as: string;
          expression: string;
      }[] = []
    • rows: string[] = []
    • columns: string[] = []
    • reduce: {
          as: string;
          operation: string;
          property?: string;
      }[] = []
    • sort: {
          field: string;
          order: "ASC" | "DESC";
      }[] = []
    • start: number = 0
    • size: number = 100

    Returns Promise<{
        count: number;
        data: StringStringType[];
        query: string;
    }>

  • Count matching entities

    Parameters

    • query: {
          field: string;
          is:
              | "="
              | ">="
              | "<="
              | "[]";
          value: string;
      }[]

    Returns Promise<number>

  • Find matching records

    Parameters

    • query: {
          field: string;
          is:
              | "="
              | ">="
              | "<="
              | "[]";
          value: string;
      }[] = []
    • start: number = 0
    • size: number = 100

    Returns Promise<{
        count: number;
        data: StringStringType[];
        query: string;
    }>

  • Speficy a more-specific task queue than the default queue (v1, v1priority, v2, acmecorp, etc)

    Returns string

  • Instance initializer

    Parameters

    • search: boolean = true

    Returns Promise<void>