user model added; message model changed; tag model added

This commit is contained in:
mandutzse68104 committed 2019-06-04 14:50:37 +02:00
1 parent d27216c8a8
commit f6a8c83586
5156 files changed
+62 -437424

No files matched your search

Generated Vendored
-22
View File
@@ -1,22 +0,0 @@
(The MIT License)
Copyright (c) 2012 [Aaron Heckmann](aaron.heckmann+github@gmail.com)
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-4
View File
@@ -1,4 +0,0 @@
bench:
node bench.js
.PHONY: test
-278
View File
@@ -1,278 +0,0 @@
#mpath
{G,S}et javascript object values using MongoDB-like path notation.
###Getting
```js
var mpath = require('mpath');
var obj = {
comments: [
{ title: 'funny' },
{ title: 'exciting!' }
]
}
mpath.get('comments.1.title', obj) // 'exciting!'
```
`mpath.get` supports array property notation as well.
```js
var obj = {
comments: [
{ title: 'funny' },
{ title: 'exciting!' }
]
}
mpath.get('comments.title', obj) // ['funny', 'exciting!']
```
Array property and indexing syntax, when used together, are very powerful.
```js
var obj = {
array: [
{ o: { array: [{x: {b: [4,6,8]}}, { y: 10} ] }}
, { o: { array: [{x: {b: [1,2,3]}}, { x: {z: 10 }}, { x: 'Turkey Day' }] }}
, { o: { array: [{x: {b: null }}, { x: { b: [null, 1]}}] }}
, { o: { array: [{x: null }] }}
, { o: { array: [{y: 3 }] }}
, { o: { array: [3, 0, null] }}
, { o: { name: 'ha' }}
];
}
var found = mpath.get('array.o.array.x.b.1', obj);
console.log(found); // prints..
[ [6, undefined]
, [2, undefined, undefined]
, [null, 1]
, [null]
, [undefined]
, [undefined, undefined, undefined]
, undefined
]
```
#####Field selection rules:
The following rules are iteratively applied to each `segment` in the passed `path`. For example:
```js
var path = 'one.two.14'; // path
'one' // segment 0
'two' // segment 1
14 // segment 2
```
- 1) when value of the segment parent is not an array, return the value of `parent.segment`
- 2) when value of the segment parent is an array
- a) if the segment is an integer, replace the parent array with the value at `parent[segment]`
- b) if not an integer, keep the array but replace each array `item` with the value returned from calling `get(remainingSegments, item)` or undefined if falsey.
#####Maps
`mpath.get` also accepts an optional `map` argument which receives each individual found value. The value returned from the `map` function will be used in the original found values place.
```js
var obj = {
comments: [
{ title: 'funny' },
{ title: 'exciting!' }
]
}
mpath.get('comments.title', obj, function (val) {
return 'funny' == val
? 'amusing'
: val;
});
// ['amusing', 'exciting!']
```
###Setting
```js
var obj = {
comments: [
{ title: 'funny' },
{ title: 'exciting!' }
]
}
mpath.set('comments.1.title', 'hilarious', obj)
console.log(obj.comments[1].title) // 'hilarious'
```
`mpath.set` supports the same array property notation as `mpath.get`.
```js
var obj = {
comments: [
{ title: 'funny' },
{ title: 'exciting!' }
]
}
mpath.set('comments.title', ['hilarious', 'fruity'], obj);
console.log(obj); // prints..
{ comments: [
{ title: 'hilarious' },
{ title: 'fruity' }
]}
```
Array property and indexing syntax can be used together also when setting.
```js
var obj = {
array: [
{ o: { array: [{x: {b: [4,6,8]}}, { y: 10} ] }}
, { o: { array: [{x: {b: [1,2,3]}}, { x: {z: 10 }}, { x: 'Turkey Day' }] }}
, { o: { array: [{x: {b: null }}, { x: { b: [null, 1]}}] }}
, { o: { array: [{x: null }] }}
, { o: { array: [{y: 3 }] }}
, { o: { array: [3, 0, null] }}
, { o: { name: 'ha' }}
]
}
mpath.set('array.1.o', 'this was changed', obj);
console.log(require('util').inspect(obj, false, 1000)); // prints..
{
array: [
{ o: { array: [{x: {b: [4,6,8]}}, { y: 10} ] }}
, { o: 'this was changed' }
, { o: { array: [{x: {b: null }}, { x: { b: [null, 1]}}] }}
, { o: { array: [{x: null }] }}
, { o: { array: [{y: 3 }] }}
, { o: { array: [3, 0, null] }}
, { o: { name: 'ha' }}
];
}
mpath.set('array.o.array.x', 'this was changed too', obj);
console.log(require('util').inspect(obj, false, 1000)); // prints..
{
array: [
{ o: { array: [{x: 'this was changed too'}, { y: 10, x: 'this was changed too'} ] }}
, { o: 'this was changed' }
, { o: { array: [{x: 'this was changed too'}, { x: 'this was changed too'}] }}
, { o: { array: [{x: 'this was changed too'}] }}
, { o: { array: [{x: 'this was changed too', y: 3 }] }}
, { o: { array: [3, 0, null] }}
, { o: { name: 'ha' }}
];
}
```
####Setting arrays
By default, setting a property within an array to another array results in each element of the new array being set to the item in the destination array at the matching index. An example is helpful.
```js
var obj = {
comments: [
{ title: 'funny' },
{ title: 'exciting!' }
]
}
mpath.set('comments.title', ['hilarious', 'fruity'], obj);
console.log(obj); // prints..
{ comments: [
{ title: 'hilarious' },
{ title: 'fruity' }
]}
```
If we do not desire this destructuring-like assignment behavior we may instead specify the `$` operator in the path being set to force the array to be copied directly.
```js
var obj = {
comments: [
{ title: 'funny' },
{ title: 'exciting!' }
]
}
mpath.set('comments.$.title', ['hilarious', 'fruity'], obj);
console.log(obj); // prints..
{ comments: [
{ title: ['hilarious', 'fruity'] },
{ title: ['hilarious', 'fruity'] }
]}
```
####Field assignment rules
The rules utilized mirror those used on `mpath.get`, meaning we can take values returned from `mpath.get`, update them, and reassign them using `mpath.set`. Note that setting nested arrays of arrays can get unweildy quickly. Check out the [tests](https://github.com/aheckmann/mpath/blob/master/test/index.js) for more extreme examples.
#####Maps
`mpath.set` also accepts an optional `map` argument which receives each individual value being set. The value returned from the `map` function will be used in the original values place.
```js
var obj = {
comments: [
{ title: 'funny' },
{ title: 'exciting!' }
]
}
mpath.set('comments.title', ['hilarious', 'fruity'], obj, function (val) {
return val.length;
});
console.log(obj); // prints..
{ comments: [
{ title: 9 },
{ title: 6 }
]}
```
### Custom object types
Sometimes you may want to enact the same functionality on custom object types that store all their real data internally, say for an ODM type object. No fear, `mpath` has you covered. Simply pass the name of the property being used to store the internal data and it will be traversed instead:
```js
var mpath = require('mpath');
var obj = {
comments: [
{ title: 'exciting!', _doc: { title: 'great!' }}
]
}
mpath.get('comments.0.title', obj, '_doc') // 'great!'
mpath.set('comments.0.title', 'nov 3rd', obj, '_doc')
mpath.get('comments.0.title', obj, '_doc') // 'nov 3rd'
mpath.get('comments.0.title', obj) // 'exciting'
```
When used with a `map`, the `map` argument comes last.
```js
mpath.get(path, obj, '_doc', map);
mpath.set(path, val, obj, '_doc', map);
```
[LICENSE](https://github.com/aheckmann/mpath/blob/master/LICENSE)
-109
View File
@@ -1,109 +0,0 @@
var mpath = require('./')
var Bench = require('benchmark');
var sha = require('child_process').exec("git log --pretty=format:'%h' -n 1", function (err, sha) {
if (err) throw err;
var fs = require('fs')
var filename = __dirname + '/bench.out';
var out = fs.createWriteStream(filename, { flags: 'a', encoding: 'utf8' });
/**
* test doc creator
*/
function doc () {
var o = { first: { second: { third: [3,{ name: 'aaron' }, 9] }}};
o.comments = [
{ name: 'one' }
, { name: 'two', _doc: { name: '2' }}
, { name: 'three'
, comments: [{},{ comments: [{val: 'twoo'}]}]
, _doc: { name: '3', comments: [{},{ _doc: { comments: [{ val: 2 }] }}] }}
];
o.name = 'jiro';
o.array = [
{ o: { array: [{x: {b: [4,6,8]}}, { y: 10} ] }}
, { o: { array: [{x: {b: [1,2,3]}}, { x: {z: 10 }}, { x: {b: 'hi'}}] }}
, { o: { array: [{x: {b: null }}, { x: { b: [null, 1]}}] }}
, { o: { array: [{x: null }] }}
, { o: { array: [{y: 3 }] }}
, { o: { array: [3, 0, null] }}
, { o: { name: 'ha' }}
];
o.arr = [
{ arr: [{ a: { b: 47 }}, { a: { c: 48 }}, { d: 'yep' }] }
, { yep: true }
]
return o;
}
var o = doc();
var s = new Bench.Suite;
s.add('mpath.get("first", obj)', function () {
mpath.get('first', o);
})
s.add('mpath.get("first.second", obj)', function () {
mpath.get('first.second', o);
})
s.add('mpath.get("first.second.third.1.name", obj)', function () {
mpath.get('first.second.third.1.name', o);
})
s.add('mpath.get("comments", obj)', function () {
mpath.get('comments', o);
})
s.add('mpath.get("comments.1", obj)', function () {
mpath.get('comments.1', o);
})
s.add('mpath.get("comments.2.name", obj)', function () {
mpath.get('comments.2.name', o);
})
s.add('mpath.get("comments.2.comments.1.comments.0.val", obj)', function () {
mpath.get('comments.2.comments.1.comments.0.val', o);
})
s.add('mpath.get("comments.name", obj)', function () {
mpath.get('comments.name', o);
})
s.add('mpath.set("first", obj, val)', function () {
mpath.set('first', o, 1);
})
s.add('mpath.set("first.second", obj, val)', function () {
mpath.set('first.second', o, 1);
})
s.add('mpath.set("first.second.third.1.name", obj, val)', function () {
mpath.set('first.second.third.1.name', o, 1);
})
s.add('mpath.set("comments", obj, val)', function () {
mpath.set('comments', o, 1);
})
s.add('mpath.set("comments.1", obj, val)', function () {
mpath.set('comments.1', o, 1);
})
s.add('mpath.set("comments.2.name", obj, val)', function () {
mpath.set('comments.2.name', o, 1);
})
s.add('mpath.set("comments.2.comments.1.comments.0.val", obj, val)', function () {
mpath.set('comments.2.comments.1.comments.0.val', o, 1);
})
s.add('mpath.set("comments.name", obj, val)', function () {
mpath.set('comments.name', o, 1);
})
s.on('start', function () {
console.log('starting...');
out.write('*' + sha + ': ' + String(new Date()) + '\n');
});
s.on('cycle', function (e) {
var s = String(e.target);
console.log(s);
out.write(s + '\n');
})
s.on('complete', function () {
console.log('done')
out.end('');
})
s.run()
})
View File
Whitespace-only changes.
-52
View File
@@ -1,52 +0,0 @@
*b566c26: Fri Mar 15 2013 14:14:04 GMT-0700 (PDT)
mpath.get("first", obj) x 3,827,405 ops/sec ±0.91% (90 runs sampled)
mpath.get("first.second", obj) x 4,930,222 ops/sec ±1.92% (91 runs sampled)
mpath.get("first.second.third.1.name", obj) x 3,070,837 ops/sec ±1.45% (97 runs sampled)
mpath.get("comments", obj) x 3,649,771 ops/sec ±1.71% (93 runs sampled)
mpath.get("comments.1", obj) x 3,846,728 ops/sec ±0.86% (94 runs sampled)
mpath.get("comments.2.name", obj) x 3,527,680 ops/sec ±0.95% (96 runs sampled)
mpath.get("comments.2.comments.1.comments.0.val", obj) x 2,046,982 ops/sec ±0.80% (96 runs sampled)
mpath.get("comments.name", obj) x 625,546 ops/sec ±2.02% (82 runs sampled)
*e42bdb1: Fri Mar 15 2013 14:19:28 GMT-0700 (PDT)
mpath.get("first", obj) x 3,700,783 ops/sec ±1.30% (95 runs sampled)
mpath.get("first.second", obj) x 4,621,795 ops/sec ±0.86% (95 runs sampled)
mpath.get("first.second.third.1.name", obj) x 3,012,671 ops/sec ±1.21% (100 runs sampled)
mpath.get("comments", obj) x 3,677,694 ops/sec ±0.80% (96 runs sampled)
mpath.get("comments.1", obj) x 3,798,862 ops/sec ±0.81% (91 runs sampled)
mpath.get("comments.2.name", obj) x 3,489,356 ops/sec ±0.66% (98 runs sampled)
mpath.get("comments.2.comments.1.comments.0.val", obj) x 2,004,076 ops/sec ±0.85% (99 runs sampled)
mpath.get("comments.name", obj) x 613,270 ops/sec ±1.33% (83 runs sampled)
*0521aac: Fri Mar 15 2013 16:37:16 GMT-0700 (PDT)
mpath.get("first", obj) x 3,834,755 ops/sec ±0.70% (100 runs sampled)
mpath.get("first.second", obj) x 4,999,965 ops/sec ±1.01% (98 runs sampled)
mpath.get("first.second.third.1.name", obj) x 3,125,953 ops/sec ±0.97% (100 runs sampled)
mpath.get("comments", obj) x 3,759,233 ops/sec ±0.81% (97 runs sampled)
mpath.get("comments.1", obj) x 3,894,893 ops/sec ±0.76% (96 runs sampled)
mpath.get("comments.2.name", obj) x 3,576,929 ops/sec ±0.68% (98 runs sampled)
mpath.get("comments.2.comments.1.comments.0.val", obj) x 2,149,610 ops/sec ±0.67% (97 runs sampled)
mpath.get("comments.name", obj) x 629,259 ops/sec ±1.30% (87 runs sampled)
mpath.set("first", obj, val) x 2,869,477 ops/sec ±0.63% (97 runs sampled)
mpath.set("first.second", obj, val) x 2,418,751 ops/sec ±0.62% (98 runs sampled)
mpath.set("first.second.third.1.name", obj, val) x 2,313,099 ops/sec ±0.69% (94 runs sampled)
mpath.set("comments", obj, val) x 2,680,882 ops/sec ±0.76% (99 runs sampled)
mpath.set("comments.1", obj, val) x 2,401,829 ops/sec ±0.68% (98 runs sampled)
mpath.set("comments.2.name", obj, val) x 2,335,081 ops/sec ±1.07% (96 runs sampled)
mpath.set("comments.2.comments.1.comments.0.val", obj, val) x 2,245,436 ops/sec ±0.76% (92 runs sampled)
mpath.set("comments.name", obj, val) x 2,356,278 ops/sec ±1.15% (100 runs sampled)
*97e85d3: Fri Mar 15 2013 16:39:21 GMT-0700 (PDT)
mpath.get("first", obj) x 3,837,614 ops/sec ±0.74% (99 runs sampled)
mpath.get("first.second", obj) x 4,991,779 ops/sec ±1.01% (94 runs sampled)
mpath.get("first.second.third.1.name", obj) x 3,078,455 ops/sec ±1.17% (96 runs sampled)
mpath.get("comments", obj) x 3,770,961 ops/sec ±0.45% (101 runs sampled)
mpath.get("comments.1", obj) x 3,832,814 ops/sec ±0.67% (92 runs sampled)
mpath.get("comments.2.name", obj) x 3,536,436 ops/sec ±0.49% (100 runs sampled)
mpath.get("comments.2.comments.1.comments.0.val", obj) x 2,141,947 ops/sec ±0.72% (98 runs sampled)
mpath.get("comments.name", obj) x 667,898 ops/sec ±1.62% (85 runs sampled)
mpath.set("first", obj, val) x 2,642,517 ops/sec ±0.72% (98 runs sampled)
mpath.set("first.second", obj, val) x 2,502,124 ops/sec ±1.28% (99 runs sampled)
mpath.set("first.second.third.1.name", obj, val) x 2,426,804 ops/sec ±0.55% (99 runs sampled)
mpath.set("comments", obj, val) x 2,699,478 ops/sec ±0.85% (98 runs sampled)
mpath.set("comments.1", obj, val) x 2,494,454 ops/sec ±1.05% (96 runs sampled)
mpath.set("comments.2.name", obj, val) x 2,463,894 ops/sec ±0.86% (98 runs sampled)
mpath.set("comments.2.comments.1.comments.0.val", obj, val) x 2,320,398 ops/sec ±0.82% (95 runs sampled)
mpath.set("comments.name", obj, val) x 2,512,408 ops/sec ±0.77% (95 runs sampled)
-8
View File
@@ -1,8 +0,0 @@
{
"name": "mpath",
"version": "0.2.1",
"main": "lib/index.js",
"scripts": [
"lib/index.js"
]
}
-1
View File
@@ -1 +0,0 @@
module.exports = exports = require('./lib');