client icon indicating copy to clipboard operation
client copied to clipboard

`IndexedStore` — `meta.added` property

Open nichoth opened this issue 4 months ago • 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.

nichoth avatar Mar 04 '24 23:03 nichoth

I created a test that demonstrates my expectation:

https://github.com/nichoth/logux-client/blob/added/client/index.test.ts#L413

nichoth avatar Mar 04 '24 23:03 nichoth

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 }
    }
  }

ai avatar Mar 05 '24 22:03 ai

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.

nichoth avatar Mar 06 '24 04:03 nichoth

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 avatar Mar 06 '24 14:03 ai

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

ai avatar Mar 07 '24 00:03 ai