Facts

The core unit of data in Jinaga is a fact. A fact is an immutable record of an event, decision, or state change. Let's start simple. When the user logs into your application, that's a fact.

const { userFact: user, profile } = await testClient.login<User>();
%0 Gs+Fo0xO04hUAteaPwrHZDmyovTwr7asnKsBrkRf3HE3M9nYIj4Sk7ZhR8YK5uMq1SMHPrQohtQNwo9B7whK0w== Jinaga.User publicKey --- TEST USER ---

Each fact has a type (Jinaga.User in this case) and a set of properties (publicKey for this example).

The Jinaga.User type is defined in the Jinaga library. But, of course, you can define your own types. Write a class with a static Type as the type name. Declare a type instance variable initialized to that value. Then declare a constructor taking all of the properties of the fact.

class Project {
  static Type = "Construction.Project" as const;
  type = Project.Type;

  constructor(public creator: User, public id: string) {}
}

To create an instance of this fact, call fact on the Jinaga client. This method is asynchronous because it will save the fact to the local store and notify the replicator to synchronize it with other clients.

const projectA = await testClient.fact(new Project(user, crypto.randomUUID()));
%0 Gs+Fo0xO04hUAteaPwrHZDmyovTwr7asnKsBrkRf3HE3M9nYIj4Sk7ZhR8YK5uMq1SMHPrQohtQNwo9B7whK0w== Jinaga.User publicKey --- TEST USER --- PYaXGGp+ksHg101LgyF/pB/OBQsixEhWZ9RDW9wxdwX/sVFWgyhpOZROgi4Gttdz1lWJ5Un0pJPJ5MvXEk1TCQ== Construction.Project id 52eb9df8-7b1c-43d4-9... PYaXGGp+ksHg101LgyF/pB/OBQsixEhWZ9RDW9wxdwX/sVFWgyhpOZROgi4Gttdz1lWJ5Un0pJPJ5MvXEk1TCQ==->Gs+Fo0xO04hUAteaPwrHZDmyovTwr7asnKsBrkRf3HE3M9nYIj4Sk7ZhR8YK5uMq1SMHPrQohtQNwo9B7whK0w== creator

Build a Model

Before you can use these fact types in an application, you have to build a model. Start by adding all of your types to a model builder.

const constructionModel = (b: ModelBuilder) => b
  .type(Project, m => m
    .predecessor("creator", User)
  )
  ;

Then you can compose a set of declarations into one model.

const model = buildModel(b => b
  .with(constructionModel)
);

Continue With

Predecessors

Jinaga is a product of Jinaga LLC.

Michael L Perry, President