I've been writing a sync function for an app today, and feeling that it's still too much work — there's a lot of boilerplate for common requirements like immutable properties. This sort of situation always gets me thinking of ways to simplify the task at hand.
So I'm brainstorming potential new helper functions that could be called from a sync function. These wouldn't add new capabilities, just make it easier to do typical things. But the acid test is whether they'd make the task seem simpler instead of more complex. required(prop, …) Takes one or more string arguments, each interpreted as a property name. If any of those properties is not present in 'doc', throws an exception. immutable(prop, …) Also takes one or more property names. If 'oldDoc' exists, and any of those properties is present in 'oldDoc' but has a different value in 'doc', throws an exception. schema(???) I'd like to have a function that can validate the types of properties — e.g. "age" has to be a number and "phone" has to be an array of strings — but whenever I start thinking of a simple way to specify that, it keeps expanding until it threatens to turn into JSON-Schema <http://json-schema.org/>. (Maybe that's not a bad thing; but JSON-Schema is pretty complex.) The simplest thing I can think of is to have the function take a JS object whose keys are the doc properties to be validated, and whose values are of the type that's required. So for example, schema({age: 0, phone: [""]}) would enforce the example schema above. I really like this, except it has obvious limitations, and once you start trying to get around those it loses its simplicity. What do you think? —Jens -- You received this message because you are subscribed to the Google Groups "Couchbase Mobile" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/mobile-couchbase/ECA09F80-ACC8-4AED-AAFE-1A57981BBE51%40couchbase.com. For more options, visit https://groups.google.com/d/optout.
