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

grunt-angularjs-thrift-0.9

v0.1.8

Published

Thrift 0.9.x Angular Code Generator ============================= Make Thrift rpc calls to your Thrift http server, from javascript in a browser, in a website or cordova/phonegap app. This is a grunt module that compiles Thrift IDL into commonjs javascri

Downloads

2

Readme

Thrift 0.9.x Angular Code Generator

Make Thrift rpc calls to your Thrift http server, from javascript in a browser, in a website or cordova/phonegap app. This is a grunt module that compiles Thrift IDL into commonjs javascript, for use with browserify or webpack. The generated angularjs module generates an angular service for each Thrift service, at runtime. For Thrift 1.0 support, see grunt-angularjs-thrift.

Dependencies

Install a thrift 0.9.x compiler on your machine: Apache Thrift

Installation

npm install grunt-angularjs-thrift-0.9

Example Gruntfile.js Configuration


    module.exports = function (grunt) {
      // load the grunt plugin
      require('grunt-angularjs-thrift-0.9/compiler/grunt-thrift-generator')(grunt);

      // configure the grunt plugin
      grunt.initConfig({
        thriftcompiler: {
          deluxe: {
            files: [
              {
                src: 'app/src/thrift/**/*.thrift',
                dest: 'app/src/generated'
              }
            ],
            thriftSrcRoot: 'app/src/thrift/', // root directory of the above src path
            thriftBin: 'thrift', // this is your Thrift 0.9.x compiler

            // (optional) with this property, it will generate angular services (at runtime, so you won't find any generated js files with angular services)
            angularServices: {
              rootEndpointUrl: '/thrift-api/v1/', // root uri path of all your thrift service endpoints (domain name is configured elsewhere)
              thriftRetryHandler: { // user-provided error handler, for thrift and http errors (see the example below)
                angularModule: 'thrift-retry',
                angularService: 'CustomThriftRetryHandler'
              }
            }
          },
          compileOnly: {
            files: [
              {
                src: 'app/src/thrift/**/*.thrift',
                dest: 'app/src/generated'
              }
            ],
            thriftSrcRoot: 'app/src/thrift/',
            thriftBin: 'thrift'
          }
        }
      });

    };

Example: User-Provided Thrift Error Handler

For example, always retry the same exact thrift call once, for whatever reason.


    // app/src/thrift/thrift-retry-service.js

    require('angular');

    var thriftRetryModule = angular.module('thrift-retry', []);
    thriftRetryModule.service('CustomThriftRetryHandler', [function CustomThriftRetryHandler() {

      this.handleError = function handleError(thriftClient, reason, state) {
        if (state.callCount > 2) {
          thriftClient.reject(reason);
        } else {
          thriftClient.retry();
        }
      };

    }]);

Example: Load Thrift In Your App


    // app/src/thrift/thrift-services.js

    // the generated thrift js module returns a configuration object with instructions for generating angular services
    var generated = require('../generated/compiled_thrift');

    // the generated angular thrift services will depend on your custom angular service, for error handling
    require('./thrift-retry-service');

    // generate the angular thrift services, in the ngThriftServices module
    require('grunt-angularjs-thrift-0.9/runtime/ng-thrift-services')(generated);

    // your module must depend on the ngThriftServices module, provided by grunt-angularjs-thrift-0.9
    angular.module('my-module', ['ngThriftServices']);

    // the naming convention for angular thrift services is: [Thrift][your service name]. So, a thrift service named
    // SomethingService would have an angular thrift service name ThriftSomethingService
    angular.module('my-module').service('MyService', ['ThriftSomethingService', function (ThriftSomethingService) {
      ThriftSomethingService.callRoomService().then(function (response) {
        console.log('response from server:', response);
      }, function (reason) {
        console.log('thrift rpc call failed:', reason);
      });
    }]);

    // app/src/thrift/services.thrift

    service SomethingService {
     string callRoomService()
    }

TODO

  1. more documentation
  2. example project