@dxos/random-access-storage 0.4.0 → 0.4.1-main.2495eb8
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/dist/lib/browser/index.mjs +34 -22
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +4 -1
- package/dist/lib/node/index.cjs.map +2 -2
- package/dist/lib/node/meta.json +1 -1
- package/dist/types/src/browser/bench.browser.test.d.ts +2 -0
- package/dist/types/src/browser/bench.browser.test.d.ts.map +1 -0
- package/dist/types/src/browser/storage.browser.test.d.ts +2 -0
- package/dist/types/src/browser/storage.browser.test.d.ts.map +1 -0
- package/dist/types/src/browser/web-fs.d.ts +1 -1
- package/dist/types/src/browser/web-fs.d.ts.map +1 -1
- package/dist/types/src/common/abstract-storage.d.ts +1 -0
- package/dist/types/src/common/abstract-storage.d.ts.map +1 -1
- package/dist/types/src/common/storage.d.ts +1 -0
- package/dist/types/src/common/storage.d.ts.map +1 -1
- package/dist/types/src/node/bench.node.test.d.ts +2 -0
- package/dist/types/src/node/bench.node.test.d.ts.map +1 -0
- package/dist/types/src/node/storage.node.test.d.ts +2 -0
- package/dist/types/src/node/storage.node.test.d.ts.map +1 -0
- package/dist/types/src/testing/benchmark.blueprint-test.d.ts +1 -1
- package/dist/types/src/testing/benchmark.blueprint-test.d.ts.map +1 -1
- package/dist/types/src/testing/storage.blueprint-test.d.ts +1 -1
- package/dist/types/src/testing/storage.blueprint-test.d.ts.map +1 -1
- package/dist/types/src/testing/wait-for-debugger.d.ts +6 -0
- package/dist/types/src/testing/wait-for-debugger.d.ts.map +1 -0
- package/package.json +9 -9
- package/src/browser/{bench.test.ts → bench.browser.test.ts} +2 -4
- package/src/browser/{storage.test.ts → storage.browser.test.ts} +1 -8
- package/src/browser/web-fs.ts +30 -9
- package/src/common/abstract-storage.ts +4 -0
- package/src/common/storage.ts +1 -0
- package/src/node/{bench.test.ts → bench.node.test.ts} +8 -7
- package/src/node/{storage.test.ts → storage.node.test.ts} +8 -7
- package/src/testing/benchmark.blueprint-test.ts +3 -3
- package/src/testing/storage.blueprint-test.ts +36 -34
- package/src/testing/wait-for-debugger.ts +22 -0
- package/dist/types/src/browser/bench.test.d.ts +0 -2
- package/dist/types/src/browser/bench.test.d.ts.map +0 -1
- package/dist/types/src/browser/storage.test.d.ts +0 -2
- package/dist/types/src/browser/storage.test.d.ts.map +0 -1
- package/dist/types/src/node/bench.test.d.ts +0 -2
- package/dist/types/src/node/bench.test.d.ts.map +0 -1
- package/dist/types/src/node/storage.test.d.ts +0 -2
- package/dist/types/src/node/storage.test.d.ts.map +0 -1
|
@@ -2,15 +2,11 @@
|
|
|
2
2
|
// Copyright 2021 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
import chaiAsPromised from 'chai-as-promised';
|
|
5
|
+
import { expect, describe, test } from 'vitest';
|
|
7
6
|
|
|
8
7
|
import { asyncTimeout } from '@dxos/async';
|
|
9
|
-
import { describe, test } from '@dxos/test';
|
|
10
8
|
|
|
11
|
-
import { type File, type Storage
|
|
12
|
-
|
|
13
|
-
chai.use(chaiAsPromised);
|
|
9
|
+
import { StorageType, type File, type Storage } from '../common';
|
|
14
10
|
|
|
15
11
|
export const randomText = () => Math.random().toString(36).substring(2);
|
|
16
12
|
|
|
@@ -19,7 +15,7 @@ export const storageTests = (testGroupName: StorageType, createStorage: () => St
|
|
|
19
15
|
await file.write(offset, data);
|
|
20
16
|
const bufferRead = await file.read(offset, data.length);
|
|
21
17
|
const result = data.equals(bufferRead);
|
|
22
|
-
expect(result).
|
|
18
|
+
expect(result).toBeTruthy();
|
|
23
19
|
};
|
|
24
20
|
|
|
25
21
|
describe(testGroupName, () => {
|
|
@@ -48,6 +44,8 @@ export const storageTests = (testGroupName: StorageType, createStorage: () => St
|
|
|
48
44
|
});
|
|
49
45
|
|
|
50
46
|
test('list files', async () => {
|
|
47
|
+
// await waitForDebugger();
|
|
48
|
+
|
|
51
49
|
const storage = createStorage();
|
|
52
50
|
const directoryName = randomText();
|
|
53
51
|
const directory = storage.createDirectory(directoryName);
|
|
@@ -63,7 +61,7 @@ export const storageTests = (testGroupName: StorageType, createStorage: () => St
|
|
|
63
61
|
}
|
|
64
62
|
|
|
65
63
|
const entries = await directory.list();
|
|
66
|
-
expect(entries.length).
|
|
64
|
+
expect(entries.length).toEqual(count);
|
|
67
65
|
}
|
|
68
66
|
|
|
69
67
|
{
|
|
@@ -75,7 +73,7 @@ export const storageTests = (testGroupName: StorageType, createStorage: () => St
|
|
|
75
73
|
}
|
|
76
74
|
|
|
77
75
|
const entries = await directory.list();
|
|
78
|
-
expect(entries.length).
|
|
76
|
+
expect(entries.length).toEqual(count - amountToDelete);
|
|
79
77
|
}
|
|
80
78
|
|
|
81
79
|
// Cleanup.
|
|
@@ -92,7 +90,7 @@ export const storageTests = (testGroupName: StorageType, createStorage: () => St
|
|
|
92
90
|
const file = directory.getOrCreateFile(fileName);
|
|
93
91
|
const { size } = await file.stat();
|
|
94
92
|
const data = await file.read(0, size);
|
|
95
|
-
expect(Buffer.from('').
|
|
93
|
+
expect(Buffer.from('')).toEqual(data);
|
|
96
94
|
});
|
|
97
95
|
|
|
98
96
|
test('reopen and check if data is the same', async () => {
|
|
@@ -110,7 +108,7 @@ export const storageTests = (testGroupName: StorageType, createStorage: () => St
|
|
|
110
108
|
{
|
|
111
109
|
const file = directory.getOrCreateFile(fileName);
|
|
112
110
|
const data2 = await file.read(0, data1.length);
|
|
113
|
-
expect(data1.
|
|
111
|
+
expect(data1).toEqual(data2);
|
|
114
112
|
await file.close();
|
|
115
113
|
}
|
|
116
114
|
});
|
|
@@ -134,14 +132,14 @@ export const storageTests = (testGroupName: StorageType, createStorage: () => St
|
|
|
134
132
|
{
|
|
135
133
|
const file = directory.getOrCreateFile(fileName);
|
|
136
134
|
const { size } = await file.stat();
|
|
137
|
-
expect(size).
|
|
135
|
+
expect(size).toBe(0);
|
|
138
136
|
await file.close();
|
|
139
137
|
}
|
|
140
138
|
});
|
|
141
139
|
|
|
142
|
-
test('double destroy file', async
|
|
140
|
+
test('double destroy file', async (t) => {
|
|
143
141
|
if (testGroupName !== StorageType.NODE) {
|
|
144
|
-
|
|
142
|
+
t.skip();
|
|
145
143
|
}
|
|
146
144
|
const fileName = randomText();
|
|
147
145
|
let firstHandle: File;
|
|
@@ -166,7 +164,7 @@ export const storageTests = (testGroupName: StorageType, createStorage: () => St
|
|
|
166
164
|
}
|
|
167
165
|
|
|
168
166
|
await firstHandle.destroy();
|
|
169
|
-
await expect(secondHandle.destroy()).
|
|
167
|
+
await expect(secondHandle.destroy()).rejects.toThrow();
|
|
170
168
|
});
|
|
171
169
|
|
|
172
170
|
test('sub-directories', async () => {
|
|
@@ -188,8 +186,8 @@ export const storageTests = (testGroupName: StorageType, createStorage: () => St
|
|
|
188
186
|
await file2.write(0, buffer2);
|
|
189
187
|
|
|
190
188
|
// 4. Check that they have correct content.
|
|
191
|
-
expect(await file1.read(0, buffer1.length)).
|
|
192
|
-
expect(await file2.read(0, buffer2.length)).
|
|
189
|
+
expect(await file1.read(0, buffer1.length)).toEqual(buffer1);
|
|
190
|
+
expect(await file2.read(0, buffer2.length)).toEqual(buffer2);
|
|
193
191
|
});
|
|
194
192
|
|
|
195
193
|
test('write in directory/sub-directory/file', async () => {
|
|
@@ -202,7 +200,7 @@ export const storageTests = (testGroupName: StorageType, createStorage: () => St
|
|
|
202
200
|
await file.write(0, buffer);
|
|
203
201
|
|
|
204
202
|
const readBuffer = await file.read(0, buffer.length);
|
|
205
|
-
expect(readBuffer).
|
|
203
|
+
expect(readBuffer).toEqual(buffer);
|
|
206
204
|
await file.close();
|
|
207
205
|
});
|
|
208
206
|
|
|
@@ -215,10 +213,14 @@ export const storageTests = (testGroupName: StorageType, createStorage: () => St
|
|
|
215
213
|
await writeAndCheck(file, buffer);
|
|
216
214
|
|
|
217
215
|
await directory.delete();
|
|
218
|
-
await expect(file.read(0, buffer.length)).
|
|
216
|
+
await expect(file.read(0, buffer.length)).rejects.toThrow();
|
|
219
217
|
});
|
|
220
218
|
|
|
221
|
-
test('del method', async () => {
|
|
219
|
+
test('del method', async (t) => {
|
|
220
|
+
// File.del() throws 'Not deletable' error for IDb.
|
|
221
|
+
if (testGroupName !== StorageType.NODE) {
|
|
222
|
+
t.skip();
|
|
223
|
+
}
|
|
222
224
|
const storage = createStorage();
|
|
223
225
|
|
|
224
226
|
const directory = storage.createDirectory();
|
|
@@ -234,14 +236,14 @@ export const storageTests = (testGroupName: StorageType, createStorage: () => St
|
|
|
234
236
|
await file.del(buffer1.length, buffer2.length);
|
|
235
237
|
expect((await file.stat()).size).to.equal(buffer1.length);
|
|
236
238
|
expect(await file.read(0, buffer1.length)).to.deep.equal(buffer1);
|
|
237
|
-
await expect(file.read(buffer1.length, buffer2.length)).
|
|
238
|
-
})
|
|
239
|
+
await expect(file.read(buffer1.length, buffer2.length)).rejects.toThrow('Could not satisfy length');
|
|
240
|
+
});
|
|
239
241
|
|
|
240
242
|
test('stat of new file', async () => {
|
|
241
243
|
const storage = createStorage();
|
|
242
244
|
const directory = storage.createDirectory();
|
|
243
245
|
const file = directory.getOrCreateFile(randomText());
|
|
244
|
-
expect((await file.stat()).size).
|
|
246
|
+
expect((await file.stat()).size).toBe(0);
|
|
245
247
|
});
|
|
246
248
|
|
|
247
249
|
test('call del with edge arguments', async () => {
|
|
@@ -257,21 +259,21 @@ export const storageTests = (testGroupName: StorageType, createStorage: () => St
|
|
|
257
259
|
const file = directory.getOrCreateFile(randomText());
|
|
258
260
|
await file.write(0, buffer);
|
|
259
261
|
await file.del(0, buffer.length + 1);
|
|
260
|
-
expect((await file.stat()).size).
|
|
262
|
+
expect((await file.stat()).size).toBe(0);
|
|
261
263
|
}
|
|
262
264
|
|
|
263
265
|
{
|
|
264
266
|
const file = directory.getOrCreateFile(randomText());
|
|
265
267
|
await file.write(0, buffer);
|
|
266
268
|
await file.del(1, buffer.length);
|
|
267
|
-
expect((await file.stat()).size).
|
|
269
|
+
expect((await file.stat()).size).toBe(1);
|
|
268
270
|
}
|
|
269
271
|
|
|
270
272
|
{
|
|
271
273
|
const file = directory.getOrCreateFile(randomText());
|
|
272
274
|
await file.write(0, buffer);
|
|
273
275
|
await file.del(0, -1);
|
|
274
|
-
expect((await file.stat()).size).
|
|
276
|
+
expect((await file.stat()).size).toBe(buffer.length);
|
|
275
277
|
}
|
|
276
278
|
});
|
|
277
279
|
|
|
@@ -297,7 +299,7 @@ export const storageTests = (testGroupName: StorageType, createStorage: () => St
|
|
|
297
299
|
const storage = createStorage();
|
|
298
300
|
const directory = storage.createDirectory();
|
|
299
301
|
const file = directory.getOrCreateFile(filename);
|
|
300
|
-
expect(
|
|
302
|
+
await expect(file.read(0, buffer.length)).resolves.toEqual(buffer);
|
|
301
303
|
await file.close();
|
|
302
304
|
}
|
|
303
305
|
|
|
@@ -310,13 +312,13 @@ export const storageTests = (testGroupName: StorageType, createStorage: () => St
|
|
|
310
312
|
const storage = createStorage();
|
|
311
313
|
const directory = storage.createDirectory();
|
|
312
314
|
const file = directory.getOrCreateFile(filename);
|
|
313
|
-
await expect(file.read(0, buffer.length)).
|
|
315
|
+
await expect(file.read(0, buffer.length)).rejects.toThrow();
|
|
314
316
|
}
|
|
315
317
|
});
|
|
316
318
|
|
|
317
|
-
test('list all files after reopen', async
|
|
319
|
+
test('list all files after reopen', async (t) => {
|
|
318
320
|
if (testGroupName !== StorageType.WEBFS && testGroupName !== StorageType.NODE) {
|
|
319
|
-
|
|
321
|
+
t.skip();
|
|
320
322
|
}
|
|
321
323
|
|
|
322
324
|
const dirname = randomText();
|
|
@@ -326,7 +328,7 @@ export const storageTests = (testGroupName: StorageType, createStorage: () => St
|
|
|
326
328
|
|
|
327
329
|
{
|
|
328
330
|
const entries = await directory.list();
|
|
329
|
-
expect(entries.length).
|
|
331
|
+
expect(entries.length).toBe(0);
|
|
330
332
|
}
|
|
331
333
|
|
|
332
334
|
const files = [...Array(10)].map(() => directory.getOrCreateFile(randomText()));
|
|
@@ -337,14 +339,14 @@ export const storageTests = (testGroupName: StorageType, createStorage: () => St
|
|
|
337
339
|
|
|
338
340
|
{
|
|
339
341
|
const entries = await directory.list();
|
|
340
|
-
expect(entries.length).
|
|
342
|
+
expect(entries.length).toBe(files.length);
|
|
341
343
|
}
|
|
342
344
|
|
|
343
345
|
{
|
|
344
346
|
const storage = createStorage();
|
|
345
347
|
const directory = storage.createDirectory(dirname);
|
|
346
348
|
const entries = await directory.list();
|
|
347
|
-
expect(entries.length).
|
|
349
|
+
expect(entries.length).toBe(files.length);
|
|
348
350
|
}
|
|
349
351
|
});
|
|
350
352
|
|
|
@@ -360,7 +362,7 @@ export const storageTests = (testGroupName: StorageType, createStorage: () => St
|
|
|
360
362
|
}
|
|
361
363
|
await directory.flush();
|
|
362
364
|
const entries = await directory.list();
|
|
363
|
-
expect(entries).
|
|
365
|
+
expect(entries).toEqual(expect.arrayContaining(FILES));
|
|
364
366
|
});
|
|
365
367
|
});
|
|
366
368
|
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { sleep } from '@dxos/async';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Will wait for the debugger to be attached and stop on the breakpoint.
|
|
9
|
+
* You can then press "step-out" to return to the caller.
|
|
10
|
+
*/
|
|
11
|
+
export const waitForDebugger = async () => {
|
|
12
|
+
while (true) {
|
|
13
|
+
const before = performance.now();
|
|
14
|
+
// eslint-disable-next-line no-debugger
|
|
15
|
+
debugger;
|
|
16
|
+
const after = performance.now();
|
|
17
|
+
if (after - before > 100) {
|
|
18
|
+
break;
|
|
19
|
+
}
|
|
20
|
+
await sleep(100);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bench.test.d.ts","sourceRoot":"","sources":["../../../../src/browser/bench.test.ts"],"names":[],"mappings":"AAMA,OAAO,6BAA6B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"storage.test.d.ts","sourceRoot":"","sources":["../../../../src/browser/storage.test.ts"],"names":[],"mappings":"AAOA,OAAO,6BAA6B,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"bench.test.d.ts","sourceRoot":"","sources":["../../../../src/node/bench.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"storage.test.d.ts","sourceRoot":"","sources":["../../../../src/node/storage.test.ts"],"names":[],"mappings":""}
|