Skip to content

Commit 0367158

Browse files
Add 'packages/models/' from commit 'e1dd8e8debc3bf8cc35ab4653023fcca81c7edc0'
git-subtree-dir: packages/models git-subtree-mainline: 58bee26 git-subtree-split: e1dd8e8
2 parents 58bee26 + e1dd8e8 commit 0367158

File tree

99 files changed

+8031
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+8031
-0
lines changed

packages/models/.eslintrc.js

+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
module.exports = {
2+
'env': {
3+
'es6': true,
4+
'node': true
5+
},
6+
'parserOptions': {
7+
'ecmaVersion': 2017
8+
},
9+
'extends': 'eslint:recommended',
10+
'rules': {
11+
'indent': [
12+
'error',
13+
2
14+
],
15+
'linebreak-style': [
16+
'error',
17+
'unix'
18+
],
19+
'quotes': [
20+
'error',
21+
'single'
22+
],
23+
'semi': [
24+
'error',
25+
'always'
26+
],
27+
'curly': [
28+
'error'
29+
],
30+
'eqeqeq': [
31+
'error',
32+
'always'
33+
],
34+
'guard-for-in': [
35+
'error'
36+
],
37+
'no-multi-spaces': [
38+
'error'
39+
],
40+
'strict': [
41+
'error',
42+
'global'
43+
],
44+
'key-spacing': [
45+
'error'
46+
],
47+
'keyword-spacing': [
48+
'error'
49+
],
50+
'space-before-function-paren': [
51+
'error',
52+
'always'
53+
],
54+
'space-in-parens': [
55+
'error',
56+
'never'
57+
],
58+
'space-infix-ops': [
59+
'error'
60+
],
61+
'no-console': 'error',
62+
'no-spaced-func': [
63+
'error'
64+
],
65+
'no-whitespace-before-property': [
66+
'error'
67+
],
68+
'space-before-blocks': [
69+
'error'
70+
],
71+
'no-template-curly-in-string': [
72+
'error'
73+
],
74+
'block-scoped-var': [
75+
'error'
76+
],
77+
'complexity': [
78+
'warn',
79+
10
80+
],
81+
'dot-location': [
82+
'error',
83+
'property'
84+
],
85+
'no-else-return': 'error',
86+
'no-floating-decimal': 'error',
87+
'no-implicit-coercion': 'error',
88+
'no-implicit-globals': 'error',
89+
'no-implied-eval': 'error',
90+
'no-lone-blocks': 'error',
91+
'no-loop-func': 'error',
92+
'no-multi-str': 'error',
93+
'no-new-wrappers': 'error',
94+
'no-new': 'error',
95+
'no-return-assign': 'error',
96+
'no-throw-literal': 'error',
97+
'no-unmodified-loop-condition': 'error',
98+
'no-useless-return': 'error',
99+
'radix': [
100+
'error',
101+
'always'
102+
],
103+
'yoda': 'error',
104+
'callback-return': 'error',
105+
'global-require': 'error',
106+
'comma-spacing': [
107+
'error',
108+
{ 'before': false, 'after': true }
109+
],
110+
'comma-style': [
111+
'error',
112+
'last'
113+
],
114+
'computed-property-spacing': [
115+
'error',
116+
'never'
117+
],
118+
'eol-last': [
119+
'error',
120+
'always'
121+
],
122+
'func-call-spacing': [
123+
'error',
124+
'never'
125+
],
126+
'func-name-matching': [
127+
'error',
128+
'always'
129+
],
130+
'func-style': [
131+
'error',
132+
'expression'
133+
],
134+
'lines-around-directive': [
135+
'error'
136+
],
137+
'newline-before-return': 'error',
138+
'newline-per-chained-call': 'error',
139+
'no-lonely-if': 'error',
140+
'no-trailing-spaces': 'error',
141+
'object-curly-spacing': [
142+
'error',
143+
'always'
144+
],
145+
'operator-assignment': [
146+
'error',
147+
'never'
148+
],
149+
'no-confusing-arrow': 'error',
150+
'no-useless-computed-key': 'error',
151+
'no-var': 'error',
152+
'prefer-const': 'error',
153+
'prefer-template': 'error',
154+
'template-curly-spacing': [
155+
'error',
156+
'never'
157+
],
158+
'no-warning-comments': 'error',
159+
'prefer-promise-reject-errors': 'error'
160+
}
161+
};

packages/models/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
node_modules
2+
.vscode
3+
npm-debug.log
4+
logs
5+
.yarn-cache

packages/models/.npmignore

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
test
2+
.eslintrc*
3+
.travis.yml
4+
.gitignore
5+
.scripts
6+
.npmignore
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
'use strict';
2+
3+
/*
4+
NPM package.json version script. Do not run manually!
5+
6+
Only tested on Linux. Node v6.
7+
8+
This script overwrites the first Markdown headline "## Unreleased" with the
9+
version in the package.json and prepends a new "## Unreleased" headline.
10+
11+
*/
12+
13+
const { version } = require('../package.json'),
14+
fs = require('fs');
15+
16+
const filename = 'CHANGELOG.md';
17+
18+
fs.readFile(filename, 'utf-8', function(err, data) {
19+
if (err) return console.log(err);
20+
const result = data.replace(
21+
/## Unreleased/i,
22+
`## Unreleased\n\n## v${version}`
23+
);
24+
25+
fs.writeFile(filename, result, 'utf8', function(err) {
26+
if (err) return console.log(err);
27+
});
28+
});

packages/models/CHANGELOG.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# @sensebox/opensensemap-api-models Changelog
2+
3+
## Unreleased
4+
5+
## v0.0.3
6+
- Fix destructuring error in json and luftdaten measurement decoding
7+
8+
## v0.0.2
9+
- Re-add bunyan logging
10+
- toLowerCase email parameter in User `initPasswordReset` to conform to rest of email address handling
11+
- Fix case where addBox re-added existing box the the `boxes` array of an user
12+
- Check if user is owner of box before removing
13+
- Set email address to address from request when calling `confirmEmail` of user
14+
- Only add legacy `loc` field to box if needed
15+
- Validate that boxes need at least one sensor
16+
- Move measurement deletion code from box to sensor
17+
- Move findLastMeasurement from measurement to sensor
18+
- Pin dependency mongoose to version 4.13.6
19+
- Use `json` as default for `format` parameter of `Box.findBoxesLastMeasurements`
20+
- Parse timestamps based on RFC 3339
21+
- Convert RFC 3339 nanoseconds to milliseconds
22+
- Include PMS.. sensor models definitions from Adorfer
23+
- Populate boxes in getBoxes of User
24+
25+
## v0.0.1
26+
- Initial Release after splitting api and models

packages/models/README.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# @sensebox/opensensemap-api-models
2+
Data models and database connection for openSenseMap
3+
4+
[![NPM Version](https://img.shields.io/npm/v/@sensebox/opensensemap-api-models.svg)](https://www.npmjs.com/package/@sensebox/opensensemap-api-models)
5+
6+
## `require()` openSenseMap API models
7+
8+
Install it as dependency: `npm install --save @sensebox/opensensemap-api-models` or `yarn add @sensebox/opensensemap-api-models`
9+
10+
This allows you to use parts like models and decoding in your own project. See `index.js`.
11+
12+
## Changelog
13+
14+
See [`CHANGELOG.md`](CHANGELOG.md)
15+
16+
#### Releasing a new version
17+
To create a new version, use `npm version`.
18+
1. Document your changes in [`CHANGELOG.md`](CHANGELOG.md). Do not `git add` the file.
19+
1. Run `npm version [ major | minor | patch ] -m "[v%s] Your commit message"`
20+
1. `git push origin master`
21+
1. `npm publish`
22+
23+
## License
24+
25+
[MIT](license.md) - Matthias Pfeil 2015 - now

packages/models/index.js

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
const { model: Box } = require('./src/box/box'),
4+
{ model: Measurement } = require('./src/measurement/measurement'),
5+
{ model: Sensor } = require('./src/sensor/sensor'),
6+
{ model: User } = require('./src/user/user'),
7+
utils = require('./src/utils'),
8+
decoding = require('./src/measurement/decoding'),
9+
db = require('./src/db');
10+
11+
module.exports = {
12+
Box,
13+
Measurement,
14+
Sensor,
15+
User,
16+
utils,
17+
decoding,
18+
db
19+
};

packages/models/license.md

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2015-2017 Matthias Pfeil, Gerald Pape
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.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/* eslint-disable */
2+
3+
db = db.getSiblingDB('OSeM-api');
4+
5+
// check schema version
6+
var collections = db.getCollectionNames();
7+
8+
if (collections.indexOf("schemaVersion") === -1) {
9+
print("Error: Unkown schema version. Exiting!");
10+
quit();
11+
}
12+
13+
var latestVersion = db.schemaVersion.find({}).sort({ schemaVersion: -1 }).limit(1).next();
14+
15+
if (latestVersion.schemaVersion !== 0) {
16+
print("Migration already applied... Exiting!");
17+
quit();
18+
}
19+
20+
// move box.mqtt to box.integrations.mqtt for all boxes
21+
db.boxes.updateMany({}, {
22+
$rename: { 'mqtt': 'integrations.mqtt' }
23+
});
24+
25+
// disable mqtt by default for all boxes, which had no mqtt field
26+
db.boxes.updateMany({ 'integrations.mqtt': { $exists: false } }, {
27+
$set: { 'integrations.mqtt': { enabled: false } }
28+
});
29+
30+
db.schemaVersion.updateOne({}, { $inc: { schemaVersion: 1 }});

0 commit comments

Comments
 (0)