Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

chain-spy

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

chain-spy

Lets you spy on a chain

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
13
increased by1200%
Maintainers
1
Weekly downloads
 
Created
Source

chain-spy Build Status codecov

Lets you spy on a chain

Install

$ npm install chain-spy

Usage

import { create } from 'chain-spy'

function select(db) {
  return db
    .select('id', 'name', 'age')
    .where('name', 'Daenerys')
    .sort('age')
    .someFunction(5)
}


const dbProxy = create({ someFunction: n => n })

const result = select(dbProxy)


console.log(result)
// 5
console.log(dbProxy.__execution_log__)
// [ { type: 'get', name: 'select' },
//   { type: 'apply', args: [ 'id', 'name', 'age' ] },
//   { type: 'get', name: 'where' },
//   { type: 'apply', args: [ 'name', 'Daenerys' ] },
//   { type: 'get', name: 'sort' },
//   { type: 'apply', args: [ 'age' ] } ]
//   { type: 'get', name: 'someFunction' },
//   { type: 'apply', args: [ 5 ] } ]

// Can be used with snapshot testing, eg.
expect(dbProxy.__execution_log__).toMatchSnapshot() // jest
t.snapshot(dbProxy.__execution_log__); // ava

API

create(overwrite?)

overwrite (optional)

Type: object

Can overwrite the return value of a property. eg.

const proxy = create({ hello: 'world', cat: n => n + 1 })

proxy.hello // world
proxy.something.hello // world
proxy.something('else').hello // world
proxy.cat(1) // 2

Can also access the proxy inside a overwrite function:

const proxy = create({ hello: function(n) {
  return n === 5 ? 7 : this
}})

proxy.hello(1).hello(2).hello(5) // 7

License

MIT

Keywords

FAQs

Package last updated on 11 Sep 2023

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc