This repository contains the source code for middleware that will provide time-series data related to Cooler Loans.
This repository deploys two API endpoints:
-
generate
- Generates daily snapshots for Cooler Loans.
- Each snapshot is based on the previous day's snapshot (where applicable), in combination with the loan events (e.g. repayment) from that day.
- Loan events are processed in the order that they occur.
- A Google Cloud Function (with a periodic trigger) determines the previous date for which the snapshot was generated, and generates from that day onwards.
- The snapshots are stored in Google Firestore
- Generates daily snapshots for Cooler Loans.
-
get
- Fetches the daily snapshots for the given
startDate
andbeforeDate
- Fetches the daily snapshots for the given
- Install JDK 11+, which is required for the firestore emulator
- On Mac:
- Install OpenJDK:
brew install openjdk@11
- Let the system know where OpenJDK 11 is installed:
sudo ln -sfn /opt/homebrew/opt/openjdk@11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
- Switch to OpenJDK 11 by default:
/usr/libexec/java_home -v 11
- Install OpenJDK:
- On Mac:
- Install the firebase emulator
gcloud emulators firestore start
- Copy the
.env.sample
file to.env
and fill out the required variables
- Run the firestore emulator:
yarn firestore:start
yarn test
If the daily snapshots need to be rebuilt (e.g. change in the subgraph or the snapshot structure), simply delete the snapshots
collection in the GCP project's Firestore section.
This can alternatively be achieved using the firebase
CLI:
firebase firestore:delete --recursive "/snapshots" -P <GCP PROJECT>
REST API clients can utilise the openapi/openapi.yml
file to generate typings. The schema, contained in openapi/snapshot.yaml
is regenerated with the yarn codegen
command.