-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df93738
commit eca893c
Showing
5 changed files
with
113 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
'use strict'; | ||
module.exports = require('./src'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" |