arso-project / sonar

A p2p content database and search engine
https://sonar.arso.xyz/
GNU General Public License v3.0
123 stars 6 forks source link

[next] Adapt for core API changes everywhere #71

Closed Frando closed 3 years ago

Frando commented 3 years ago

Most of the core tests have to be changed to async/await and adapted for API changes in the next branch.

API changes

Most methods changed from callbacks to async/await. API changes can best be seen by looking what core/lib/compat.js does.

Workspace

Collection

What needs to be done

Examples from core/test/basic.js:

old:

tape('open close', t => {
  createStore({ network: false }, (err, workspace, cleanup) => {
    if (err) t.fail(err)
    t.true(workspace.opened, 'opened property is set')
    t.error(err)
    cleanup(err => {
      t.error(err)
      t.end()
    })
  })
})

tape('put and get 1', t => {
  createStore({ network: false }, (err, workspace, cleanup) => {
    t.error(err, 'tempdir ok')
    workspace.create('default', (err, collection) => {
      t.error(err)
      collection.putType({ name: 'doc', fields: { title: { type: 'string' } } }, err => {
        t.error(err)
        collection.put({ type: 'doc', value: { title: 'hello' } }, (err, record) => {
          t.error(err)
          const id = record.id
          collection.query('records', { id }, { waitForSync: true }, (err, records) => {
            t.error(err)
            t.equal(records.length, 1)
            t.equal(records[0].value.title, 'hello')
            cleanup(() => t.end())
          })
        })
      })
    })
  })
})

new:

tape('open close new', async t => {
  const { cleanup, workspace } = await createOne()
  t.true(workspace.opened, 'opened property is set')
  await cleanup()
})

tape('put and get 1', async t => {
  const { cleanup, workspace } = await createOne()
  const collection = await workspace.openCollection('default')
  await collection.putType({ name: 'doc', fields: { title: { type: 'string' } } })
  const record = await collection.put({ type: 'doc', value: { title: 'hello' } })
  t.equal(record.value.title, 'hello')
  const id = record.id
  const records = await collection.query('records', { id }, { sync: true })
  t.equal(records.length, 1)
  t.equal(records[0].value.title, 'hello')
  await cleanup()
})
sidasmo commented 3 years ago

done