New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

potion-client

Package Overview
Dependencies
Maintainers
2
Versions
183
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

potion-client

A ES6 client for APIs written in Flask-Potion

  • 0.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
105
decreased by-52.7%
Maintainers
2
Weekly downloads
 
Created
Source

Potion

Build Status

A TypeScript client for APIs written in Flask-Potion.

Installation


$(node bin)/jspm install npm:potion-client

Usage


Before you use this package, make sure you include reflect-metadata and a shim for ES6/7 features (core-js has the most comprehensive collection of shims and I advise using it).

Furthermore, this package has multiple implementations available, it can be used as:

  • standalone package using Fetch API (make sure to include a polyfill such as whatwg-fetch if you are targeting a browser that does not implement the API);
  • as a AngularJS module.

Note that any routes created with Route.<method> and the following methods on Item return a Promise:

  • .save()
  • .update()
  • .destroy()
  • .query()
  • .fetch()
Standalone

TODO

AngularJS

If you decide to use this package as a AngularJS module, use the following example as a starting point:

import angular from 'angular';

import 'potion/angular';
// If the bellow import is used,
// the line above is not necessary.
// By importing anything from the module,
// it will implicitly load and register the angularjs module.
import {Item, Route} from 'potion/angular';

angular
    .module('myApp', ['potion'])
    // Config the Potion client
    .config(['potionProvider', (potionProvider) => {
    	potionProvider.config({prefix: ''});
    }])
    // Register a resource
    .factory('User', ['potion', (potion) => {
    
        // Resources can also be registered using `@potion.registerAs('/user')`
        class User extends Item {
            static names = Route.GET('/names');
            attributes = Route.GET('/attributes');
            name: string;
        }

        // If the `@potion.registerAs('/user')` decorator is used,
        // this is no longer needed.
        potion.register('/user', User);

        return User;
    }])
    .controller('MyAppController', ['User', (User) => {
        // Fetch a user by id
        const user1 = User.fetch(1);
        
        // Get all user names using the static route created with `Route.GET('/names')`
        const names = User.names();
        
        // Get the user attributes using the instance route created with `Route.GET('/attributes')`
        user1.then((user) => {
        	user.attributes().then((attrs) => {
        		console.log(attrs);
        	});
        });
        
        // Get all users
        const users = User.query();
        
        // Update a user
        user1.then((user) => {
            const name = 'John Foo Doe';
        	user.update({name});
        });
        
        // Delete a user
        user1.then((user) => {
            user.destroy({name});
        });
        
        // Create and save a new user
        const name = 'Foo Bar';
        let user2 = User.create({name});
        user2.save();
    }]);

Contributing


Clone the repository git clone https://github.com/biosustain/potion-node, install all the deps (npm install, $(npm bin)/typings install) and start hacking. Make sure that the builds and tests will run successfully, before you make a pull request. Follow the next steps:

  • use npm run build to build the .ts files and see if any errors have occurred;
  • run the tests using npm test (if you wish to run tests on file change, use $(npm bin)/karma start karma.config.js.);
  • lint the code with npm run lint.

Note: If you add new files or remove files, make sure to edit the "files" field in tsconfig.json:

"files": [
    // these files will always stay here
	"node_modules/typescript/lib/lib.es6.d.ts",
	"typings/main.d.ts",
	// you can change the bellow as you wish
	"src/angular.ts",
	"src/fetch.ts",
	"src/base.ts",
	"src/utils.ts"
]

If you are a contributor for the package on npm and have publish rights, you can use the following script to publish the package:

sh scripts/npm_publish.sh

FAQs

Package last updated on 08 Apr 2016

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