1.0.8 • Published 2 years ago

@dataprograms/repdao-polybase v1.0.8

Weekly downloads
-
License
(MIT OR Apache-2....
Repository
github
Last release
2 years ago

repdao-polybase

This is a type definition package for Filecoin Reputation WG data stored in Polybase.

Usage

Start with installing the package

npm i @dataprograms/repdao-polybase

Then import the types you need

import {DB, filfox} from "@dataprograms/repdao-polybase";

const provider = 'f01889512'

const doc = (await DB.collection('filfox')
    .where('provider', '==', provider)
    .limit(1).get())
    .data[0].data as filfox

console.log(`Filfox record for ${provider}: total rewards: ${doc.totalRewards}`)

Or using javascript without type check

import {DB} from "@dataprograms/repdao-polybase";

const provider = 'f01889512'

const doc = (await DB.collection('filfox')
    .where('provider', '==', provider)
    .limit(1).get())
    .data[0].data

console.log(`Filfox record for ${provider}: total rewards: ${doc.totalRewards}`)

Or explore all available collections

import {CollectionNames} from "@dataprograms/repdao-polybase";

for (const collectionName of CollectionNames) {
    let response
    try {
        response = await DB.collection(collectionName).where('provider', '==', provider).limit(1).get()
    } catch (e: any) {
        if (e instanceof PolybaseError) {
            console.error(`Polybase error: ${e.code} ${e.message} when retrieving ${collectionName} record for ${provider}`)
            continue
        }

        throw e
    }
    if (response.data.length === 0) {
        console.log(`No ${collectionName} record for ${provider}`)
        continue
    }
    const doc = response.data[0].data
    console.log(`${collectionName} record for ${provider}:`)
    console.log(doc)
}

You will need to set the following env variables in an .env file in the root folder

PRIVATE_KEY=<PRIVATE_KEY>
PUBLIC_KEY=<PUBLIC_KEY>
MONGO_URI=<MONGO_URI>

:warning: This is helpful to create schemas files but there are cases where the latest row may have null values and that will cause this script to fail. Going forward manual schema updates should be preferred and this script should be considered deprecated.

ts-node --esm src/gen.ts

To create schemas files and run the code gen run

ts-node --esm src/create_schema.ts

To pull data from mongo and push to polybase run

ts-node --esm src/run.ts

(uncomment baseURL if you want to push the changes to mainnet)

1.0.8

2 years ago

1.0.7

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.0.1

2 years ago