function S4(){return(0|65536*(1+Math.random())).toString(16).substring(1)}function guid(){return S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4()}function Sync(e,t,r){var n=t.config.adapter.collection_name?t.config.adapter.collection_name:"default",o=new RegExp("^("+n+")\\-(.+)$"),i=null;if("read"===e)if(r.parse){var u=[];_.each(TAP.listProperties(),function(e){var t=e.match(o);null!==t&&u.push(TAP.getObject(e))}),i=u}else{var c=TAP.getObject(n+"-"+t.id);t.set(c),i=t.toJSON()}else"create"===e||"update"===e?(t.id||(t.id=guid(),t.set(t.idAttribute,t.id)),TAP.setObject(n+"-"+t.id,t.toJSON()||{}),i=t.toJSON()):"delete"===e&&(TAP.removeProperty(n+"-"+t.id),t.clear(),i=t.toJSON());i?(_.isFunction(r.success)&&r.success(i),"read"===e&&t.trigger("fetch")):_.isFunction(r.error)&&r.error(i)}var Alloy=require("alloy"),_=require("alloy/underscore")._,TAP=Ti.App.Properties;module.exports.sync=Sync,module.exports.beforeModelCreate=function(e){return e=e||{},e.columns=e.columns||{},e.defaults=e.defaults||{},("undefined"==typeof e.columns.id||null===e.columns.id)&&(e.columns.id="String"),e};