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

marchio-core-record

v0.1.3

Published

REST response record tool

Downloads

14

Readme

marchio-core-record

REST response record tool

Installation

$ npm init
$ npm install marchio-core-record --save

Modules

marchio-core-record

Module

marchio-core-record.package()

Returns the package name

Kind: instance method of marchio-core-record

marchio-core-record.build(body) ⇒ Promise

Build a record based on the model and an input record containing original values

Kind: instance method of marchio-core-record
Returns: Promise - that resolves to a record object containing the resulting record

| Param | Type | Description | | --- | --- | --- | | body | Object | An object where properties represent fields from a response (like req.response) |

Example (Usage Example)

var factory = require("marchio-core-record");

var modelName = 'coretest';

var model = {
    name: modelName,
    fields: {
        email:    { type: String, required: true },
        status:   { type: String, required: true, default: "NEW" },
        // In a real world example, password would be hashed by middleware before being saved
        password: { type: String, select: false },  // select: false, exclude from query results
     }
 };
 
 // normally this would come from an http method handler
 var req = {
     body: {
         email: "[email protected]"
     }
 };

factory.create({ model: model })
.then( (rm) => rm.build( req.body )
.then( (record) => {
    console.log("record: ", record );
})
.catch( function(err) { 
    console.error(err); 
});

marchio-core-record.buildUpdate(body) ⇒ Promise

Build an update record based on the model and an input record containing original values

Kind: instance method of marchio-core-record
Returns: Promise - that resolves to a record object containing the resulting record

| Param | Type | Description | | --- | --- | --- | | body | Object | An object where properties represent fields from a response (like req.response) |

Example (Usage Example)

var factory = require("marchio-core-record");

var modelName = 'coretest';

var model = {
    name: modelName,
    fields: {
        email:    { type: String, required: true },
        status:   { type: String, required: true, default: "NEW" },
        // In a real world example, password would be hashed by middleware before being saved
        password: { type: String, select: false },  // select: false, exclude from query results
     }
 };
 
 // normally this would come from an http method handler
 var req = {
     body: {
         email: "[email protected]"
     }
 };

factory.create({ model: model })
.then( (rm) => rm.buildUpdate( req.body )
.then( (record) => {
    console.log("record: ", record );
})
.catch( function(err) { 
    console.error(err); 
});

marchio-core-record.select(body) ⇒ Promise

Build a record based on the selected fields in a model and a record containing original values

Kind: instance method of marchio-core-record
Returns: Promise - that resolves to a record object containing the resulting record

| Param | Type | Description | | --- | --- | --- | | body | Object | An object where properties represent fields from a response (like req.response) |

Example (Usage Example)

var factory = require("marchio-core-record");

var modelName = 'coretest';

var model = {
    name: modelName,
    fields: {
        email:    { type: String, required: true },
        status:   { type: String, required: true, default: "NEW" },
        // In a real world example, password would be hashed by middleware before being saved
        password: { type: String, select: false },  // select: false, exclude from query results
     }
};
 
 // normally this would come from an http method handler
var req = {
     body: {
         email: "[email protected]"
     }
};

var recMgr = null; 

factory.create({ model: model })
.then( (rm) => {
                    recMgr = rm;
    return rm.build( { req.body );
})
.then( (record) => recMgr.select( record ) )
.then( (response) => {
     console.log( response );
 })
.catch( function(err) { 
    console.error(err); 
});

marchio-core-record.selectedFields() ⇒ Promise

Return a list containing the names of fields that are selected

Kind: instance method of marchio-core-record
Returns: Promise - that resolves to a list of selected field names
Example (Usage Example)

var factory = require("marchio-core-record");

var modelName = 'coretest';

var model = {
    name: modelName,
    fields: {
        email:    { type: String, required: true },
        status:   { type: String, required: true, default: "NEW" },
        // In a real world example, password would be hashed by middleware before being saved
        password: { type: String, select: false },  // select: false, exclude from query results
     }
};
 
 // normally this would come from an http method handler
var req = {
     body: {
         email: "[email protected]"
     }
};

var recMgr = null; 

factory.create({ model: model })
.then( (recMgr) => {
    recMgr = rm;
    return recMgr.selectedFields();
})
.then( (response) => {
     console.log( response );
 })
.catch( function(err) { 
    console.error(err); 
});

marchio-core-record.fields(fields, body) ⇒ Promise

Build a record including all fields a list and a record containing original values

Kind: instance method of marchio-core-record
Returns: Promise - that resolves to a record object containing the resulting record

| Param | Type | Description | | --- | --- | --- | | fields | Object | An object where property values are objects defininig fields | | body | Object | An object where properties represent fields from a response (like req.response) |

Example (Usage Example)

var factory = require("marchio-core-record");

var modelName = 'coretest';

var model = {
    name: modelName,
    fields: {
        email:    { type: String, required: true },
        status:   { type: String, required: true, default: "NEW" },
        // In a real world example, password would be hashed by middleware before being saved
        password: { type: String, select: false },  // select: false, exclude from query results
     }
};
 
// normally this would come from an http method handler
var req = {
     body: {
         email: "[email protected]"
     }
};

const fList = ["email", "status", "password"];

var recMgr = null; 

factory.create({ model: model })
.then( (rm) => {
                    recMgr = rm;
    return rm.build( { req.body );
})
.then( (record) => recMgr.fields( fList, record ) )
.then( (response) => {
     console.log( response );
 })
.catch( function(err) { 
    console.error(err); 
});

marchio-core-record-factory

Factory module

marchio-core-record-factory.create(spec) ⇒ Promise

Factory method It takes one spec parameter that must be an object with named parameters

Kind: static method of marchio-core-record-factory
Returns: Promise - that resolves to {module:marchio-core-record}

| Param | Type | Description | | --- | --- | --- | | spec | Object | Named parameters object | | spec.model | Object | Model object that must contain a fields property |

Example (Usage example)

var factory = require("marchio-core-record");

var modelName = 'coretest';

var model = {
    name: modelName,
    fields: {
        email:    { type: String, required: true },
        status:   { type: String, required: true, default: "NEW" },
        // In a real world example, password would be hashed by middleware before being saved
        password: { type: String, select: false },  // select: false, exclude from query results
     }
 };

 factory.create({ model: model })
 .then(function(obj) {
     return obj.health();
 })
 .catch( function(err) { 
     console.error(err); 
 });

Testing

To test, go to the root folder and type (sans $):

$ npm test

Repo(s)


Contributing

In lieu of a formal style guide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.


Version History

Version 0.1.3

  • added buildUpdate method

Version 0.1.2

  • added selectedFields method

Version 0.1.1

  • updated documentation

Version 0.1.0

  • initial release