1.12.0 • Published 26 days ago

@joystream/js v1.12.0

Weekly downloads
-
License
GPL-3.0-only
Repository
github
Last release
26 days ago

@joystream/js

This package is home to the Joystream.js libraries which provide everything required to work with Joystream network.

  • @joystream/js/utils Common utilities used by different Joystreamjs packages
  • @joystream/js/content Interact with content directory module - managing videos, channels, payouts, assets, categories and curator groups

Installation

yarn install @joystream/js

Development

  1. Run yarn to install dependencies
  2. Run yarn build to build the package

Content Submodule (@joystream/js/content)

Interact with content directory module - managing payouts, channels, videos, assets, categories and curator groups

Usage

Getting payout record by channel Id

This function gets the payout record from the remote source. It first fetches the payload header and then uses the offset of given channel Id from header to fetch the record.

import { channelPayoutProof } from '@joystream/js/content'

const channelId = 1
const payoutRecord = await channelPayoutProof(channelId)

Getting channel payout record from serialized payload file at given byte

import { channelPayoutProofAtByteOffset } from '@joystream/js/content'
import { readBytesFromFile } from '@joystream/js/utils'

const readContext = 'PATH' // 'PATH' | 'URL'
const inputFilePath = './payload'
const byteOffset = 40
const payoutRecord = await channelPayoutProofAtByteOffset(
  readBytesFromFile(readContext, inputFilePath), byteOffset
)

Get header from serialized channel payouts payload file

import { serializedPayloadHeader } from '@joystream/js/content'
import { ChannelPayoutsMetadata } from '@joystream/metadata-protobuf'
import { readBytesFromFile } from '@joystream/js/utils'

const readContext = 'PATH' // 'PATH' | 'URL'
const inputFilePath = './payload'
const serializedHeader = await serializedPayloadHeader(
  readBytesFromFile(readContext, inputFilePath)
)
// decode header
const header = ChannelPayoutsMetadata.Header.decode(serializedHeader)
console.log(
  header.payloadLengthInBytes,
  header.headerLengthInBytes,
  header.numberOfChannels,
  header.channelPayoutByteOffsets
)

Generate merkle root from serialized channel payouts payload

import { generateCommitmentFromPayloadFile } from '@joystream/js/content'

const inputFilePath = './payload'
const readContext = 'PATH' // 'PATH' | 'URL'
const merkleRoot = await generateCommitmentFromPayloadFile(
  readBytesFromFile(readContext, inputFilePath)
)

Utils Submodule (@joystream/js/utils)

Common utilities used by different Joystreamjs packages.

Submodule structure:

  • src/schemas/json/ JSON schemas
  • typings/ Type definitions generated from JSON schemas using json-schema-to-typescript

Usage

Read stream of bytes from file

Read a range of bytes from input file provided start and end values. Both start and end are inclusive

import { readBytesFromFile } from '@joystream/js/utils'

const readContext = 'PATH' // 'PATH' | 'URL'
const inputFilePath = './payload'
const start = 10
const end = 20
const bytesReader = readBytesFromFile(readContext, inputFilePath)
const bytes = await bytesReader(start, end)
1.12.0

26 days ago

1.11.0

2 months ago

1.10.0

2 months ago

1.9.0

2 months ago

1.8.0

2 months ago

1.7.0

4 months ago

1.6.3

5 months ago

1.6.2

5 months ago

1.6.1

6 months ago

1.6.0

6 months ago

1.5.0

6 months ago

1.4.0

1 year ago

1.3.0

1 year ago

1.2.0

1 year ago

1.1.0

1 year ago

1.0.0

1 year ago