Skip to content

Commit c3468c8

Browse files
committed
Initial Commit
0 parents  commit c3468c8

15 files changed

+5929
-0
lines changed

.eslintrc

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"root": true,
3+
"parser": "@typescript-eslint/parser",
4+
"parserOptions": {
5+
"project": "./tsconfig.eslint.json"
6+
},
7+
"plugins": [
8+
"@typescript-eslint"
9+
],
10+
"extends": [
11+
"airbnb-typescript/base",
12+
"plugin:@typescript-eslint/eslint-recommended",
13+
"plugin:@typescript-eslint/recommended"
14+
],
15+
"rules": {
16+
"no-underscore-dangle": "off",
17+
"@typescript-eslint/no-explicit-any": "off",
18+
"@typescript-eslint/naming-convention": [
19+
"error",
20+
{
21+
"selector": ["function"],
22+
"format": null,
23+
"leadingUnderscore": "allow"
24+
}
25+
],
26+
"class-methods-use-this": [
27+
"error",
28+
{
29+
"exceptMethods": [
30+
"_getId",
31+
"_getSortQuery",
32+
"_getLimitQuery",
33+
"_getSkipQuery",
34+
"_mapQueryOperator"
35+
]
36+
}
37+
]
38+
}
39+
}

.gitignore

+131
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
2+
# Created by https://www.toptal.com/developers/gitignore/api/node
3+
# Edit at https://www.toptal.com/developers/gitignore?templates=node
4+
5+
### Node ###
6+
# Logs
7+
logs
8+
*.log
9+
npm-debug.log*
10+
yarn-debug.log*
11+
yarn-error.log*
12+
lerna-debug.log*
13+
14+
# Diagnostic reports (https://nodejs.org/api/report.html)
15+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
16+
17+
# Runtime data
18+
pids
19+
*.pid
20+
*.seed
21+
*.pid.lock
22+
23+
# Directory for instrumented libs generated by jscoverage/JSCover
24+
lib-cov
25+
26+
# Coverage directory used by tools like istanbul
27+
coverage
28+
*.lcov
29+
30+
# nyc test coverage
31+
.nyc_output
32+
33+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
34+
.grunt
35+
36+
# Bower dependency directory (https://bower.io/)
37+
bower_components
38+
39+
# node-waf configuration
40+
.lock-wscript
41+
42+
# Compiled binary addons (https://nodejs.org/api/addons.html)
43+
build/Release
44+
45+
# Dependency directories
46+
node_modules/
47+
jspm_packages/
48+
49+
# TypeScript v1 declaration files
50+
typings/
51+
52+
# TypeScript cache
53+
*.tsbuildinfo
54+
55+
# Optional npm cache directory
56+
.npm
57+
58+
# Optional eslint cache
59+
.eslintcache
60+
61+
# Optional stylelint cache
62+
.stylelintcache
63+
64+
# Microbundle cache
65+
.rpt2_cache/
66+
.rts2_cache_cjs/
67+
.rts2_cache_es/
68+
.rts2_cache_umd/
69+
70+
# Optional REPL history
71+
.node_repl_history
72+
73+
# Output of 'npm pack'
74+
*.tgz
75+
76+
# Yarn Integrity file
77+
.yarn-integrity
78+
79+
# dotenv environment variables file
80+
.env
81+
.env.test
82+
.env*.local
83+
84+
# parcel-bundler cache (https://parceljs.org/)
85+
.cache
86+
.parcel-cache
87+
88+
# Next.js build output
89+
.next
90+
91+
# Nuxt.js build / generate output
92+
.nuxt
93+
dist
94+
95+
# Storybook build outputs
96+
.out
97+
.storybook-out
98+
storybook-static
99+
100+
# rollup.js default build output
101+
dist/
102+
103+
# Gatsby files
104+
.cache/
105+
# Comment in the public line in if your project uses Gatsby and not Next.js
106+
# https://nextjs.org/blog/next-9-1#public-directory-support
107+
# public
108+
109+
# vuepress build output
110+
.vuepress/dist
111+
112+
# Serverless directories
113+
.serverless/
114+
115+
# FuseBox cache
116+
.fusebox/
117+
118+
# DynamoDB Local files
119+
.dynamodb/
120+
121+
# TernJS port file
122+
.tern-port
123+
124+
# Stores VSCode versions used for testing VSCode extensions
125+
.vscode-test
126+
127+
# Temporary folders
128+
tmp/
129+
temp/
130+
131+
# End of https://www.toptal.com/developers/gitignore/api/node

.npmignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# .vscode directory
2+
.vscode
3+
4+
# test directory
5+
test
6+
7+
# nyc test coverage
8+
.nyc_output

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"typescript.tsdk": "node_modules\\typescript\\lib"
3+
}

CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## 0.1.0 (June 4, 2021)
2+
3+
Initial Release

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Joseph Gan
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+138
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,138 @@
1+
# feathers-ottoman
2+
3+
__IMPORTANT__: This is still in early development stage, please report any issue found
4+
5+
This library is written against [ottoman-2.0.0-beta.1](https://github.com/couchbaselabs/node-ottoman). It is tested against [Couchbase 7.0 BETA](https://docs.couchbase.com/server/7.0/introduction/intro.html) which supports [scope and collection](https://docs.couchbase.com/server/7.0/learn/data/scopes-and-collections.html) and it should work with current version, [Couchbase 6.6](https://docs.couchbase.com/server/current/introduction/intro.html)
6+
7+
---
8+
9+
A [Feathers](https://feathersjs.com) database adapter for [Ottoman](https://ottomanjs.com/), an object modeling tool for [Couchbase](https://www.couchbase.com/)
10+
11+
```bash
12+
$ npm install feathers-ottoman
13+
```
14+
15+
> __Important:__ `feathers-ottoman` implements the [Feathers Common database adapter API](https://docs.feathersjs.com/api/databases/common.html) and [querying syntax](https://docs.feathersjs.com/api/databases/querying.html)
16+
17+
> This adapter also requires a [running Couchbase](https://docs.couchbase.com/tutorials/getting-started-ce/index.html) database server
18+
19+
## API
20+
21+
### `service([options])`
22+
23+
Returns a new service instance initialized with the given options. `Model` has to be a `Ottoman` model. See the [Ottoman Guide](https://ottomanjs.com/guides/schema.html#defining-your-schema) for more information on defining your model
24+
25+
```js
26+
// commonjs
27+
const service = require('feathers-ottoman');
28+
// es6 / typescript
29+
import { service } from 'feathers-ottoman';
30+
31+
app.use('/messages', service({ Model }));
32+
app.use('/messages', service({ Model, id, events, paginate, ottoman: { lean, consistency } }));
33+
```
34+
35+
__Options:__
36+
37+
- `Model` (**required**) - The Ottoman model definition
38+
- `id` (*optional*, default: `'id'`) - The name of the id field property. Note that the `id` has to be also define when initializing the `Ottoman Model` if not using default value
39+
- `events` (*optional*) - A list of [custom service events](https://docs.feathersjs.com/api/events.html#custom-events) sent by this service
40+
- `paginate` (*optional*) - A [pagination object](https://docs.feathersjs.com/api/databases/common.html#pagination) containing a `default` and `max` page size
41+
- `whitelist` (*optional*) - A list of additional query parameters to allow
42+
- `multi` (*optional*) - Allow `create` with arrays and `update` and `remove` with `id` `null` to change multiple items. Can be `true` for all methods or an array of allowed methods (e.g. `[ 'remove', 'create' ]`)
43+
- `ottoman.lean` (*optional*, default: `true`) - Runs queries faster by returning plain objects instead of `Ottoman Model`
44+
- `ottoman.consistency` (*optional*, default: `NONE`) - Define default [Search Consistency Strategy](https://docs.couchbase.com/server/current/learn/services-and-indexes/indexes/index-replication.html#index-consistency)
45+
46+
> **Note:** You can get access to the Ottoman model via `this.Model` inside a [hook](https://docs.feathersjs.com/api/hooks.html) and use it as usual. See the [Ottoman Guide](https://ottomanjs.com/guides/schema.html#defining-your-schema) for more information on defining your model
47+
48+
## Example
49+
50+
Here is an example of a Feathers server with a `messages` Ottoman service
51+
52+
```
53+
$ npm install @feathersjs/feathers @feathersjs/express ottoman feathers-ottoman
54+
```
55+
56+
In `index.js`:
57+
58+
```js
59+
// Initialize Ottoman connection
60+
const { Ottoman, getModel, Schema, SearchConsistency } = require('ottoman');
61+
62+
const ottoman = new Ottoman();
63+
64+
ottoman.connect({
65+
connectionString: 'couchbase://localhost',
66+
bucketName: 'messageBucket',
67+
username: 'user',
68+
password: 'password',
69+
});
70+
71+
const modelOptions = {
72+
// specify `idKey` if not using default
73+
// idKey: 'customId',
74+
scopeName: 'messageScope',
75+
collectionName: 'messageCollection',
76+
};
77+
78+
const schema = new Schema({
79+
text: { type: String },
80+
});
81+
82+
ottoman.model('message', schema, modelOptions);
83+
84+
ottoman.start();
85+
86+
// Setup feathers service
87+
const feathers = require('@feathersjs/feathers');
88+
const express = require('@feathersjs/express');
89+
90+
const { Service } = require('feathers-ottoman');
91+
92+
// Creates an ExpressJS compatible Feathers application
93+
const app = express(feathers());
94+
95+
// Parse HTTP JSON bodies
96+
app.use(express.json());
97+
// Parse URL-encoded params
98+
app.use(express.urlencoded({ extended: true }));
99+
// Host static files from the current folder
100+
app.use(express.static(__dirname));
101+
// Add REST API support
102+
app.configure(express.rest());
103+
// Register a Ottoman message service
104+
app.use('/messages', new Service({
105+
Model: getModel('message'),
106+
// if `idKey` is specify for the Model
107+
// id: 'customid',
108+
ottoman: {
109+
lean: true,
110+
consistency: SearchConsistency.LOCAL,
111+
},
112+
paginate: {
113+
default: 10,
114+
max: 100
115+
}
116+
}));
117+
// Register a nicer error handler than the default Express one
118+
app.use(express.errorHandler());
119+
120+
// Create a dummy Message
121+
app.service('messages').create({
122+
text: 'Message created on Ottoman server'
123+
}).then(function(message) {
124+
console.log('Created messages', message);
125+
});
126+
127+
app.listen(3030).on('listening', () => console.log('feathers-ottoman example started'));
128+
```
129+
130+
Run the example with `node .` and go to [localhost:3030/messages](http://localhost:3030/messages)
131+
132+
For a complete example, take a look at [feathers-ottoman-demo](https://github.com/bwgjoseph/feathers-ottoman-demo) repository
133+
134+
## License
135+
136+
Copyright (c) 2021
137+
138+
Licensed under the [MIT license](LICENSE).

0 commit comments

Comments
 (0)