0.0.66 • Published 4 years ago

@borsawy/types v0.0.66

Weekly downloads
184
License
ISC
Repository
github
Last release
4 years ago

Borsawy Types

Borsawy Types is a library of common classes that are used almost everywhere in all other Borsawy components. Here we include things such as access to the Database or the Elasticsearch domain. Since almost everyone writing code in any Borsawy component will need to access the Database some way or another, we write the Database logic here where other repositories can depend on it and use it.

Usage

To use this package, simply npm install @borsawy/types in your node project, then import { WhateverYouWant } from '@borsawy/types'; in your javascript/typescript.

Example Use Cases

  • To create a Market object, see the specification is constructable from objects or is constructable from json in src/market.spec.ts
  • To save a Market object to DynamoDb, see the specification is persistable to dynamo in src/market.spec.ts
  • To save a Market object to ElasticSearch, see the specification is persistable to elasticsearch in src/market.spec.ts
  • To find a Market in DynamoDb, see the specification is queryable from dynamo in src/market.spec.ts
  • To search for a Market in ElasticSearch, see the specification is searchable from elasticsearch in src/market.spec.ts
  • To search in ElasticSearch for an Exchange that belongs to a market that has a certain UUID, see the specification is searchable from elasticsearch by the UUID of a market in exchange.spec.ts

Validation

Besides being a place for common classed, Borsawy Types also includes most of our validation logic. For example, we know that the price of a stock can never be less than or equal to Zero. In order to make sure that we never receive a price variable that is less than zero, we create a class called Price. In the constructor of that class, we make sure to validate that the parameter is greater than Zero. See price.ts. Any other place in the code that needs a price input should then use the Price class instead of a simple price variable. This way, the developer can be sure that the value of this price is greater than zero, because the constructor of the Price class would have thrown an exception otherwise long before it was passed to us.

For example, in tick.ts, the Tick class is defined like this... constructor(price: Price) instead of... constructor(price: number) This is because number can be anything, but Price is guaranteed to be valid.

Ontology

Some classes in the Borsawy types library represent entities in the Borsawy ontology. See https://en.wikipedia.org/wiki/Ontology_(information_science)! By understanding the Borsawy ontology, you understand how objects interact with each other and how you can use them. Some of the most important entities in the ontology are Market, Exchange, Ticker, Tick, and TickerPrediction. Each entity is defined in its own source file and includes a docblock that explain the role of the entity in the ontology. Try src/market.ts for example.

Every entity has two main properties: the UUID, and the time. UUID is unique in the entire system. You can not have two objects with the same UUID. If you know the UUID of an object, you can query it directly without needing to know anything else about it. The UUID is a key to the object.

To understand why we have time in every object, you need to understand that it is not safe to edit existing items in the system. The reason why it is not safe is beyond the scope of this introduction. Since updates are not safe, we need a way to add new objects to the system and deprecate the old ones without editing the old ones. This is how we use time. For example, if you have two Exchange objects in the system with name XCAI, one of them is at time 5 and the other is at time 10, use the exchange at time 10. This means that for some reason we needed to update the data in the XCAI exchange so we added a new Exchange with the updated data at time 10 so that everyone would know this is an update. Most of the time, you will need the latest version of the item. To do that while querying ElasticSearch for example, you sort the results by time descending-ly and take the first item.

DynamoDB

Some classes in the Borsawy types library represent objects that we need to persist to DynamoDB. For example, exchange.ts, market.ts, and ticker.ts. These are called entities. We also have a special class called DynamoTable defined in dynamo-table.ts that is responsible for communicating with DynamoDB and storing the entities. Each entity has its own fields. Thus each entity must tell DynamoTable how it wants to be stored in DynamoDB. If an entity wants to define this, it needs to implement the DynamoObject interface. Read the comments in dynamo-object.ts and the spec about dynamo in each entities spec file (e.g. market.spec.ts) for examples on how this works.

ElasticSearch

Just like DynamoDB, some entities need to be stored in ElasticSearch. A special class called ElasticDomain knows how to communicate with ELasticSearch. In order to store an entity, the entity must implement the ElasticDocument interface in order to tell ElasticDomain how to store it. See elastic-document.ts and elastic-domain.spec.ts for more details on how this works.

Deployment

To deploy the types package to npmjs.com, you need an authentication token. The authentication token is written in a GitHub Actions secret called NPM_TOKEN. This token is obtained from npmjs.com using the Borsawy account. Thus, only the production Borsawy repository can publish a new version of the types library. See .github/workflows/tags.yml for more info on how this token is used.

0.0.66

4 years ago

0.0.63

4 years ago

0.0.64

4 years ago

0.0.62

4 years ago

0.0.61

4 years ago

0.0.60

4 years ago

0.0.59

4 years ago

0.0.58

4 years ago

0.0.56

4 years ago

0.0.55

4 years ago

0.0.53

4 years ago

0.0.54

4 years ago

0.0.52

4 years ago

0.0.51

4 years ago

0.0.50

4 years ago

0.0.49

4 years ago

0.0.46

4 years ago

0.0.48

4 years ago

0.0.44

4 years ago

0.0.43

4 years ago

0.0.42

4 years ago

0.0.41

4 years ago

0.0.40

4 years ago

0.0.39

4 years ago

0.0.37

4 years ago

0.0.38

4 years ago

0.0.36

4 years ago

0.0.35

4 years ago

0.0.34

4 years ago

0.0.33

4 years ago

0.0.31

4 years ago

0.0.32

4 years ago

0.0.30

4 years ago

0.0.29

4 years ago

0.0.25

4 years ago

0.0.26

4 years ago

0.0.27

4 years ago

0.0.28

4 years ago

0.0.23

4 years ago

0.0.24

4 years ago

0.0.22

4 years ago

0.0.21

4 years ago

0.0.20

4 years ago

0.0.19

4 years ago

0.0.18

4 years ago

0.0.17

4 years ago

0.0.16

4 years ago

0.0.15

4 years ago

0.0.10

4 years ago

0.0.11

4 years ago

0.0.13

4 years ago

0.0.14

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.4

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago