Live Objects for Station.
To test live objects locally, first make sure the following requirements are met/installed.
- Node.js >= 16
- Deno >= 1.3 (+recommend the Deno/Denoland VSCode extension)
- Postgres >= 14
- Spec CLI
Helpful Links
- Install the Spec CLI:
$ npm install -g @spec.dev/cli
- Login to your account:
$ spec login
- Make sure one of your Spec projects has been set as the current one (Spec just needs to use one of your project's api keys when subscribing to input events during testing).
$ spec use project station/internal
- Make sure your local postgres instance is running on localhost:5432
These guides are currently written with the Allo protocol as reference examples, but should still be very helpful:
https://github.com/spec-dev/allo/tree/master/guides
-
Since the "block-related properties" of your live object get automatically set for you before your event handlers run, you should be able to reference them in your handlers when needed as
this.blockNumber
,this.blockHash
,this.blockTimestamp
, andthis.chainId
, respectively. -
If you ever need to return early from a handler in a "do nothing" case, make sure to
return false
-- this tells our live object runner not to try and "auto-save" the live object class after the handler function finishes.
- Make sure your CLI and local Spec client are up to date:
$ npm i -g @spec.dev/cli @spec.dev/spec
- Make sure Postgres is running
$ psql
- Link your local folder (this repo) to your Spec project:
$ spec link project station/internal .
- Make sure your
.spec/connect.toml
is pointed to the local DB you want to run the Spec client against. If you don't have this file yet (since it's gitignored, you can use this as a template):
# Local database.
[local]
name = 'station' # whatever your local db name is
port = 5432
host = 'localhost'
user = '<your-db-username>' # whatever shows up as your user when you type "psql"
password = '' # can just leave blank
-
Make sure you have both
Membership
andPointsBalance
tables inside your local DB. I assume this is a migration from Prisma. -
Make sure your
<column> = <property>
data mappings are exactly how you want them inside of theLive Columns
section of.spec/project.toml
: -
Jump into your handlers folder and
npm install
:
$ cd .spec/handlers
$ npm install
$ cd ../../
- Back in your root folder, start the Spec client :)
$ spec start
This should kick off the Spec client against your local DB and also locally set up your event handlers (so that you can test these too.