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

sweetp-base

v1.0.0

Published

Base module to write services for Sweetp server to automate your development workflow.

Downloads

11

Readme

Base package for Sweetp services developed with node.js

NPM version

Sweetp main site.

Features:

  • simple DSL to define service methods easily
  • asynchronous callback API like node.js packages
  • wire protocol abstracted for you, again, so you can write new services easily
  • call other services

Examples

Service creation

var service, methods, client, sweetp, log;

log = require('sweetp-base/lib/log')('YOUR SERVICE NAME:internal:');
sweetp = require('sweetp-base');

// service methods with sweetp meta data
service = {

    // add methods as properties of the service object, the key is used as target
    yourMethod:{
        // target:"/yourService/your/own/target/string/", /* optional! */
        options: {
            // description which params you need from sweetp
            params: {
                // use URL to call other services
                url: sweetp.PARAMETER_TYPES.url,
                // define own parameters
                myOwnParam: sweetp.PARAMETER_TYPES.one,
                // or fetch config
                config: sweetp.PARAMETER_TYPES.projectConfig
            },
            // add simple descriptions so everyone knows what this method does
            description: {
                summary:"Get user and password for 'key'.",
                example:"more fancy text here, you can use HTML here",
                returns:"a string with text"
            }
        },
        // assign a function to the "fn" property, this gets executed when the service method gets called
        fn:function(params, callback) {
            // create unicorns here or any other fancy stuff which makes you more productive

            log.debug("Search for unicorns.");
            log.info("I create beautiful unicorns.");
            log.warn("uh oh, no unicorns??");
            log.error("No unicorns!!!! :(");

            return callback(null, "This is your response and can be a String or JSON.");
        }
    },

};

// create service methods and start sweetp service (client)
methods = sweetp.createMethods(service, '/yourService/');
client = sweetp.start("YOUR SERVICE NAME", methods);

Put this in a file like /somedir/foo.js. Add this to your Sweetp services.json file:

{
    "id":"example-node-service",
    "exec":[
        "node",
        "foo.js"
    ],
    "dir":"/somedir/"
}

Now (re-)start Sweetp server and you should be able to call your example service with http://localhost:7777/services/yourService/yourMethod :-)

Call other service

Calling an other service is easy. Fetch the url of the Sweetp server your service is running with parameter type sweetp.PARAMETER_TYPES.url. Add parameters for the service call as simple map and put in the other parameters:

var callback = function (err, result) {
    console.log('result from service call', result);
};
var params = {
    title:'This is my title',
    message:'This is my message'
};
sweetp.callService(url, "noproject", "ui/dialog/password", params, false, callback);

This would call the service "ui/dialog/password" of project "noproject", which runs in the same Sweetp server instance as your service. As result you going to get the answer of the called service.

Parameter types

See JVM version for more details.

sweetp.PARAMETER_TYPES.url = "url";
sweetp.PARAMETER_TYPES.one = "one";
sweetp.PARAMETER_TYPES.projectConfig = "projectConfig";
sweetp.PARAMETER_TYPES.list = "list";
sweetp.PARAMETER_TYPES.request = "request";