server/wraputil.js
function makeStateValidator(type){
	if(type.type === 'set' || type.type === 'list'){
		return function(s){
			_.assertArray(s)
			return s
		}
	}else if(type.type === 'map'){
		return function(m){
			if(m === undefined) return {}
			_.assertObject(m)
			return m
		}
	}else if(type.type === 'primitive'){
		return function(v){
			_.assertPrimitive(v)
			return v
		}
	}else if(type.type === 'object'){
		return function(id){
			_.assertNot(_.isArray(id))
			return id
		}
	}else if(type.type === 'view'){
		return function(id){
			_.assertNot(_.isArray(id))
			if(id !== undefined) _.assertString(id)
			return id
		}
	}else if(type.type === 'nil'){
		return function(n){
			return n
		}
	}else{
		_.errout('TODO: ' + JSON.stringify(type))
	}
}
function makeStateValidator(type){
	if(type.type === 'set' || type.type === 'list'){
		return function(s){
			_.assertArray(s)
			return s
		}
	}else if(type.type === 'map'){
		return function(m){
			if(m === undefined) return {}
			_.assertObject(m)
			return m
		}
	}else if(type.type === 'primitive'){
		return function(v){
			_.assertPrimitive(v)
			return v
		}
	}else if(type.type === 'object'){
		return function(id){
			_.assertNot(_.isArray(id))
			return id
		}
	}else if(type.type === 'view'){
		return function(id){
			_.assertNot(_.isArray(id))
			if(id !== undefined) _.assertString(id)
			return id
		}
	}else if(type.type === 'nil'){
		return function(n){
			return n
		}
	}else{
		_.errout('TODO: ' + JSON.stringify(type))
	}
}
/*
function makeChangeConverter(type){
_.errout('TODO REMOVE')
if(type.type === 'set' || type.type === 'list'){
return function(state){
var changes = []
_.assertDefined(state)
_.assertArray(state)

state.forEach(function(v){
changes.push({type: 'add', value: v})
})
return changes
}
}else if(type.type === 'map'){
return function(edits){
_.errout('TODO')
}
}else if(type.type === 'primitive' || type.type === 'object' || type.type === 'view'){
return function(state){
if(_.isArray(state)) _.errout('bad convert')
if(state !== undefined){
return [{type: 'set', value: state}]
}else{
return []
}
}
}else if(type.type === 'nil'){
return function(state){
_.errout('TODO?')
}
}

_.errout('tODO: ' + JSON.stringify(type))
}