deepbase-json 3.0.6 → 3.1.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "deepbase-json",
3
- "version": "3.0.6",
3
+ "version": "3.1.0",
4
4
  "description": "⚡ DeepBase JSON - filesystem driver",
5
5
  "type": "module",
6
6
  "main": "src/index.cjs",
@@ -15,7 +15,7 @@
15
15
  "steno": "^0.4.4"
16
16
  },
17
17
  "peerDependencies": {
18
- "deepbase": "^3.0.6"
18
+ "deepbase": "^3.1.0"
19
19
  },
20
20
  "scripts": {
21
21
  "test": "mocha test/test.js"
package/src/JsonDriver.js CHANGED
@@ -60,7 +60,8 @@ export class JsonDriver extends DeepBaseDriver {
60
60
  const keys = args.slice(0, -1);
61
61
  const value = args[args.length - 1];
62
62
 
63
- this._setRecursive(this.obj, keys, value);
63
+ // Make a copy to avoid modifying the original array
64
+ this._setRecursive(this.obj, keys.slice(), value);
64
65
  await this._saveToFile();
65
66
  return keys;
66
67
  }
package/test/test.js CHANGED
@@ -68,6 +68,52 @@ describe('JsonDriver', function() {
68
68
  });
69
69
  });
70
70
 
71
+ describe('Keys with Dots', function() {
72
+ it('should handle keys containing dots', async function() {
73
+ const setResult = await db.set('value', 'martin.clasen@gmail.com', 1);
74
+
75
+ assert.strictEqual(setResult.length, 2);
76
+ assert.strictEqual(setResult[0], 'value');
77
+ assert.strictEqual(setResult[1], 'martin.clasen@gmail.com');
78
+
79
+ const getValue = await db.get('value');
80
+ assert.deepStrictEqual(getValue, { 'martin.clasen@gmail.com': 1 });
81
+ });
82
+
83
+ it('should handle keys with multiple dots', async function() {
84
+ await db.set('config', 'api.prod.endpoint', 'https://api.example.com');
85
+ const endpoint = await db.get('config', 'api.prod.endpoint');
86
+ assert.strictEqual(endpoint, 'https://api.example.com');
87
+ });
88
+
89
+ it('should handle nested paths with dots in keys', async function() {
90
+ await db.set('users', 'john.doe@example.com', 'name', 'John Doe');
91
+ await db.set('users', 'john.doe@example.com', 'age', 30);
92
+
93
+ const user = await db.get('users', 'john.doe@example.com');
94
+ assert.deepStrictEqual(user, { name: 'John Doe', age: 30 });
95
+ });
96
+
97
+ it('should handle dots in first level keys', async function() {
98
+ await db.set('config.prod', 'value', 100);
99
+ const configProd = await db.get('config.prod');
100
+ assert.deepStrictEqual(configProd, { value: 100 });
101
+ });
102
+
103
+ it('should distinguish between dots in keys and path separators', async function() {
104
+ // Set a regular nested path
105
+ await db.set('users', 'alice', 'email', 'alice@example.com');
106
+
107
+ // Set a key with dots at the same level
108
+ await db.set('users', 'john.doe@company.com', 'email', 'john@work.com');
109
+
110
+ const users = await db.get('users');
111
+ assert.strictEqual(users.alice.email, 'alice@example.com');
112
+ assert.strictEqual(users['john.doe@company.com'].email, 'john@work.com');
113
+ assert.strictEqual(Object.keys(users).length, 2);
114
+ });
115
+ });
116
+
71
117
  describe('Delete Operations', function() {
72
118
  it('should delete a key', async function() {
73
119
  await db.set('temp', 'value');