Skip to content

Migrate driver-fs, driver-localstorage, and driver-excel to v4.0.0#171

Merged
xuyushun441-sys merged 5 commits intomainfrom
copilot/migrate-driver-fs-code
Jan 23, 2026
Merged

Migrate driver-fs, driver-localstorage, and driver-excel to v4.0.0#171
xuyushun441-sys merged 5 commits intomainfrom
copilot/migrate-driver-fs-code

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Jan 23, 2026

Migrates three drivers to DriverInterface v4.0 spec, bringing ecosystem compliance to 87.5% (7/8 drivers). Each driver now supports QueryAST-based queries and unified command execution while maintaining full backward compatibility.

Changes

@objectql/driver-fs

  • Added executeQuery(ast: QueryAST) and executeCommand(command: Command) methods
  • Implements FilterNode → legacy filter conversion via convertFilterNodeToLegacy()
  • Version: 3.0.1 → 4.0.0
  • Dependency: Added @objectstack/spec ^0.2.0
  • Tests: +11 new tests (47 total, all passing)

@objectql/driver-localstorage

  • Added executeQuery(ast: QueryAST) and executeCommand(command: Command) methods
  • Implements FilterNode → legacy filter conversion via convertFilterNodeToLegacy()
  • Version: 3.0.1 → 4.0.0
  • Dependency: Added @objectstack/spec ^0.2.0
  • Tests: +10 new tests (41 total, all passing)

@objectql/driver-excel

  • Added executeQuery(ast: QueryAST) and executeCommand(command: Command) methods
  • Implements FilterNode → legacy filter conversion via convertFilterNodeToLegacy()
  • Version: 3.0.1 → 4.0.0
  • Dependency: Added @objectstack/spec ^0.2.0
  • Tests: +10 new tests (49 total, all passing)

Documentation

  • Updated DRIVER_COMPLIANCE_MATRIX.md to reflect 87.5% compliance
  • Marked fs, localstorage, and excel as fully compliant

Usage

// New QueryAST interface
const result = await driver.executeQuery({
  object: 'users',
  filters: {
    type: 'comparison',
    field: 'age',
    operator: '>',
    value: 25
  },
  sort: [{ field: 'name', order: 'asc' }],
  top: 10,
  skip: 0
});

// Unified command interface
const result = await driver.executeCommand({
  type: 'bulkCreate',
  object: 'users',
  records: [
    { name: 'Alice', age: 30 },
    { name: 'Bob', age: 25 }
  ]
});

Implementation Pattern

Each driver follows the established migration pattern:

  • executeQuery() converts QueryAST to legacy query format, delegates to existing find()
  • executeCommand() provides unified interface for create/update/delete/bulk operations
  • convertFilterNodeToLegacy() handles AND/OR/comparison node conversion
  • execute() throws descriptive error directing to executeCommand()

Impact

  • 137 tests passing across all three drivers (100% pass rate)
  • Zero breaking changes to existing APIs
  • Drivers support both legacy Driver and new DriverInterface
  • Only driver-redis remains for full ecosystem compliance
Original prompt

🎯 优先级 3: driver-fs 迁移

估计时间: 4-5 小时
复杂度: 中 (文件系统操作)
依赖: 无

任务清单

3.1 代码迁移 (2.5-3 小时)

更新 package.json (15分钟)

版本: 3.0.1 → 4.0.0
添加 @objectstack/spec
文件: packages/drivers/fs/package.json
实现 executeQuery() (1-1.5小时)

读取对象目录下所有 JSON 文件
解析 JSON 到对象数组
内存中应用过滤器
内存中排序
应用 limit/offset
错误处理 (文件不存在, 无效 JSON)
实现 executeCommand() (1-1.5小时)

create → writeFile {object}/{id}.json
update → readFile + modify + writeFile
delete → unlink file
bulkCreate → Promise.all writeFile
bulkUpdate → Promise.all update
bulkDelete → Promise.all unlink
处理并发文件访问
添加辅助方法 (30分钟)

getObjectDir() - 获取对象目录路径
getFilePath() - 生成文件路径
ensureDir() - 确保目录存在
3.2 测试 (1-1.5 小时)

executeQuery 测试
executeCommand 测试
文件系统错误处理
并发操作测试
3.3 文档 (30分钟)

JSDoc
合规矩阵更新
交付物

packages/drivers/fs/src/index.ts (~180 LOC)
packages/drivers/fs/package.json
测试更新
🎯 优先级 4: driver-localstorage 迁移

估计时间: 3-4 小时
复杂度: 低 (浏览器 API 包装)
依赖: 无

任务清单

4.1 代码迁移 (2-2.5 小时)

更新 package.json (15分钟)

版本: 3.0.1 → 4.0.0
添加 @objectstack/spec
文件: packages/drivers/localstorage/package.json
实现 executeQuery() (1小时)

遍历 localStorage keys
过滤匹配对象前缀的键
解析 JSON 值
内存中过滤和排序
应用 limit/offset
实现 executeCommand() (1小时)

create → localStorage.setItem
update → getItem + modify + setItem
delete → removeItem
Bulk 操作: 循环调用
处理 quota 超限错误
添加辅助 (15分钟)

generateKey() - 键生成
同步 API 包装为 Promise
4.2 测试 (1小时)

浏览器环境模拟测试
localStorage mock
Quota 限制测试
4.3 文档 (30分钟)

JSDoc
浏览器兼容性说明
合规矩阵
交付物

packages/drivers/localstorage/src/index.ts (~150 LOC)
packages/drivers/localstorage/package.json
测试更新
🎯 优先级 5: driver-excel 迁移

估计时间: 5-6 小时
复杂度: 中高 (Excel 格式复杂性)
依赖: 无

任务清单

5.1 代码迁移 (3-4 小时)

更新 package.json (15分钟)

版本: 3.0.1 → 4.0.0
添加 @objectstack/spec
文件: packages/drivers/excel/package.json
实现 executeQuery() (1.5-2小时)

加载 workbook
获取对应 worksheet
将行转换为对象 (第一行为表头)
内存中过滤和排序
应用 limit/offset
处理多种数据类型 (日期, 数字, 公式)
实现 executeCommand() (1.5-2小时)

create → addRow
update → 查找行 + 修改 + 保存
delete → 删除行 + 保存
bulkCreate → 批量 addRow
bulkUpdate → 批量修改
bulkDelete → 批量删除
workbook.xlsx.writeFile 保存
添加辅助 (30分钟)

rowToObject() - Excel 行 → 对象
objectToRow() - 对象 → Excel 行
getColumnMapping() - 列名映射
handleCellValue() - 类型转换
5.2 测试 (1.5-2 小时)

Excel 文件读写
数据类型转换
多 worksheet 操作
公式处理
5.3 文档 (30分钟)

JSDoc
Excel 格式限制说明
合规矩阵
交付物

packages/drivers/excel/src/index.ts (~220 LOC)
packages/drivers/excel/package.json
测试更新


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@vercel
Copy link
Copy Markdown

vercel Bot commented Jan 23, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
objectql-site Ready Ready Preview, Comment Jan 23, 2026 10:49am

Request Review

Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
test('should execute bulkDelete command', async () => {
const user1 = await driver.create('users', { name: 'Alice' });
const user2 = await driver.create('users', { name: 'Bob' });
const user3 = await driver.create('users', { name: 'Charlie' });
Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
it('should execute bulkDelete command', async () => {
const user1 = await driver.create('users', { name: 'Alice' });
const user2 = await driver.create('users', { name: 'Bob' });
const user3 = await driver.create('users', { name: 'Charlie' });
Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
Co-authored-by: xuyushun441-sys <255036401+xuyushun441-sys@users.noreply.github.com>
it('should execute bulkDelete command', async () => {
const user1 = await driver.create(TEST_OBJECT, { name: 'Alice' });
const user2 = await driver.create(TEST_OBJECT, { name: 'Bob' });
const user3 = await driver.create(TEST_OBJECT, { name: 'Charlie' });
@github-actions
Copy link
Copy Markdown
Contributor

⚠️ No Changeset Found

This PR does not include a changeset file.
If this PR includes user-facing changes, please add a changeset by running:

pnpm changeset

@xuyushun441-sys xuyushun441-sys marked this pull request as ready for review January 23, 2026 10:54
Copilot AI changed the title [WIP] Migrate driver-fs implementation to version 4.0.0 Migrate driver-fs, driver-localstorage, and driver-excel to v4.0.0 Jan 23, 2026
Copilot AI requested a review from xuyushun441-sys January 23, 2026 10:54
@xuyushun441-sys
Copy link
Copy Markdown
Contributor

@copilot Fix ci test and test again

@xuyushun441-sys xuyushun441-sys merged commit 9fffdd2 into main Jan 23, 2026
4 checks passed
@xuyushun441-sys xuyushun441-sys deleted the copilot/migrate-driver-fs-code branch January 23, 2026 11:01
Copilot stopped work on behalf of xuyushun441-sys due to an error January 23, 2026 11:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants