TypeScript SDK

TypeScript SDK contains Jmix data model (entities and enums), rest services and queries as TypeScript classes.

The SDK is framework-agnostic, meaning that in addition to using it with e.g. our React client, you can use it with any TypeScript-compatible framework such as Angular of Vue.

SDK can be used for front-end clients and Node.js-based BFF (Backend for Frontend) development.

Entities

Consider this example entity.

export class User {
  static NAME = "scr_User";
  id?: string;
  version?: number | null;
  username?: string | null;
  password?: string | null;
  firstName?: string | null;
  lastName?: string | null;
  email?: string | null;
  enabled?: boolean | null;
  phone?: string | null;
}
  • You can easily access the entity name using static NAME property: User.NAME,

  • The User class contains all properties of the domain model entity. Reference fields has corresponding types as well so that you can work with them in a type-safe manner.

user.enabled = true;   // ok
user.enabled = 'foo';  // compilation fails

Enums

Jmix REST API uses enum’s constant name in client-server communication. SDK contains generated string enums e.g.:

export enum CarType {
    SEDAN = "SEDAN",
    HATCHBACK = "HATCHBACK"
}

In order to get enum id and localized caption, you can query full information about enums in runtime using loadEnums method of Jmix REST:

import {EnumInfo, initializeApp} from "@haulmont/jmix-rest";

const jmixREST = initializeApp();
jmixREST.loadEnums()
    .then(((enums: EnumInfo[]) => {
        console.log('enums', enums)
    }));

Response example:

[{
    "name": "com.company.mpg.entity.CarType",
    "values": [
      {
        "name": "SEDAN",
        "id": "SEDAN",
        "caption": "Sedan"
      },
      {
        "name": "HATCHBACK",
        "id": "HATCHBACK",
        "caption": "Hatchback"
      }
    ]
  }]