deepbase-json 3.6.5 → 3.6.6
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 +2 -0
- package/package.json +2 -2
- package/src/JsonDriver.js +39 -0
- package/test/test.js +13 -0
package/README.md
CHANGED
|
@@ -233,6 +233,8 @@ new DeepBase(drivers, options)
|
|
|
233
233
|
- `await db.add(...path, value)` - Add item with auto-generated ID
|
|
234
234
|
- `await db.upd(...path, fn)` - Update value with function
|
|
235
235
|
- `await db.keys(...path)` - Get keys at path
|
|
236
|
+
- `await db.first(...path)` - Get first key at path (same order as `keys()`)
|
|
237
|
+
- `await db.last(...path)` - Get last key at path (same order as `keys()`)
|
|
236
238
|
- `await db.values(...path)` - Get values at path
|
|
237
239
|
- `await db.entries(...path)` - Get entries at path
|
|
238
240
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "deepbase-json",
|
|
3
|
-
"version": "3.6.
|
|
3
|
+
"version": "3.6.6",
|
|
4
4
|
"description": "⚡ DeepBase JSON - filesystem driver",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/index.cjs",
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"steno": "^0.4.4"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"deepbase": "^3.6.
|
|
21
|
+
"deepbase": "^3.6.6"
|
|
22
22
|
},
|
|
23
23
|
"scripts": {
|
|
24
24
|
"test": "mocha test/test.js"
|
package/src/JsonDriver.js
CHANGED
|
@@ -148,6 +148,45 @@ export class JsonDriver extends DeepBaseDriver {
|
|
|
148
148
|
return args;
|
|
149
149
|
});
|
|
150
150
|
}
|
|
151
|
+
|
|
152
|
+
async first(...args) {
|
|
153
|
+
if (this.multiProcess) {
|
|
154
|
+
this._refreshFromDisk();
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const value = this._getRecursive(this.obj, args.slice());
|
|
158
|
+
if (value === null || typeof value !== 'object') {
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
for (const key in value) {
|
|
163
|
+
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
164
|
+
return key;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return undefined;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
async last(...args) {
|
|
172
|
+
if (this.multiProcess) {
|
|
173
|
+
this._refreshFromDisk();
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const value = this._getRecursive(this.obj, args.slice());
|
|
177
|
+
if (value === null || typeof value !== 'object') {
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
let last;
|
|
182
|
+
for (const key in value) {
|
|
183
|
+
if (Object.prototype.hasOwnProperty.call(value, key)) {
|
|
184
|
+
last = key;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
return last;
|
|
189
|
+
}
|
|
151
190
|
|
|
152
191
|
// Internal set without queuing (for use within queued operations)
|
|
153
192
|
async _setInternal(...args) {
|
package/test/test.js
CHANGED
|
@@ -248,6 +248,19 @@ describe('JsonDriver', function() {
|
|
|
248
248
|
assert.ok(entries.some(([k, v]) => k === 'alice' && v.age === 30));
|
|
249
249
|
assert.ok(entries.some(([k, v]) => k === 'bob' && v.age === 25));
|
|
250
250
|
});
|
|
251
|
+
|
|
252
|
+
it('first/last should match keys() boundaries', async function() {
|
|
253
|
+
const keys = await db.keys('users');
|
|
254
|
+
const driver = db.getDriver(0);
|
|
255
|
+
assert.strictEqual(await driver.first('users'), keys[0]);
|
|
256
|
+
assert.strictEqual(await driver.last('users'), keys[keys.length - 1]);
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
it('first/last should return undefined for missing path', async function() {
|
|
260
|
+
const driver = db.getDriver(0);
|
|
261
|
+
assert.strictEqual(await driver.first('missing'), undefined);
|
|
262
|
+
assert.strictEqual(await driver.last('missing'), undefined);
|
|
263
|
+
});
|
|
251
264
|
});
|
|
252
265
|
|
|
253
266
|
describe('Persistence', function() {
|