Skip to content

Commit e119286

Browse files
Copilothuangyiirene
andcommitted
Fix FileSystem driver tests and verify example works
Co-authored-by: huangyiirene <[email protected]>
1 parent 94cb232 commit e119286

File tree

3 files changed

+80
-291
lines changed

3 files changed

+80
-291
lines changed

packages/drivers/fs/src/index.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,15 @@ export class FileSystemDriver implements Driver {
216216
* Create a new record.
217217
*/
218218
async create(objectName: string, data: any, options?: any): Promise<any> {
219+
// Validate object name
220+
if (!objectName || objectName.trim() === '') {
221+
throw new ObjectQLError({
222+
code: 'INVALID_OBJECT_NAME',
223+
message: 'Object name cannot be empty',
224+
details: { objectName }
225+
});
226+
}
227+
219228
const records = this.loadRecords(objectName);
220229

221230
// Generate ID if not provided
@@ -314,8 +323,10 @@ export class FileSystemDriver implements Driver {
314323
actualFilters = filters.filters;
315324
}
316325

317-
// If no filters, return total count
318-
if (!actualFilters || (Array.isArray(actualFilters) && actualFilters.length === 0)) {
326+
// If no filters or empty object/array, return total count
327+
if (!actualFilters ||
328+
(Array.isArray(actualFilters) && actualFilters.length === 0) ||
329+
(typeof actualFilters === 'object' && !Array.isArray(actualFilters) && Object.keys(actualFilters).length === 0)) {
319330
return records.length;
320331
}
321332

packages/drivers/fs/test/index.test.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ describe('FileSystemDriver', () => {
7272

7373
test('should update a record', async () => {
7474
const created = await driver.create('users', { name: 'David', age: 25 });
75+
76+
// Add small delay to ensure different timestamp
77+
await new Promise(resolve => setTimeout(resolve, 10));
78+
7579
const updated = await driver.update('users', created.id, { age: 26 });
7680

7781
expect(updated.age).toBe(26);

0 commit comments

Comments
 (0)