npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@cosmic-plus/loopcall

v1.6.0

Published

Implements limitless advanced queries to Stellar Horizon nodes

Downloads

203

Readme

loopcall / ReadmeContributingChangelog

Readme

Licence Build Coverage Dependencies Vulnerabilities Downloads Bundle

Implements limitless advanced queries to Stellar Horizon nodes.

Introduction

Loopcall is a tiny library that enables unlimited complex queries to Horizon nodes. It takes a CallBuilder and accepts a few optional parameters. It returns an array of records similar to the ones returned by CallBuilder.call().

Installation

NPM/Yarn

  • NPM: npm install @cosmic-plus/loopcall
  • Yarn: yarn add @cosmic-plus/loopcall

In your script: const loopcall = require("@cosmic-plus/loopcall")

Bower

bower install cosmic-plus-loopcall

In your HTML page:

<script src="./bower_components/cosmic-plus-loopcall/loopcall.js"></script>

HTML

In your HTML page:

<script src="https://cdn.cosmic.plus/[email protected]"></script>

Note: For production release it is advised to serve your copy of the library.

Usage

Methods

loopcall(callBuilder, [options]) ⇒ Array

Fetch more than 200 records

To get an arbitrary amount of record:

const callBuilder = server.operations().order("asc")
const the2000FirstOperations = await loopcall(callBuilder, { limit: 2000 })

To get all existing records (take care with that one!):

const callBuilder = server.transactions().forAccount("GDE...YBX")
const allTransactions = await loopcall(callBuilder)

Conditional Break

To stop fetching records when a condition is met:

const callBuilder = server.transactions().forAccount("GDE...YBX")
const thisYearTransactions = await loopcall(callBuilder, {
  breaker: (record) => record.created_at.substr(0, 4) < 2018
})

breaker is a Function that is called over each fetched record. Once it returns true, the fetching loop breaks and the record that triggered the break is discarded.

Conditional Filtering

To filter records by condition:

const callBuilder = server.transactions().forAccount("GDE...YBX")
const transactionsWithoutMemo = await loopcall(callBuilder, {
  filter: (record) => !record.memo
})

filter is a Function that is called over each fetched record. When provided, the records are added to the query results only when it returns true.

Iterating over records on-the-fly

In some situations waiting for the result to be concatenated is not an option. filter offers the possibility of iterating over records while they are fetched:

const callBuilder = server.transactions()

async function showTxUntilScreenIsFilled(record) {
  displayTxUsingRecord(record)
  await endOfPageReached()
}

loopcall(callBuilder, { filter: showTxUntilScreenIsFilled })

This example shows a part of the code to implement unlimited scrolling on a webpage showing the last transactions on a Stellar network.

Combining parameters

All those parameters may be combined together:

const callBuilder = server.operations().order("asc")

function iterateOver1000RecordsMax() {
  let counter = 0
  return function () {
    counter++
    if (counter > 1000) return true
  }
}

const the20firstAccountCreations = await loopcall(callBuilder, {
  limit: 20,
  breaker: iterateOver1000RecordsMax(),
  filter: (record) => record.type === "create_account"
})

When both are provided, breaker is called before filter.

| Param | Type | Description | | ----------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | callBuilder | CallBuilder | A CallBuilder object | | [options] | Object | | | [options.limit] | Integer | The maximum number of record to return | | [options.filter] | function | A function that accepts a record argument. It is called with each fetched record. If it returns a true value, the record is added to returned records, else it is discarded. | | [options.breaker] | function | A function that accepts a record argument. It is called with each fetched record. If it returns a true value, the loop ends and the array of the filtered records is returned. |

Links

Organization: Cosmic.plus | @GitHub | @NPM

Follow: Reddit | Twitter | Medium | Codepen

Talk: Telegram | Keybase