fix: 同步应用循环数组解构错误(.for is not iterable)
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -0,0 +1,48 @@
|
||||
import 'fake-indexeddb/auto'
|
||||
import { bindDatabase, WorklogDB } from '../src/db/schema'
|
||||
|
||||
async function main() {
|
||||
bindDatabase(new WorklogDB('repro_db'))
|
||||
const mod = await import('../src/db/schema')
|
||||
const db = mod.db
|
||||
|
||||
await db.project.bulkAdd([{ name: 'P1', archived: 0, created_at: '2025-01-01T00:00:00' }])
|
||||
await db.work_log.bulkAdd([{ date: '2025-01-02', created_at: '2025-01-02T00:00:00' }])
|
||||
await db.setting.bulkAdd([
|
||||
{ key: 'work_start', value: '09:00' },
|
||||
{ key: 'sync_base_url', value: 'http://127.0.0.1:3780' }
|
||||
])
|
||||
await db.attendance.bulkAdd([{ date: '2025-01-02', clock_in_at: '2025-01-02T09:00:00', clock_out_at: '2025-01-02T18:00:00', kind: 'normal', note: null, created_at: '2025-01-02T09:00:00' }])
|
||||
await db.table('transaction').bulkAdd([{ type: 'expense', category: '餐饮', amount: 2500, date: '2025-01-02', note: 'lunch', reimbursable: 1, reimbursed: 0, created_at: '2025-01-02T12:00:00' }])
|
||||
|
||||
const engine = await import('../src/sync/engine')
|
||||
engine.enableRealtimeSync()
|
||||
|
||||
await fetch('http://127.0.0.1:3780/api/auth/register', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ username: 'rt', password: 'rt123456' })
|
||||
}).catch(() => { /* 已注册则忽略 */ })
|
||||
|
||||
const r1 = await engine.runSync({ baseUrl: 'http://127.0.0.1:3780', username: 'rt', password: 'rt123456' })
|
||||
console.log('SYNC1 OK:', JSON.stringify(r1))
|
||||
|
||||
// 触发本地变更,走实时推送路径
|
||||
await db.table('log_item').add({
|
||||
work_log_id: 1, content: '实时测试条目', project_id: null, category: 'dev',
|
||||
minutes: null, is_milestone: 0, needs_followup: 0, takeaway: null,
|
||||
remark: null, sort_order: 0, created_at: '2025-01-02T10:00:00'
|
||||
})
|
||||
await new Promise(r => setTimeout(r, 4500))
|
||||
console.log('REALTIME PATH DONE')
|
||||
|
||||
// 二次同步幂等验证
|
||||
const r2 = await engine.runSync({ baseUrl: 'http://127.0.0.1:3780', username: 'rt', password: 'rt123456' })
|
||||
console.log('SYNC2 OK:', JSON.stringify(r2))
|
||||
process.exit(0)
|
||||
}
|
||||
|
||||
main().catch(e => {
|
||||
console.error('FAILED:', (e && (e.stack || e.message)) || e)
|
||||
process.exit(1)
|
||||
})
|
||||
Reference in New Issue
Block a user