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

machine

Package Overview
Dependencies
Maintainers
2
Versions
132
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

machine - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

DIRECT_USAGE.md

2

package.json
{
"name": "machine",
"version": "1.0.3",
"version": "1.0.4",
"description": "Configure and execute a machine using inputs and exits",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,38 +0,13 @@

# node-machine
# machine
First, here's a quick example:
This module is a runtime for _machines_; i.e. any function which conforms to the open standard outlined [here](http://node-machine.org/spec/machine).
```bash
$ node
> require('machinepack-github').getRepo
-----------------------------------------
[Machine: get-repo]
Fetch metadata about a github repo.
Most machine consumers won't interact with this module directly-- rather, you'll want to require a machinepack from NPM like so:
Inputs:
• repo (type: string)
• user (type: string)
-----------------------------------------
> require('machinepack-github').getRepo({repo: 'sails', user: 'balderdashy'}).exec(console.log)
{ ... }
```
## Using a machine
##### With traditional options+callback function usage:
```javascript
Github.getRepo({
user: 'balderdashy',
repo: 'sails'
}, function (err, repo) { /* ... */ });
var Github = require('machinepack-github');
```
Then use one of its machines:
##### With chainable helper function(s) and a switchback:
```javascript

@@ -46,167 +21,25 @@ Github.getRepo({

error: function (err){ /*...*/ },
invalidApiKey: function (err){ /*...*/ },
// etc.
invalidApiKey: function (err){ /*...*/ }
});
```
For more information on using machines, an up-to-date list of all available machinepacks, and standardized documentation for each one, visit http://node-machine.org.
##### With an environment:
```javascript
Github.getRepo({
user: 'balderdashy',
repo: 'sails'
})
.setEnvironment({
config: sails.config.githubCredentials
})
.exec(function (err, repo) {
// ...
});
### For implementors
If you're implementing a machinepack, you'll need to use this module to `.pack()` your machines. See http://node-machine.org/spec/machinepack for more information.
### Advanced Use
##### Low-level usage:
If you're implementing a one-off machine (i.e. just to take advantage of the caching or type-checking this module provides), you may need lower-level access to the methods herein.
> (machinepack-independent)
See [DIRECT_USAGE.md](./DIRECT_USAGE.md) for information on how to use all the lower-level features of this module.
```javascript
var Machine = require('node-machine');
Machine.build(require('machinepack-github/get-repo'))
.configure({
user: 'balderdashy',
repo: 'sails'
}).exec(function (err, results){
if (err) {
// ...
}
### License
// ...
})
```
MIT
© 2014 Mike McNeil
## Building your own machine
Machines are mostly just simple functions that always have the same usage paradigm:
```javascript
function (inputs, cb) {
return cb();
}
```
If you define a function that way (let's say you export it from a local module called "foo.js"), you can actually use it as a machine like this:
```javascript
require('node-machine').build(require('./foo'))
.configure({
// input values go here
})
.exec(function (err) {
console.log('all done.');
});
```
## Advanced Usage
Since machine definitions are completely static, we must consider all of the various methods by which we might deserialize them and inject the runtime scope.
#### The `Machine` constructor
When you require `node-machine`, you get the stateless `Machine` constructor:
```javascript
var Machine = require('node-machine');
console.log(Machine);
/*
-----------------------------------------
node-machine
v0.2.2
• License : MIT
• Docs : http://node-machine.org
-----------------------------------------
*/
```
As with the top-level value exported from any node module, you really shouldn't make changes to this object since it would pollute the module elsewhere in the currently-running process (in other functions, other files, and even other modules!)
#### Building callable machines
`Machine.build()` is a static factory method which constructs callable functions.
```javascript
var Machine = require('node-machine');
var foobar = Machine.build(function foobar(inputs, cb){ return cb(); });
```
#### Executing machines
Once you have a callable machine function, you can call it directly:
```javascript
foobar({
foo: 1,
bar: 2
}, function (err, result) {
});
```
or just use the chainable convenience methods:
```javascript
foobar.configure({
foo: 1,
bar: 2
})
.exec(function (err, result) {
});
```
#### Chainable usage / deferred object
Calling `.configure()` on a machine returns a chainable intermediate object, much like a promise.
> In the future, this object might eventually be a promise.
This allows for some flexibility in how the machine is called:
```javascript
var thisFoobar = foobar.configure();
thisFoobar.configure({foo: 1});
thisFoobar.configure({bar: 2});
thisFoobar.exec(function (err, result){
});
```
#### Caching
Machines know how to cache their own results.
```javascript
var Machine = require('node-machine');
var ls = Machine.build(require('machinepack-fs/ls'));
ls
.configure({
})
.cache({ttl: 2000}) // this is the ttl, 2000ms === 2 seconds
.exec(console.log)
```
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