ueberdb2 1.4.17 → 2.0.2

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/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # Notable Changes
2
2
 
3
+ ## v2.0.0
4
+
5
+ * When saving an object that has a `.toJSON()` method, the value returned from
6
+ that method is saved to the database instead of the object itself. This
7
+ matches [the behavior of
8
+ `JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify#tojson_behavior).
9
+ The `.toJSON()` method is used even if the chosen database driver never
10
+ actually converts anything to JSON.
11
+ * New `memory` database driver that stores values in memory only.
12
+
13
+ ## v1.4.19
14
+
15
+ Updated database (and other) dependencies:
16
+ * `mongodb`: Updated `mongodb` to 3.7.3.
17
+ * `mssql`: Updated `mssql` to 7.3.0.
18
+ * `dirty_git`: Updated `simple-git` to 2.47.0.
19
+
3
20
  ## v1.4.16
4
21
 
5
22
  * `postgres`: You can now provide a connection string instead of a settings
package/README.md CHANGED
@@ -18,6 +18,7 @@ writes are done in a bulk. This can be turned off.
18
18
  * Dirty
19
19
  * Elasticsearch
20
20
  * Maria
21
+ * `memory`: An in-memory ephemeral database.
21
22
  * Mongo
22
23
  * MsSQL
23
24
  * MySQL
@@ -0,0 +1,41 @@
1
+ 'use strict';
2
+
3
+ const AbstractDatabase = require('../lib/AbstractDatabase');
4
+
5
+ exports.Database = class extends AbstractDatabase {
6
+ constructor(settings) {
7
+ super();
8
+ this.settings = settings;
9
+ settings.json = false;
10
+ settings.cache = 0;
11
+ settings.writeInterval = 0;
12
+ this._data = null;
13
+ }
14
+
15
+ get isAsync() { return true; }
16
+
17
+ close() {
18
+ this._data = null;
19
+ }
20
+
21
+ findKeys(key, notKey) {
22
+ const regex = this.createFindRegex(key, notKey);
23
+ return [...this._data.keys()].filter((k) => regex.test(k));
24
+ }
25
+
26
+ get(key) {
27
+ return this._data.get(key);
28
+ }
29
+
30
+ init() {
31
+ this._data = new Map();
32
+ }
33
+
34
+ remove(key) {
35
+ this._data.delete(key);
36
+ }
37
+
38
+ set(key, value) {
39
+ this._data.set(key, value);
40
+ }
41
+ };
package/index.js CHANGED
@@ -153,10 +153,12 @@ exports.Database = class {
153
153
  }
154
154
  };
155
155
 
156
- const clone = (obj) => {
156
+ const clone = (obj, key = '') => {
157
157
  // Handle the 3 simple types, and null or undefined
158
158
  if (null == obj || 'object' !== typeof obj) return obj;
159
159
 
160
+ if (typeof obj.toJSON === 'function') return clone(obj.toJSON(key));
161
+
160
162
  // Handle Date
161
163
  if (obj instanceof Date) {
162
164
  const copy = new Date();
@@ -168,7 +170,7 @@ const clone = (obj) => {
168
170
  if (obj instanceof Array) {
169
171
  const copy = [];
170
172
  for (let i = 0, len = obj.length; i < len; ++i) {
171
- copy[i] = clone(obj[i]);
173
+ copy[i] = clone(obj[i], String(i));
172
174
  }
173
175
  return copy;
174
176
  }
@@ -177,7 +179,7 @@ const clone = (obj) => {
177
179
  if (obj instanceof Object) {
178
180
  const copy = {};
179
181
  for (const attr in obj) {
180
- if (Object.prototype.hasOwnProperty.call(obj, attr)) copy[attr] = clone(obj[attr]);
182
+ if (Object.prototype.hasOwnProperty.call(obj, attr)) copy[attr] = clone(obj[attr], attr);
181
183
  }
182
184
  return copy;
183
185
  }
package/package.json CHANGED
@@ -21,34 +21,34 @@
21
21
  }
22
22
  ],
23
23
  "dependencies": {
24
- "async": "^3.2.1",
24
+ "async": "^3.2.2",
25
25
  "cassandra-driver": "^4.6.3",
26
26
  "dirty": "^1.1.3",
27
- "elasticsearch": "^16.7.1",
28
- "mongodb": "^3.6.11",
29
- "mssql": "^7.2.1",
27
+ "elasticsearch": "^16.7.2",
28
+ "mongodb": "^3.7.3",
29
+ "mssql": "^7.3.0",
30
30
  "mysql": "2.18.1",
31
- "nano": "^9.0.3",
31
+ "nano": "^9.0.5",
32
32
  "pg": "^8.7.1",
33
33
  "redis": "^3.1.2",
34
34
  "rethinkdb": "^2.4.2",
35
- "simple-git": "^2.45.0"
35
+ "simple-git": "^2.47.0"
36
36
  },
37
37
  "optionalDependencies": {
38
- "sqlite3": "^5.0.2"
38
+ "sqlite3": "github:mapbox/node-sqlite3#593c9d498be2510d286349134537e3bf89401c4a"
39
39
  },
40
40
  "devDependencies": {
41
- "cli-table": "^0.3.6",
41
+ "cli-table": "^0.3.8",
42
42
  "eslint": "^7.32.0",
43
- "eslint-config-etherpad": "^2.0.0",
44
- "eslint-plugin-cypress": "^2.11.3",
43
+ "eslint-config-etherpad": "^2.0.2",
44
+ "eslint-plugin-cypress": "^2.12.1",
45
45
  "eslint-plugin-eslint-comments": "^3.2.0",
46
46
  "eslint-plugin-mocha": "^9.0.0",
47
47
  "eslint-plugin-node": "^11.1.0",
48
48
  "eslint-plugin-prefer-arrow": "^1.2.3",
49
- "eslint-plugin-promise": "^5.1.0",
49
+ "eslint-plugin-promise": "^5.1.1",
50
50
  "eslint-plugin-you-dont-need-lodash-underscore": "^6.12.0",
51
- "mocha": "^9.1.1",
51
+ "mocha": "^9.1.3",
52
52
  "randexp": "^0.5.3",
53
53
  "wtfnode": "^0.9.1"
54
54
  },
@@ -57,7 +57,7 @@
57
57
  "url": "https://github.com/ether/ueberDB.git"
58
58
  },
59
59
  "main": "./index",
60
- "version": "1.4.17",
60
+ "version": "2.0.2",
61
61
  "bugs": {
62
62
  "url": "https://github.com/ether/ueberDB/issues"
63
63
  },
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  exports.databases = {
4
+ memory: {},
4
5
  dirty: {
5
6
  filename: '/tmp/ueberdb-test.db',
6
7
  speeds: {
@@ -0,0 +1,40 @@
1
+ 'use strict';
2
+
3
+ const assert = require('assert').strict;
4
+ const ueberdb = require('../index');
5
+ const util = require('util');
6
+
7
+ describe(__filename, function () {
8
+ let db = null;
9
+
10
+ before(async function () {
11
+ const udb = new ueberdb.Database('memory', {}, {});
12
+ db = {};
13
+ for (const fn of ['init', 'close', 'set', 'get']) db[fn] = util.promisify(udb[fn].bind(udb));
14
+ await db.init();
15
+ });
16
+
17
+ after(async function () {
18
+ await db.close();
19
+ });
20
+
21
+ it('no .toJSON method', async function () {
22
+ await db.set('key', {prop: 'value'});
23
+ assert.deepEqual(await db.get('key'), {prop: 'value'});
24
+ });
25
+
26
+ it('direct', async function () {
27
+ await db.set('key', {toJSON: (arg) => `toJSON ${arg}`});
28
+ assert.equal(await db.get('key'), 'toJSON ');
29
+ });
30
+
31
+ it('object property', async function () {
32
+ await db.set('key', {prop: {toJSON: (arg) => `toJSON ${arg}`}});
33
+ assert.deepEqual(await db.get('key'), {prop: 'toJSON prop'});
34
+ });
35
+
36
+ it('array entry', async function () {
37
+ await db.set('key', [{toJSON: (arg) => `toJSON ${arg}`}]);
38
+ assert.deepEqual(await db.get('key'), ['toJSON 0']);
39
+ });
40
+ });