@cardano-sdk/projection-typeorm 0.8.27 → 0.8.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,12 +1,48 @@
1
1
  # Cardano JS SDK | projection-typeorm
2
2
 
3
- Project Chain Sync events into PostgreSQL via TypeORM.
3
+ This package is a library of utilities for projecting `ProjectionEvent`s into PostgreSQL database via [TypeORM](https://github.com/typeorm/typeorm).
4
4
 
5
- ## Adding new projections
5
+ If you're interested in generic projection types and utilities, see [projection](../projection) package.
6
6
 
7
- 1. Create a new mapper that maps the block into something that you want to project (see [withStakeKeys](../projection/src/operators/Mappers/certificates/withStakeKeys.ts) as an example).
8
- 2. Create a new granular TypeORM store (see [storeStakeKeys](./src/operators/storeStakeKeys.ts)) as an example.
7
+ If you're interested in projector application as run by Lace, see [setup](../cardano-services/src/Projection) and [README](../cardano-services/README.md) in `cardano-services` package.
8
+
9
+ ## TypeormStabilityWindowBuffer
10
+
11
+ Writes the block data into [block_data](./src/entity/BlockData.entity.ts) table and implements [StabilityWindowBuffer](../projection/README.md#stabilitywindowbuffer) interface that is required by [Bootstrap.fromCardanoNode](../projection/README.md#bootstrapfromcardanonode)
12
+
13
+ ### TypeormStabilityWindowBuffer.storeBlockData
14
+
15
+ 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.
16
+
17
+ ## createTypeormTipTracker
18
+
19
+ Queries and emits local tip (latest block header) from [block](./src/entity/Block.entity.ts) table. Returns:
20
+ - an operator that should be applied after processing the block
21
+ - an `Observable<TipOrOrgin>` that is required by [Bootstrap.fromCardanoNode](../projection/README.md#bootstrapfromcardanonode)
22
+
23
+ ## withTypeormTransaction
24
+
25
+ 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](#store-operators)).
9
26
 
10
- ### Demo
27
+ ## typeormTransactionCommit
11
28
 
12
- See [demo/projection-typeorm.js](../../demo/)
29
+ Commits PostgreSQL transaction started by [withTypeormTransaction](#withtypeormtransaction) and removes TypeORM context from the event object.
30
+
31
+ ## createObservableConnection
32
+
33
+ Utility to initialize TypeORM data source.
34
+ Returns an Observable that can be used as a dependency for
35
+ [withTypeormTransaction](#withtypeormtransaction), [TypeormStabilityWindowBuffer](#typeormstabilitywindowbuffer) and [createTypeormTipTracker](#createtypeormtiptracker).
36
+
37
+ ## Store Operators
38
+
39
+ [Each store operator](./src/operators) 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](../projection/README.md#mappers).
40
+
41
+ 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](./src/operators/storeAssets.ts) which adds new total supplies for each minted asset).
42
+
43
+ ---
44
+
45
+ ### Adding New Store Operators
46
+
47
+ 1. (optional) Create a new mapper that maps the block into something that you want to project (see [withStakeKeys](../projection/src/operators/Mappers/certificates/withStakeKeys.ts) as an example).
48
+ 2. Create a new granular TypeORM store (see [storeStakeKeys](./src/operators/storeStakeKeys.ts)) as an example.