Sample HAF indexer and API server. Indexes Hive from a starting block number for relevant insert_operation_here
operations using the HAF app sync algorithm.
Replace every instance of myhaf_app
with your actual HAF app name in:
- All SQL files in src/sql folder
- src/constants.ts
- .env.example
- This README file
Replace every instance of myhaf_api
with your actual HAF app API schema name in:
- src/sql/create_apis.sql
- src/sql/drop_db.sql
- src/server.ts
- PostgREST start scripts in scripts folder (including docker)
- This README file
Replace every instance of myhaf_owner
with your actual HAF app owner role in:
- src/sql/create_apis.sql
- src/sql/builtin_roles.sql
- This README file
Replace every instance of myhaf_user
with your actual HAF app API user in:
- src/sql/create_apis.sql
- PostgREST start scripts in scripts folder (including docker)
- This README file
Replace the environment variable prefix HAFAPP
in:
Write the PostgreSQL table definitions in src/sql/create_tables.sql file. All registered tables (forking app) must contain the column hive_rowid
as shown in the example table. List the registered table names (without schema name) in src/schema.ts, under HAF_TABLES
array.
Then define foreign key definitions in the same file under HAF_FKS
object, and list those definitions that has to be dropped when uninstalling the HAF app in src/sql/drop_db.sql.
An example PL/pgSQL function for fetching custom_json
operations has been defined in src/sql/create_functions.sql. Adapt the function to your desired set of operation IDs by referring to the operations list linked in the file.
Define all operation processing methods in the same file.
Define PostgREST API definitions in src/sql/create_apis.sql file under the HAF app API schema. For APIs that must be written in TypeScript, define the Express API methods in src/server.ts.
Define Express API request types in src/server_types.ts.
Define additional configuration required in config.js file. All constants are to be defined in constants.ts.
Include the required validation for operations fetched from myhaf_app.enum_op()
in src/processor.ts file in validateAndParse()
method. Execute the operations by calling the operation processing PL/pgSQL methods in process()
within the same file.
Import the required state providers in src/schema.ts. The accounts
state provider has been included as an example.
A sample Dockerfile is supplied in this template. Replace all instances of hafapp
with your app name, and substitute environment variables with your defined prefix. Additionally, adjust the names in scripts/postgrest_docker_start.sh file accordingly.
- Replace the LICENSE file with your desired license.
- Replace all values in package.json with actual names and URLs.
- Delete this section of the README file and update the HAF app description above.
nodejs
andnpm
(Latest LTS, v18 minimum supported)- Synced HAF node
psql -f src/sql/builtin_roles.sql haf_block_log
./scripts/postgrest_install.sh
psql -f src/sql/create_apis.sql block_log
git clone https://github.com/techcoderx/typescript-haf-app-template
cd typescript-haf-app-template
npm i
npm run compile
npm start
./scripts/postgrest_start.sh postgres://myhaf_user:<myhaf_user_password>@localhost:5432/block_log <server_port>
npm run server