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

datamodel

Package Overview
Dependencies
Maintainers
1
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

datamodel

Design datamodels with asynchronous functions and flows.

  • 1.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
51
decreased by-63.57%
Maintainers
1
Weekly downloads
 
Created
Source

Datamodel

Build Status

Design datamodels with asynchronous functions and flows.

Contributors

Installation

With npm do:

$ npm install datamodel

Tests

Use mocha to run the tests.

$ npm install mocha
$ mocha test

Examples

Example 1 : Create a datamodel with 3 files and 1 directory

var fs = require('fs')
  , datamodel = require('datamodel');

datamodel()
.declare('dirname', function(input, fill) {
    fill('/etc');
})
.append('file1', function(input, fill) {
	fs.readFile(this.dirname + '/group', function (err, data) {
      fill(err ? err : data.toString().substring(0, 7).concat('...'));
	});
})
.append('file2', function(input, fill) {
	fs.readFile(this.dirname + '/hosts', function (err, data) {
      fill(err ? err : data.toString().substring(0, 7).concat('...'));
	});
})
.append('file3', function(input, fill) {
	fs.readFile(this.dirname + '/unknown', function (err, data) {
      fill(err ? err : data.toString().substring(0, 7).concat('...'));
	});
})
.apply(function(err, res) {
    console.error('Error>', err);
    console.log('Result>', res);
});

output

Error> { [Error: Some fields are errors.] fields: [ 'file3' ] }
Result> { dirname: '/etc',
  file1: 'root:x:...',
  file2: '127.0.0...',
  file3: { [Error: ENOENT, open '/etc/unknown'] errno: 34, code: 'ENOENT', path: '/etc/unknown' } }

Example 2 : Declare a datamodel as package/module

obj.js


var datamodel = require('datamodel');

datamodel()
.declare('a', function(input, fill) {
    fill(input + 'A');
})
.append('b.1', function(input, fill) {
    fill(input + 'B1');
})
.append('b.2', function(input, fill) {
    fill(input + 'B1');
})
.append('b.3', function(input, fill) {
    fill(input + 'B3');
})
.complete('c', function(input, fill) {
    fill(input + 'C');
})
.attach(module);

index.js

var util = require('util');

require('./obj.js')('#', function(o) {
    console.log(util.inspect(o, { colors:true, depth: null }));
  }
);

Output

{ a: '#A',
  'b.1': '#B1',
  'b.2': '#B1',
  'b.3': '#B3',
  c: '#C' }

Example 3 : Combine a datamodel and a route with Express

var app = require('express');

app.route('/resource/:param1/:param2').all(require('./obj.js'));

API Documentation

datamodel()

declare(String key, Function callback)

append(String key, Function callback)

complete(String key, Function callback)

transform(Function callback)

send(Function callback)

apply(Mixed input, Mixed output, Function callback)

attach(Object module)

License

MIT/X11

Keywords

FAQs

Package last updated on 18 Jun 2014

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