Skip to content

Latest commit

 

History

History

projection-typeorm

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Cardano JS SDK | projection-typeorm

This package is a library of utilities for projecting ProjectionEvents into PostgreSQL database via TypeORM.

If you're interested in generic projection types and utilities, see projection package.

If you're interested in projector application as run by Lace, see setup and README in cardano-services package.

TypeormStabilityWindowBuffer

Writes the block data into block_data table and implements StabilityWindowBuffer interface that is required by Bootstrap.fromCardanoNode

TypeormStabilityWindowBuffer.storeBlockData

This method is intended to be called as part of PostgreSQL transaction that writes all other data from the event. It is important to keep StabilityWindowBuffer consistent with projection state.

createTypeormTipTracker

Queries and emits local tip (latest block header) from block table. Returns:

  • an operator that should be applied after processing the block
  • an Observable<TipOrOrgin> that is required by Bootstrap.fromCardanoNode

withTypeormTransaction

Adds TypeORM context (query runner) to each event and starts a PostgreSQL transaction. Subsequent operators can utilize this context to perform database operations (see Store Operators).

typeormTransactionCommit

Commits PostgreSQL transaction started by withTypeormTransaction and removes TypeORM context from the event object.

createObservableConnection

Utility to initialize TypeORM data source. Returns an Observable that can be used as a dependency for withTypeormTransaction, TypeormStabilityWindowBuffer and createTypeormTipTracker.

Store Operators

Each store operator takes in an Observable<WithTypeormContext & T>, where T depends on what the specific operator needs. Usually it depends on one or more of the Mappers.

Most store operators will just write some data into the database and emit the same event object (unchanged). However, they can also add additional context to the events (see storeAssets which adds new total supplies for each minted asset).


Adding New Store Operators

  1. (optional) Create a new mapper that maps the block into something that you want to project (see withStakeKeys as an example).
  2. Create a new granular TypeORM store (see storeStakeKeys) as an example.