GithubHelp home page GithubHelp logo

techcoderx / typescript-haf-app-template Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 105 KB

TypeScript HAF app template

License: MIT License

Dockerfile 1.72% Shell 4.09% TypeScript 82.51% PLpgSQL 11.68%

typescript-haf-app-template's Introduction

TypeScript HAF App Template

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.

How To Use This Template

HAF App Names

Replace every instance of myhaf_app with your actual HAF app name in:

Replace every instance of myhaf_api with your actual HAF app API schema name in:

Replace every instance of myhaf_owner with your actual HAF app owner role in:

Replace every instance of myhaf_user with your actual HAF app API user in:

Replace the environment variable prefix HAFAPP in:

Table Definitions

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.

Function Definitions

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.

API Definitions

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.

Config Definitions

Define additional configuration required in config.js file. All constants are to be defined in constants.ts.

Operation Validation and Execution

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.

State Providers

Import the required state providers in src/schema.ts. The accounts state provider has been included as an example.

Docker

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.

Everything Else

  • 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.

Required Dependencies

  • nodejs and npm (Latest LTS, v18 minimum supported)
  • Synced HAF node

Setup

PostgreSQL Roles

psql -f src/sql/builtin_roles.sql haf_block_log

PostgREST Installation

./scripts/postgrest_install.sh

PostgREST API methods

psql -f src/sql/create_apis.sql block_log

Installation

git clone https://github.com/techcoderx/typescript-haf-app-template
cd typescript-haf-app-template
npm i

Compile

npm run compile

Sync

npm start

Start PostgREST server

./scripts/postgrest_start.sh postgres://myhaf_user:<myhaf_user_password>@localhost:5432/block_log <server_port>

Start Express server

npm run server

typescript-haf-app-template's People

Contributors

techcoderx avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.