Skip to content

Commit

Permalink
Init Code
Browse files Browse the repository at this point in the history
  • Loading branch information
luke3butler committed Jun 10, 2017
1 parent df93738 commit eca893c
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 1 deletion.
43 changes: 42 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,42 @@
# feathers-versionate

# feathers-versionate

## About
> Service nesting for feathersjs
Nests services under configurable base paths, and provides easy methods to access those services.

## Getting Started

Install the module

NPM: `npm install feathers-versionate --save`

Yarn: `yarn add feathers-versionate`

```js
var feathers = require('feathers');
var versionate = require('feathers-versionate');
var memory = require('feathers-memory');

const app = feathers();
// Configure versionate
app.configure(versionate());
// Register a base-path "/api/v2", and provide access to it via `app.v2`
app.versionate.register('v2', '/api/v2/');
// Now you can use `app.v2` to create and access services under the registered path!
app.v2.use('/users', memory); // http://localhost:3030/api/v2/users
```

## Documentation

`feathers-versionate` is just a wrapper around app.use and app.service for applying

* `app.versionate.register(name, basePath)`

## Release History

__0.1.0__

- Initial release
- Support for app.use and app.service
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
'use strict';
module.exports = require('./src');
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"name": "feathers-versionate",
"description": "feathersjs service nesting utility",
"version": "0.1.0",
"main": "index.js",
"license": "MIT",
"dependencies": {
"uberproto": "^1.2.0"
}
}
52 changes: 52 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
'use strict';
const path = require('path');
const Proto = require('uberproto');

const service = function (name, basePath, subItem = false) {
const app = this;

// Relay use to app.use with basePath applied
const use = function () {
const args = Array.from(arguments);
const subPath = args.shift();
app.use(path.join(basePath, subPath), ...args);
}

// Relay service to app.service with basePath applied
const service = function (subPath) {
return app.service(path.join(basePath, subPath));
}

// Create an object that will be added to `app`
const newService = {};
newService[name] = {
use,
service
};

// Nest object within `vs` if flag set to true
if (subItem === true) {
newService = {
versionate: newService
};
}

// Return the new service's function methods
return newService;
}

module.exports = function () {
return function () {
const app = this;
Proto.mixin({
versionate: {
register: function () {
// Create new service
const newService = service.apply(app, Array.from(arguments));
// Add new service access method to app
Proto.mixin(newService, app)
}
}
}, app)
}
}
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


uberproto@^1.2.0:
version "1.2.0"
resolved "https://registry.yarnpkg.com/uberproto/-/uberproto-1.2.0.tgz#61d4eab024f909c4e6ea52be867c4894a4beeb76"

0 comments on commit eca893c

Please sign in to comment.