logux/client

`IndexedStore` — `meta.added` property

nichoth opened this issue · 5 comments

I am calling client.log.add in the browser code, and the returned metadata does not have the added field.

const client = new CrossTabClient({
    server: (import.meta.env.DEV ?
        'ws://localhost:8765' :
        'wss://logux.example.com'),
    store: new IndexedStore('try-logux'),
    subprotocol: '1.0.0',
    userId: 'anonymous',  // TODO: We will fill it, in Authentication recipe
    token: '123'  // TODO: We will fill it in Authentication recipe
})

// ...

const inc = increment()
const meta = await client.log.add(inc, { sync: true })  // should add `added` here
debug('the increment meta', meta) // <-- does not have 'added' prop

Looking at the source code, we see that 'added' is added to meta. I'm not sure why I don't see it.

ai commented

Strange.

  1. Can you send PR with this test to https://github.com/logux/core/blob/main/each-store-check/index.js
  2. Could you try this test after you replace this lines https://github.com/logux/client/blob/main/indexed-store/index.js#L55-L56 to
    if (exist) {
      return false
    } else {
      let added = await promisify(store.os('log', 'write').add(entry))
      delete store.adding[entry.created]
-     meta.added = added
-     return meta
+    return { ...meta, added }
    }
  }

I tried changing the file in client/indexed-store as described — https://github.com/nichoth/logux-client/blob/added/indexed-store/index.js#L55 — but still the same test results. Also, on main branch in @logux/core, the tests do not pass for me.

pnpm test
image

But, it looks like there is already a check for 'added' there — https://github.com/logux/core/blob/main/each-store-check/index.js#L132

I'm not sure where it is failing.

ai commented

That test checks that store keep added in storage. My theory that IndexedDB freeze object and add just doesn't return the right object.

ai commented

I will look on next week (too busy because of the conference on this week)