Socket
Socket
Sign inDemoInstall

arql-ops

Package Overview
Dependencies
0
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    arql-ops

Tiny library for functional composition of ArQL operators


Version published
Weekly downloads
58
decreased by-34.09%
Maintainers
1
Install size
11.1 kB
Created
Weekly downloads
 

Readme

Source

ArQL ops

Very tiny (53 lines including whitespace) library to build ArQL for queries for Arweave https://www.github.com/ArweaveTeam/arweave-js

Packaged up with https://github.com/pikapkg/pack, for web, node, typescript and even deno!

For fun, it's published on the on the arweave blockchain itself :)

npm install https://kybjhezuyftg.arweave.net/ITTPLYoxidZzAJP50FQ03QJUSkkh9iKHcmMcLZOvqtQ

  • PROS: exact dependency pinning, immutable blockchain so package can't be removed or replaced with something malicious. (although npm lockfiles and exact versions will take of this too)
  • CONS: not exactly easy to remember install line :D manual upgrades

This works because npm can install a .tgz file from any url, so it was just a matter of running pika build, tar'ing the pkg/ folder it produces, and uploading to arweave.

Usage examples

import { and, or, equals } from 'arql-ops';

const myQuery = and(
  equals('from', 'awalletaddressXyz'),
  equals('App-Name', 'super-app'),
  or(
    equals('someTag', '4'),
    equals('someTag', '5'),
    equals('someTag', '6')
  )
);

const results = await arweave.arql(myQuery);

With spread operators:


const myQuery = and(
  equals('App-Name', 'my-app'), 
  equals('myFooTag', 'bar'),
  or(
    ...listOfPossibleSomeTagValues.map(val => equals('someTag', val))
  )
);

const results = await arweave.arql(myQuery);

and() and or() will take any number of arguments and produce the correct Json of nested expressions:


const query = and(
  equals('my-super-tag', '1'),
  or(                                     
    equals('my-color-tag', 'red'), 
    equals('my-color-tag', 'blue'),
    equals('my-color-tag', 'purple'),
    equals('my-color-tag', 'orange'),
    equals('my-color-tag', 'white'),
    equals('my-color-tag', 'black'),
  )
);

This will produce a query that matches TXs with the tag 'my-super-tag'=1 , AND any of the color values that match 'my-color-tag'

Output Json:

{
  "op": "and",
  "expr1": {
    "op": "equals",
    "expr1": "my-super-tag",
    "expr2": "1"
  },
  "expr2": {
    "op": "or",
    "expr1": {
      "op": "equals",
      "expr1": "my-color-tag",
      "expr2": "red"
    },
    "expr2": {
      "op": "or",
      "expr1": {
        "op": "equals",
        "expr1": "my-color-tag",
        "expr2": "blue"
      },
      "expr2": {
        "op": "or",
        "expr1": {
          "op": "equals",
          "expr1": "my-color-tag",
          "expr2": "purple"
        },
        "expr2": {
          "op": "or",
          "expr1": {
            "op": "equals",
            "expr1": "my-color-tag",
            "expr2": "orange"
          },
          "expr2": {
            "op": "or",
            "expr1": {
              "op": "equals",
              "expr1": "my-color-tag",
              "expr2": "white"
            },
            "expr2": {
              "op": "equals",
              "expr1": "my-color-tag",
              "expr2": "black"
            }
          }
        }
      }
    }
  }
}

FAQs

Last updated on 12 Oct 2019

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc