Skip to content

Support abstract-level v3 APIs#3

Open
germanoeich wants to merge 4 commits into
ForgeVTT:mainfrom
germanoeich:v3
Open

Support abstract-level v3 APIs#3
germanoeich wants to merge 4 commits into
ForgeVTT:mainfrom
germanoeich:v3

Conversation

@germanoeich

Copy link
Copy Markdown

Summary

Adds the abstract-level v3 API surface needed by rave-level / Foundry:

  • updates the test suite for abstract-level v3 behavior
  • adds RPC support for has() and hasMany()
  • adds explicit snapshot support over RPC
  • wires snapshots through get, getMany, has, hasMany, iterators, keys, values, and clear
  • ensures retry mode correctly reports snapshots as unsupported
  • adds opt-in getSync support:
    • forwarded/local DBs call the underlying _getSync()
    • remote users can provide a custom sync handler
    • plain remote guests still reject with LEVEL_NOT_SUPPORTED

Notes

getSync is intentionally not implemented as a generic async RPC wait inside many-level. Blocking the event loop while waiting on the same async stream can deadlock. many-level now exposes the minimal hook needed for consumers like rave-level to provide their own sync transport strategy.

Related PR: ForgeVTT/rave-level#5

@oneirocosm

Copy link
Copy Markdown

I'm a little confused by line 39 of the guest.js file

    const hasGetSync = getSync === true || typeof getSync === 'function'

this implies that getSync can be passed as a boolean, but later in the file, get sync is set with this

    this[kGetSync] = typeof getSync === 'function' ? getSync : null

To me, this implies that if getSync is passed in as true, the function itself will remain null. I imagine there could be a reason for this if the class was extended, but I want to double check instead of just speculating.

@germanoeich

Copy link
Copy Markdown
Author

@oneirocosm good catch, that's the cursed nature of having a local leader and remote follower distinction in the same process.

getSync: true is an opt-in for the local DB path (leader). In that case _getSync() first checks this[kDb] and delegates to the underlying database’s _getSync(), so there is no custom handler to store in kGetSync.

getSync: function is the remote/custom-handler path (follower). That is what consumers like rave-level use when a follower needs to provide its own synchronous transport strategy.

So yes, if getSync is passed as true, this[kGetSync] remains null. Support is advertised for the forwarded DB case, not because there is a standalone remote sync handler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants