mikolalysenko / mudb

Low latency state replication for the web
MIT License
168 stars 10 forks source link

RDA map constrain #223

Open hediyi opened 4 years ago

hediyi commented 4 years ago

Goal

Guarding state integrity from arbitrary actions. Known use cases:

Cover these cases first and add more constraints later.

API

constructor (keySchema, valueRDA, constrain?)
constrain {
    set?:boolean | (k, v) => boolean
    remove?:boolean | (k) => boolean
    move?:boolean | (f, t) => boolean
}

Considerations

should we impose constraints exactly as specified?

An action may be replaced by a combination of other actions:

Probably should keep it simple. These are not technically equivalent though, maybe overthinking.

should we impose constraints in action() or apply()?

Imposing constraints in action() seems easier to do, but apply() may be the way to go because action objects may not be constructed by action(). Experiment with and test both.

if we impose constraints in apply(), will the inverses be valid?

Test the following cases,

probably should return false from apply() if action is not allowed

User may use return to decide whether to sync with other stores.

hediyi commented 4 years ago

API update

constructor (keySchema, valueRDA, constrain?)
constrain {
    set?:boolean | (k, v) => boolean
    remove?:boolean | (k) => boolean
    move?:boolean | (f, t) => boolean
    maxKeyLength?:number
}