@electerm/nedb 1.10.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +10 -717
- package/lib/async.js +237 -0
- package/lib/cursor.js +1 -1
- package/lib/datastore.js +10 -8
- package/lib/executor.js +1 -1
- package/lib/indexes.js +12 -10
- package/lib/model.js +37 -34
- package/lib/persistence.js +2 -2
- package/lib/storage.js +1 -1
- package/lib/underscore.js +177 -0
- package/lib/util.js +44 -0
- package/package.json +25 -20
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Minimal underscore.js replacement with only the functions needed by nedb
|
|
3
|
+
* This replaces the full underscore library to reduce dependencies
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Returns the intersection of arrays - elements that appear in all arrays
|
|
8
|
+
* @param {Array} array - First array
|
|
9
|
+
* @param {...Array} arrays - Additional arrays to intersect with
|
|
10
|
+
* @returns {Array} - Array of elements that appear in all input arrays
|
|
11
|
+
*/
|
|
12
|
+
function intersection(array) {
|
|
13
|
+
if (!Array.isArray(array)) return [];
|
|
14
|
+
|
|
15
|
+
var result = [];
|
|
16
|
+
var argsLength = arguments.length;
|
|
17
|
+
|
|
18
|
+
for (var i = 0; i < array.length; i++) {
|
|
19
|
+
var item = array[i];
|
|
20
|
+
var included = true;
|
|
21
|
+
|
|
22
|
+
// Check if item exists in all other arrays
|
|
23
|
+
for (var j = 1; j < argsLength; j++) {
|
|
24
|
+
var otherArray = arguments[j];
|
|
25
|
+
if (!Array.isArray(otherArray) || otherArray.indexOf(item) === -1) {
|
|
26
|
+
included = false;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// Add to result if not already there and exists in all arrays
|
|
32
|
+
if (included && result.indexOf(item) === -1) {
|
|
33
|
+
result.push(item);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return result;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Extracts property values from an array of objects
|
|
42
|
+
* @param {Array} array - Array of objects
|
|
43
|
+
* @param {String} property - Property name to extract
|
|
44
|
+
* @returns {Array} - Array of extracted property values
|
|
45
|
+
*/
|
|
46
|
+
function pluck(array, property) {
|
|
47
|
+
if (!Array.isArray(array)) return [];
|
|
48
|
+
|
|
49
|
+
var result = [];
|
|
50
|
+
for (var i = 0; i < array.length; i++) {
|
|
51
|
+
if (array[i] && array[i].hasOwnProperty(property)) {
|
|
52
|
+
result.push(array[i][property]);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
return result;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Returns a copy of object with specified keys omitted
|
|
60
|
+
* @param {Object} obj - Source object
|
|
61
|
+
* @param {...String} keys - Keys to omit
|
|
62
|
+
* @returns {Object} - New object without the omitted keys
|
|
63
|
+
*/
|
|
64
|
+
function omit(obj) {
|
|
65
|
+
if (typeof obj !== 'object' || obj === null) return {};
|
|
66
|
+
|
|
67
|
+
var result = {};
|
|
68
|
+
var keysToOmit = Array.prototype.slice.call(arguments, 1);
|
|
69
|
+
|
|
70
|
+
for (var key in obj) {
|
|
71
|
+
if (obj.hasOwnProperty(key) && keysToOmit.indexOf(key) === -1) {
|
|
72
|
+
result[key] = obj[key];
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Checks if object has the given key as a direct property
|
|
81
|
+
* @param {Object} obj - Object to check
|
|
82
|
+
* @param {String} key - Key to check for
|
|
83
|
+
* @returns {Boolean} - True if object has the key
|
|
84
|
+
*/
|
|
85
|
+
function has(obj, key) {
|
|
86
|
+
return obj != null && Object.prototype.hasOwnProperty.call(obj, key);
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Creates a new array with results of calling provided function on every element
|
|
91
|
+
* @param {Array} array - Array to map over
|
|
92
|
+
* @param {Function} iteratee - Function to call for each element
|
|
93
|
+
* @returns {Array} - New array with mapped values
|
|
94
|
+
*/
|
|
95
|
+
function map(array, iteratee) {
|
|
96
|
+
if (!Array.isArray(array) || typeof iteratee !== 'function') return [];
|
|
97
|
+
|
|
98
|
+
var result = [];
|
|
99
|
+
for (var i = 0; i < array.length; i++) {
|
|
100
|
+
result.push(iteratee(array[i], i, array));
|
|
101
|
+
}
|
|
102
|
+
return result;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* Creates a new array with all elements that pass the test implemented by provided function
|
|
107
|
+
* @param {Array} array - Array to filter
|
|
108
|
+
* @param {Function} predicate - Function to test each element
|
|
109
|
+
* @returns {Array} - New array with filtered elements
|
|
110
|
+
*/
|
|
111
|
+
function filter(array, predicate) {
|
|
112
|
+
if (!Array.isArray(array) || typeof predicate !== 'function') return [];
|
|
113
|
+
|
|
114
|
+
var result = [];
|
|
115
|
+
for (var i = 0; i < array.length; i++) {
|
|
116
|
+
if (predicate(array[i], i, array)) {
|
|
117
|
+
result.push(array[i]);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
return result;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Creates a duplicate-free version of an array
|
|
125
|
+
* @param {Array} array - Array to make unique
|
|
126
|
+
* @param {Function} iteratee - Optional function to compute uniqueness criterion
|
|
127
|
+
* @returns {Array} - New array with unique values
|
|
128
|
+
*/
|
|
129
|
+
function uniq(array, iteratee) {
|
|
130
|
+
if (!Array.isArray(array)) return [];
|
|
131
|
+
|
|
132
|
+
var result = [];
|
|
133
|
+
var seen = [];
|
|
134
|
+
|
|
135
|
+
for (var i = 0; i < array.length; i++) {
|
|
136
|
+
var value = array[i];
|
|
137
|
+
var computed = iteratee ? iteratee(value) : value;
|
|
138
|
+
|
|
139
|
+
if (seen.indexOf(computed) === -1) {
|
|
140
|
+
seen.push(computed);
|
|
141
|
+
result.push(value);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
return result;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Checks if value is a function
|
|
150
|
+
* @param {*} value - Value to check
|
|
151
|
+
* @returns {Boolean} - True if value is a function
|
|
152
|
+
*/
|
|
153
|
+
function isFunction(value) {
|
|
154
|
+
return typeof value === 'function';
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Checks if value is a boolean
|
|
159
|
+
* @param {*} value - Value to check
|
|
160
|
+
* @returns {Boolean} - True if value is a boolean
|
|
161
|
+
*/
|
|
162
|
+
function isBoolean(value) {
|
|
163
|
+
return typeof value === 'boolean';
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Export the functions
|
|
167
|
+
module.exports = {
|
|
168
|
+
intersection: intersection,
|
|
169
|
+
pluck: pluck,
|
|
170
|
+
omit: omit,
|
|
171
|
+
has: has,
|
|
172
|
+
map: map,
|
|
173
|
+
filter: filter,
|
|
174
|
+
uniq: uniq,
|
|
175
|
+
isFunction: isFunction,
|
|
176
|
+
isBoolean: isBoolean
|
|
177
|
+
};
|
package/lib/util.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
var util = require('util');
|
|
2
|
+
|
|
3
|
+
function isDate(obj) {
|
|
4
|
+
return Object.prototype.toString.call(obj) === '[object Date]';
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function isRegExp(obj) {
|
|
8
|
+
return Object.prototype.toString.call(obj) === '[object RegExp]';
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function isArray(obj) {
|
|
12
|
+
if (typeof Array.isArray === 'function') {
|
|
13
|
+
return Array.isArray(obj);
|
|
14
|
+
}
|
|
15
|
+
return util.isArray(obj);
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function inherits(ctor, superCtor) {
|
|
19
|
+
if (ctor === undefined || ctor === null) {
|
|
20
|
+
throw new TypeError('The constructor to inherit from must not be null or undefined');
|
|
21
|
+
}
|
|
22
|
+
if (typeof superCtor !== 'function') {
|
|
23
|
+
throw new TypeError('The super constructor must be a function');
|
|
24
|
+
}
|
|
25
|
+
ctor.super_ = superCtor;
|
|
26
|
+
Object.defineProperty(ctor, 'prototype', {
|
|
27
|
+
value: Object.create(superCtor.prototype, {
|
|
28
|
+
constructor: {
|
|
29
|
+
value: ctor,
|
|
30
|
+
enumerable: false,
|
|
31
|
+
writable: true,
|
|
32
|
+
configurable: true
|
|
33
|
+
}
|
|
34
|
+
})
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
module.exports = {
|
|
39
|
+
isDate: isDate,
|
|
40
|
+
isRegExp: isRegExp,
|
|
41
|
+
isArray: isArray,
|
|
42
|
+
inherits: inherits,
|
|
43
|
+
util: util
|
|
44
|
+
};
|
package/package.json
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@electerm/nedb",
|
|
3
|
-
"version": "
|
|
4
|
-
"author":
|
|
5
|
-
"name": "Louis Chatriot",
|
|
6
|
-
"email": "louis.chatriot@gmail.com"
|
|
7
|
-
},
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"author": "Louis Chatriot <louis.chatriot@gmail.com>",
|
|
8
5
|
"contributors": [
|
|
9
6
|
"Louis Chatriot"
|
|
10
7
|
],
|
|
@@ -14,29 +11,37 @@
|
|
|
14
11
|
"datastore",
|
|
15
12
|
"embedded"
|
|
16
13
|
],
|
|
17
|
-
"homepage": "https://github.com/
|
|
14
|
+
"homepage": "https://github.com/electerm/nedb",
|
|
18
15
|
"repository": {
|
|
19
16
|
"type": "git",
|
|
20
|
-
"url": "git@github.com:
|
|
17
|
+
"url": "git+ssh://git@github.com:electerm/nedb.git"
|
|
21
18
|
},
|
|
22
19
|
"dependencies": {
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"localforage": "*",
|
|
26
|
-
"lodash": "*",
|
|
27
|
-
"mkdirp": "*"
|
|
20
|
+
"@yetzt/binary-search-tree": "^0.2.6",
|
|
21
|
+
"mkdirp": "^1.0.4"
|
|
28
22
|
},
|
|
29
23
|
"devDependencies": {
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"exec-time": "0.0.2",
|
|
33
|
-
"mocha": "1.4.x",
|
|
34
|
-
"request": "2.9.x",
|
|
35
|
-
"sinon": "1.3.x"
|
|
24
|
+
"async": "^3.2.0",
|
|
25
|
+
"jest": "^29.7.0"
|
|
36
26
|
},
|
|
37
27
|
"scripts": {
|
|
38
|
-
"test": "
|
|
28
|
+
"test": "jest --testTimeout=60000 --runInBand",
|
|
29
|
+
"test:parallel": "jest --testTimeout=30000",
|
|
30
|
+
"pub": "npm publish --access public"
|
|
39
31
|
},
|
|
32
|
+
"files": [
|
|
33
|
+
"lib/",
|
|
34
|
+
"index.js",
|
|
35
|
+
"LICENSE",
|
|
36
|
+
"README.md"
|
|
37
|
+
],
|
|
40
38
|
"main": "index",
|
|
41
|
-
"license": "
|
|
39
|
+
"license": "MIT",
|
|
40
|
+
"bugs": {
|
|
41
|
+
"url": "https://github.com/electerm/nedb/issues"
|
|
42
|
+
},
|
|
43
|
+
"directories": {
|
|
44
|
+
"lib": "lib",
|
|
45
|
+
"test": "test"
|
|
46
|
+
}
|
|
42
47
|
}
|