UNPKG

@anysoftinc/anydb-sdk

Version:

AnyDB TypeScript SDK for querying and transacting with Datomic databases

589 lines (524 loc) 24.1 kB
var $CLJS = require("./cljs_env"); var $jscomp = $CLJS.$jscomp; var COMPILED = false; require("./cljs.core.js"); require("./datascript.db.js"); var anydb=$CLJS.anydb || ($CLJS.anydb = {}); var clojure=$CLJS.clojure || ($CLJS.clojure = {}); var cljs=$CLJS.cljs || ($CLJS.cljs = {}); var goog=$CLJS.goog || ($CLJS.goog = {}); var datascript=$CLJS.datascript || ($CLJS.datascript = {}); var me=$CLJS.me || ($CLJS.me = {}); var extend_clj=$CLJS.extend_clj || ($CLJS.extend_clj = {}); $CLJS.SHADOW_ENV.setLoaded("datascript.impl.entity.js"); goog.provide('datascript.impl.entity'); datascript.impl.entity.entid = (function datascript$impl$entity$entid(db,eid){ if(((typeof eid === 'number') || (((cljs.core.sequential_QMARK_(eid)) || ((eid instanceof cljs.core.Keyword)))))){ return datascript.db.entid(db,eid); } else { return null; } }); datascript.impl.entity.entity = (function datascript$impl$entity$entity(db,eid){ if(datascript.db.db_QMARK_(db)){ } else { throw (new Error("Assert failed: (db/db? db)")); } var temp__5804__auto__ = datascript.impl.entity.entid(db,eid); if(cljs.core.truth_(temp__5804__auto__)){ var e = temp__5804__auto__; if(datascript.db.numeric_eid_exists_QMARK_(db,e)){ var G__11514 = db; var G__11515 = e; var G__11516 = cljs.core.volatile_BANG_(false); var G__11517 = cljs.core.volatile_BANG_(cljs.core.PersistentArrayMap.EMPTY); return (datascript.impl.entity.__GT_Entity.cljs$core$IFn$_invoke$arity$4 ? datascript.impl.entity.__GT_Entity.cljs$core$IFn$_invoke$arity$4(G__11514,G__11515,G__11516,G__11517) : datascript.impl.entity.__GT_Entity.call(null,G__11514,G__11515,G__11516,G__11517)); } else { return null; } } else { return null; } }); datascript.impl.entity.entity_attr = (function datascript$impl$entity$entity_attr(db,a,datoms){ if(datascript.db.multival_QMARK_(db,a)){ if(datascript.db.ref_QMARK_(db,a)){ return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3((function (p1__11520_SHARP_,p2__11521_SHARP_){ return cljs.core.conj.cljs$core$IFn$_invoke$arity$2(p1__11520_SHARP_,datascript.impl.entity.entity(db,new cljs.core.Keyword(null,"v","v",21465059).cljs$core$IFn$_invoke$arity$1(p2__11521_SHARP_))); }),cljs.core.PersistentHashSet.EMPTY,datoms); } else { return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3((function (p1__11523_SHARP_,p2__11524_SHARP_){ return cljs.core.conj.cljs$core$IFn$_invoke$arity$2(p1__11523_SHARP_,new cljs.core.Keyword(null,"v","v",21465059).cljs$core$IFn$_invoke$arity$1(p2__11524_SHARP_)); }),cljs.core.PersistentHashSet.EMPTY,datoms); } } else { if(datascript.db.ref_QMARK_(db,a)){ return datascript.impl.entity.entity(db,new cljs.core.Keyword(null,"v","v",21465059).cljs$core$IFn$_invoke$arity$1(cljs.core.first(datoms))); } else { return new cljs.core.Keyword(null,"v","v",21465059).cljs$core$IFn$_invoke$arity$1(cljs.core.first(datoms)); } } }); datascript.impl.entity._lookup_backwards = (function datascript$impl$entity$_lookup_backwards(db,eid,attr,not_found){ var temp__5802__auto__ = cljs.core.not_empty(datascript.db._search(db,new cljs.core.PersistentVector(null, 3, 5, cljs.core.PersistentVector.EMPTY_NODE, [null,attr,eid], null))); if(cljs.core.truth_(temp__5802__auto__)){ var datoms = temp__5802__auto__; if(datascript.db.component_QMARK_(db,attr)){ return datascript.impl.entity.entity(db,new cljs.core.Keyword(null,"e","e",1381269198).cljs$core$IFn$_invoke$arity$1(cljs.core.first(datoms))); } else { return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3((function (p1__11526_SHARP_,p2__11527_SHARP_){ return cljs.core.conj.cljs$core$IFn$_invoke$arity$2(p1__11526_SHARP_,datascript.impl.entity.entity(db,new cljs.core.Keyword(null,"e","e",1381269198).cljs$core$IFn$_invoke$arity$1(p2__11527_SHARP_))); }),cljs.core.PersistentHashSet.EMPTY,datoms); } } else { return not_found; } }); datascript.impl.entity.multival__GT_js = (function datascript$impl$entity$multival__GT_js(val){ if(cljs.core.truth_(val)){ return cljs.core.to_array(val); } else { return null; } }); datascript.impl.entity.js_seq = (function datascript$impl$entity$js_seq(e){ (datascript.impl.entity.touch.cljs$core$IFn$_invoke$arity$1 ? datascript.impl.entity.touch.cljs$core$IFn$_invoke$arity$1(e) : datascript.impl.entity.touch.call(null,e)); var iter__5480__auto__ = (function datascript$impl$entity$js_seq_$_iter__11549(s__11550){ return (new cljs.core.LazySeq(null,(function (){ var s__11550__$1 = s__11550; while(true){ var temp__5804__auto__ = cljs.core.seq(s__11550__$1); if(temp__5804__auto__){ var s__11550__$2 = temp__5804__auto__; if(cljs.core.chunked_seq_QMARK_(s__11550__$2)){ var c__5478__auto__ = cljs.core.chunk_first(s__11550__$2); var size__5479__auto__ = cljs.core.count(c__5478__auto__); var b__11552 = cljs.core.chunk_buffer(size__5479__auto__); if((function (){var i__11551 = (0); while(true){ if((i__11551 < size__5479__auto__)){ var vec__11553 = cljs.core._nth(c__5478__auto__,i__11551); var a = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__11553,(0),null); var v = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__11553,(1),null); cljs.core.chunk_append(b__11552,((datascript.db.multival_QMARK_(e.db,a))?new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [a,datascript.impl.entity.multival__GT_js(v)], null):new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [a,v], null))); var G__11738 = (i__11551 + (1)); i__11551 = G__11738; continue; } else { return true; } break; } })()){ return cljs.core.chunk_cons(cljs.core.chunk(b__11552),datascript$impl$entity$js_seq_$_iter__11549(cljs.core.chunk_rest(s__11550__$2))); } else { return cljs.core.chunk_cons(cljs.core.chunk(b__11552),null); } } else { var vec__11557 = cljs.core.first(s__11550__$2); var a = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__11557,(0),null); var v = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__11557,(1),null); return cljs.core.cons(((datascript.db.multival_QMARK_(e.db,a))?new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [a,datascript.impl.entity.multival__GT_js(v)], null):new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [a,v], null)),datascript$impl$entity$js_seq_$_iter__11549(cljs.core.rest(s__11550__$2))); } } else { return null; } break; } }),null,null)); }); return iter__5480__auto__(cljs.core.deref(e.cache)); }); /** * @constructor * @implements {cljs.core.IEquiv} * @implements {cljs.core.IHash} * @implements {cljs.core.IFn} * @implements {cljs.core.ICounted} * @implements {cljs.core.ISeqable} * @implements {cljs.core.IPrintWithWriter} * @implements {cljs.core.IAssociative} * @implements {cljs.core.ILookup} */ datascript.impl.entity.Entity = (function (db,eid,touched,cache){ this.db = db; this.eid = eid; this.touched = touched; this.cache = cache; this.cljs$lang$protocol_mask$partition0$ = 2162164483; this.cljs$lang$protocol_mask$partition1$ = 0; }); (datascript.impl.entity.Entity.prototype.entry_set = (function (){ var self__ = this; var this$ = this; return cljs.core.to_array(cljs.core.map.cljs$core$IFn$_invoke$arity$2(cljs.core.to_array,datascript.impl.entity.js_seq(this$))); })); (datascript.impl.entity.Entity.prototype.forEach = (function() { var G__11742 = null; var G__11742__1 = (function (f){ var self__ = this; var this$ = this; var seq__11572 = cljs.core.seq(datascript.impl.entity.js_seq(this$)); var chunk__11573 = null; var count__11574 = (0); var i__11575 = (0); while(true){ if((i__11575 < count__11574)){ var vec__11590 = chunk__11573.cljs$core$IIndexed$_nth$arity$2(null,i__11575); var a = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__11590,(0),null); var v = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__11590,(1),null); (f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(v,a,this$) : f.call(null,v,a,this$)); var G__11750 = seq__11572; var G__11751 = chunk__11573; var G__11752 = count__11574; var G__11753 = (i__11575 + (1)); seq__11572 = G__11750; chunk__11573 = G__11751; count__11574 = G__11752; i__11575 = G__11753; continue; } else { var temp__5804__auto__ = cljs.core.seq(seq__11572); if(temp__5804__auto__){ var seq__11572__$1 = temp__5804__auto__; if(cljs.core.chunked_seq_QMARK_(seq__11572__$1)){ var c__5525__auto__ = cljs.core.chunk_first(seq__11572__$1); var G__11754 = cljs.core.chunk_rest(seq__11572__$1); var G__11755 = c__5525__auto__; var G__11756 = cljs.core.count(c__5525__auto__); var G__11757 = (0); seq__11572 = G__11754; chunk__11573 = G__11755; count__11574 = G__11756; i__11575 = G__11757; continue; } else { var vec__11593 = cljs.core.first(seq__11572__$1); var a = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__11593,(0),null); var v = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__11593,(1),null); (f.cljs$core$IFn$_invoke$arity$3 ? f.cljs$core$IFn$_invoke$arity$3(v,a,this$) : f.call(null,v,a,this$)); var G__11766 = cljs.core.next(seq__11572__$1); var G__11767 = null; var G__11768 = (0); var G__11769 = (0); seq__11572 = G__11766; chunk__11573 = G__11767; count__11574 = G__11768; i__11575 = G__11769; continue; } } else { return null; } } break; } }); var G__11742__2 = (function (f,use_as_this){ var self__ = this; var this$ = this; var seq__11596 = cljs.core.seq(datascript.impl.entity.js_seq(this$)); var chunk__11597 = null; var count__11598 = (0); var i__11599 = (0); while(true){ if((i__11599 < count__11598)){ var vec__11610 = chunk__11597.cljs$core$IIndexed$_nth$arity$2(null,i__11599); var a = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__11610,(0),null); var v = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__11610,(1),null); f.call(use_as_this,v,a,this$); var G__11776 = seq__11596; var G__11777 = chunk__11597; var G__11778 = count__11598; var G__11779 = (i__11599 + (1)); seq__11596 = G__11776; chunk__11597 = G__11777; count__11598 = G__11778; i__11599 = G__11779; continue; } else { var temp__5804__auto__ = cljs.core.seq(seq__11596); if(temp__5804__auto__){ var seq__11596__$1 = temp__5804__auto__; if(cljs.core.chunked_seq_QMARK_(seq__11596__$1)){ var c__5525__auto__ = cljs.core.chunk_first(seq__11596__$1); var G__11784 = cljs.core.chunk_rest(seq__11596__$1); var G__11785 = c__5525__auto__; var G__11786 = cljs.core.count(c__5525__auto__); var G__11787 = (0); seq__11596 = G__11784; chunk__11597 = G__11785; count__11598 = G__11786; i__11599 = G__11787; continue; } else { var vec__11614 = cljs.core.first(seq__11596__$1); var a = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__11614,(0),null); var v = cljs.core.nth.cljs$core$IFn$_invoke$arity$3(vec__11614,(1),null); f.call(use_as_this,v,a,this$); var G__11792 = cljs.core.next(seq__11596__$1); var G__11793 = null; var G__11794 = (0); var G__11795 = (0); seq__11596 = G__11792; chunk__11597 = G__11793; count__11598 = G__11794; i__11599 = G__11795; continue; } } else { return null; } } break; } }); G__11742 = function(f,use_as_this){ switch(arguments.length){ case 1: return G__11742__1.call(this,f); case 2: return G__11742__2.call(this,f,use_as_this); } throw(new Error('Invalid arity: ' + arguments.length)); }; G__11742.cljs$core$IFn$_invoke$arity$1 = G__11742__1; G__11742.cljs$core$IFn$_invoke$arity$2 = G__11742__2; return G__11742; })() ); (datascript.impl.entity.Entity.prototype.get = (function (attr){ var self__ = this; var this$ = this; if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(attr,":db/id")){ return self__.eid; } else { if(datascript.db.reverse_ref_QMARK_(attr)){ return datascript.impl.entity.multival__GT_js(datascript.impl.entity._lookup_backwards(self__.db,self__.eid,datascript.db.reverse_ref(attr),null)); } else { var G__11620 = (datascript.impl.entity.lookup_entity.cljs$core$IFn$_invoke$arity$2 ? datascript.impl.entity.lookup_entity.cljs$core$IFn$_invoke$arity$2(this$,attr) : datascript.impl.entity.lookup_entity.call(null,this$,attr)); if(datascript.db.multival_QMARK_(self__.db,attr)){ return datascript.impl.entity.multival__GT_js(G__11620); } else { return G__11620; } } } })); (datascript.impl.entity.Entity.prototype.key_set = (function (){ var self__ = this; var this$ = this; return cljs.core.to_array(cljs.core.keys(this$)); })); (datascript.impl.entity.Entity.prototype.entries = (function (){ var self__ = this; var this$ = this; return cljs.core.es6_entries_iterator(datascript.impl.entity.js_seq(this$)); })); (datascript.impl.entity.Entity.prototype.value_set = (function (){ var self__ = this; var this$ = this; return cljs.core.to_array(cljs.core.map.cljs$core$IFn$_invoke$arity$2(cljs.core.second,datascript.impl.entity.js_seq(this$))); })); (datascript.impl.entity.Entity.prototype.toString = (function (){ var self__ = this; var this$ = this; return cljs.core.pr_str_STAR_(this$); })); (datascript.impl.entity.Entity.prototype.keys = (function (){ var self__ = this; var this$ = this; return cljs.core.es6_iterator(cljs.core.keys(this$)); })); (datascript.impl.entity.Entity.prototype.values = (function (){ var self__ = this; var this$ = this; return cljs.core.es6_iterator(cljs.core.map.cljs$core$IFn$_invoke$arity$2(cljs.core.second,datascript.impl.entity.js_seq(this$))); })); (datascript.impl.entity.Entity.prototype.equiv = (function (other){ var self__ = this; var this$ = this; return (datascript.impl.entity.equiv_entity.cljs$core$IFn$_invoke$arity$2 ? datascript.impl.entity.equiv_entity.cljs$core$IFn$_invoke$arity$2(this$,other) : datascript.impl.entity.equiv_entity.call(null,this$,other)); })); (datascript.impl.entity.Entity.prototype.has = (function (attr){ var self__ = this; var this$ = this; return (!((this$.get(attr) == null))); })); (datascript.impl.entity.Entity.prototype.cljs$core$ILookup$_lookup$arity$2 = (function (this$,attr){ var self__ = this; var this$__$1 = this; return (datascript.impl.entity.lookup_entity.cljs$core$IFn$_invoke$arity$3 ? datascript.impl.entity.lookup_entity.cljs$core$IFn$_invoke$arity$3(this$__$1,attr,null) : datascript.impl.entity.lookup_entity.call(null,this$__$1,attr,null)); })); (datascript.impl.entity.Entity.prototype.cljs$core$ILookup$_lookup$arity$3 = (function (this$,attr,not_found){ var self__ = this; var this$__$1 = this; return (datascript.impl.entity.lookup_entity.cljs$core$IFn$_invoke$arity$3 ? datascript.impl.entity.lookup_entity.cljs$core$IFn$_invoke$arity$3(this$__$1,attr,not_found) : datascript.impl.entity.lookup_entity.call(null,this$__$1,attr,not_found)); })); (datascript.impl.entity.Entity.prototype.cljs$core$IPrintWithWriter$_pr_writer$arity$3 = (function (_,writer,opts){ var self__ = this; var ___$1 = this; return cljs.core._pr_writer(cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(cljs.core.deref(self__.cache),new cljs.core.Keyword("db","id","db/id",-1388397098),self__.eid),writer,opts); })); (datascript.impl.entity.Entity.prototype.cljs$core$ICounted$_count$arity$1 = (function (this$){ var self__ = this; var this$__$1 = this; (datascript.impl.entity.touch.cljs$core$IFn$_invoke$arity$1 ? datascript.impl.entity.touch.cljs$core$IFn$_invoke$arity$1(this$__$1) : datascript.impl.entity.touch.call(null,this$__$1)); return cljs.core.count(cljs.core.deref(self__.cache)); })); (datascript.impl.entity.Entity.prototype.cljs$core$IHash$_hash$arity$1 = (function (this$){ var self__ = this; var this$__$1 = this; return (datascript.impl.entity.hash_entity.cljs$core$IFn$_invoke$arity$1 ? datascript.impl.entity.hash_entity.cljs$core$IFn$_invoke$arity$1(this$__$1) : datascript.impl.entity.hash_entity.call(null,this$__$1)); })); (datascript.impl.entity.Entity.prototype.cljs$core$IEquiv$_equiv$arity$2 = (function (this$,o){ var self__ = this; var this$__$1 = this; return (datascript.impl.entity.equiv_entity.cljs$core$IFn$_invoke$arity$2 ? datascript.impl.entity.equiv_entity.cljs$core$IFn$_invoke$arity$2(this$__$1,o) : datascript.impl.entity.equiv_entity.call(null,this$__$1,o)); })); (datascript.impl.entity.Entity.prototype.cljs$core$IAssociative$_contains_key_QMARK_$arity$2 = (function (this$,k){ var self__ = this; var this$__$1 = this; return cljs.core.not_EQ_.cljs$core$IFn$_invoke$arity$2(new cljs.core.Keyword("datascript.impl.entity","nf","datascript.impl.entity/nf",-953741353),(datascript.impl.entity.lookup_entity.cljs$core$IFn$_invoke$arity$3 ? datascript.impl.entity.lookup_entity.cljs$core$IFn$_invoke$arity$3(this$__$1,k,new cljs.core.Keyword("datascript.impl.entity","nf","datascript.impl.entity/nf",-953741353)) : datascript.impl.entity.lookup_entity.call(null,this$__$1,k,new cljs.core.Keyword("datascript.impl.entity","nf","datascript.impl.entity/nf",-953741353)))); })); (datascript.impl.entity.Entity.prototype.cljs$core$ISeqable$_seq$arity$1 = (function (this$){ var self__ = this; var this$__$1 = this; (datascript.impl.entity.touch.cljs$core$IFn$_invoke$arity$1 ? datascript.impl.entity.touch.cljs$core$IFn$_invoke$arity$1(this$__$1) : datascript.impl.entity.touch.call(null,this$__$1)); return cljs.core.seq(cljs.core.deref(self__.cache)); })); (datascript.impl.entity.Entity.prototype.call = (function (unused__10318__auto__){ var self__ = this; var self__ = this; var G__11626 = (arguments.length - (1)); switch (G__11626) { case (1): return self__.cljs$core$IFn$_invoke$arity$1((arguments[(1)])); break; case (2): return self__.cljs$core$IFn$_invoke$arity$2((arguments[(1)]),(arguments[(2)])); break; default: throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1((arguments.length - (1)))].join(''))); } })); (datascript.impl.entity.Entity.prototype.apply = (function (self__,args11570){ var self__ = this; var self____$1 = this; return self____$1.call.apply(self____$1,[self____$1].concat(cljs.core.aclone(args11570))); })); (datascript.impl.entity.Entity.prototype.cljs$core$IFn$_invoke$arity$1 = (function (k){ var self__ = this; var this$ = this; return (datascript.impl.entity.lookup_entity.cljs$core$IFn$_invoke$arity$2 ? datascript.impl.entity.lookup_entity.cljs$core$IFn$_invoke$arity$2(this$,k) : datascript.impl.entity.lookup_entity.call(null,this$,k)); })); (datascript.impl.entity.Entity.prototype.cljs$core$IFn$_invoke$arity$2 = (function (k,not_found){ var self__ = this; var this$ = this; return (datascript.impl.entity.lookup_entity.cljs$core$IFn$_invoke$arity$3 ? datascript.impl.entity.lookup_entity.cljs$core$IFn$_invoke$arity$3(this$,k,not_found) : datascript.impl.entity.lookup_entity.call(null,this$,k,not_found)); })); (datascript.impl.entity.Entity.getBasis = (function (){ return new cljs.core.PersistentVector(null, 4, 5, cljs.core.PersistentVector.EMPTY_NODE, [new cljs.core.Symbol(null,"db","db",-1661185010,null),new cljs.core.Symbol(null,"eid","eid",-2094915839,null),new cljs.core.Symbol(null,"touched","touched",1031397108,null),new cljs.core.Symbol(null,"cache","cache",403508473,null)], null); })); (datascript.impl.entity.Entity.cljs$lang$type = true); (datascript.impl.entity.Entity.cljs$lang$ctorStr = "datascript.impl.entity/Entity"); (datascript.impl.entity.Entity.cljs$lang$ctorPrWriter = (function (this__5287__auto__,writer__5288__auto__,opt__5289__auto__){ return cljs.core._write(writer__5288__auto__,"datascript.impl.entity/Entity"); })); /** * Positional factory function for datascript.impl.entity/Entity. */ datascript.impl.entity.__GT_Entity = (function datascript$impl$entity$__GT_Entity(db,eid,touched,cache){ return (new datascript.impl.entity.Entity(db,eid,touched,cache)); }); datascript.impl.entity.entity_QMARK_ = (function datascript$impl$entity$entity_QMARK_(x){ return (x instanceof datascript.impl.entity.Entity); }); datascript.impl.entity.equiv_entity = (function datascript$impl$entity$equiv_entity(this$,that){ return (((that instanceof datascript.impl.entity.Entity)) && ((((this$.db === that.db)) && (cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(this$.eid,that.eid))))); }); datascript.impl.entity.hash_entity = (function datascript$impl$entity$hash_entity(e){ return datascript.db.combine_hashes(cljs.core.hash(e.eid),goog.getUid(e.db)); }); datascript.impl.entity.lookup_entity = (function datascript$impl$entity$lookup_entity(var_args){ var G__11673 = arguments.length; switch (G__11673) { case 2: return datascript.impl.entity.lookup_entity.cljs$core$IFn$_invoke$arity$2((arguments[(0)]),(arguments[(1)])); break; case 3: return datascript.impl.entity.lookup_entity.cljs$core$IFn$_invoke$arity$3((arguments[(0)]),(arguments[(1)]),(arguments[(2)])); break; default: throw (new Error(["Invalid arity: ",cljs.core.str.cljs$core$IFn$_invoke$arity$1(arguments.length)].join(''))); } }); (datascript.impl.entity.lookup_entity.cljs$core$IFn$_invoke$arity$2 = (function (this$,attr){ return datascript.impl.entity.lookup_entity.cljs$core$IFn$_invoke$arity$3(this$,attr,null); })); (datascript.impl.entity.lookup_entity.cljs$core$IFn$_invoke$arity$3 = (function (this$,attr,not_found){ if(cljs.core._EQ_.cljs$core$IFn$_invoke$arity$2(attr,new cljs.core.Keyword("db","id","db/id",-1388397098))){ return this$.eid; } else { if(datascript.db.reverse_ref_QMARK_(attr)){ return datascript.impl.entity._lookup_backwards(this$.db,this$.eid,datascript.db.reverse_ref(attr),not_found); } else { var temp__5806__auto__ = (function (){var fexpr__11689 = cljs.core.deref(this$.cache); return (fexpr__11689.cljs$core$IFn$_invoke$arity$1 ? fexpr__11689.cljs$core$IFn$_invoke$arity$1(attr) : fexpr__11689.call(null,attr)); })(); if((temp__5806__auto__ == null)){ if(cljs.core.truth_(cljs.core.deref(this$.touched))){ return not_found; } else { var temp__5806__auto____$1 = cljs.core.not_empty(datascript.db._search(this$.db,new cljs.core.PersistentVector(null, 2, 5, cljs.core.PersistentVector.EMPTY_NODE, [this$.eid,attr], null))); if((temp__5806__auto____$1 == null)){ return not_found; } else { var datoms = temp__5806__auto____$1; var value = datascript.impl.entity.entity_attr(this$.db,attr,datoms); cljs.core.vreset_BANG_(this$.cache,cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(cljs.core.deref(this$.cache),attr,value)); return value; } } } else { var v = temp__5806__auto__; return v; } } } })); (datascript.impl.entity.lookup_entity.cljs$lang$maxFixedArity = 3); datascript.impl.entity.touch_components = (function datascript$impl$entity$touch_components(db,a__GT_v){ return cljs.core.reduce_kv((function (acc,a,v){ return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(acc,a,((datascript.db.component_QMARK_(db,a))?((datascript.db.multival_QMARK_(db,a))?cljs.core.set(cljs.core.map.cljs$core$IFn$_invoke$arity$2(datascript.impl.entity.touch,v)):(datascript.impl.entity.touch.cljs$core$IFn$_invoke$arity$1 ? datascript.impl.entity.touch.cljs$core$IFn$_invoke$arity$1(v) : datascript.impl.entity.touch.call(null,v))):v)); }),cljs.core.PersistentArrayMap.EMPTY,a__GT_v); }); datascript.impl.entity.datoms__GT_cache = (function datascript$impl$entity$datoms__GT_cache(db,datoms){ return cljs.core.reduce.cljs$core$IFn$_invoke$arity$3((function (acc,part){ var a = new cljs.core.Keyword(null,"a","a",-2123407586).cljs$core$IFn$_invoke$arity$1(cljs.core.first(part)); return cljs.core.assoc.cljs$core$IFn$_invoke$arity$3(acc,a,datascript.impl.entity.entity_attr(db,a,part)); }),cljs.core.PersistentArrayMap.EMPTY,cljs.core.partition_by.cljs$core$IFn$_invoke$arity$2(new cljs.core.Keyword(null,"a","a",-2123407586),datoms)); }); datascript.impl.entity.touch = (function datascript$impl$entity$touch(e){ if((((e == null)) || (datascript.impl.entity.entity_QMARK_(e)))){ } else { throw (new Error("Assert failed: (or (nil? e) (entity? e))")); } if((!((e == null)))){ if(cljs.core.truth_(cljs.core.deref(e.touched))){ } else { var temp__5804__auto___11846 = cljs.core.not_empty(datascript.db._search(e.db,new cljs.core.PersistentVector(null, 1, 5, cljs.core.PersistentVector.EMPTY_NODE, [e.eid], null))); if(cljs.core.truth_(temp__5804__auto___11846)){ var datoms_11850 = temp__5804__auto___11846; cljs.core.vreset_BANG_(e.cache,datascript.impl.entity.touch_components(e.db,datascript.impl.entity.datoms__GT_cache(e.db,datoms_11850))); cljs.core.vreset_BANG_(e.touched,true); } else { } } return e; } else { return null; } }); goog.exportSymbol("datascript.impl.entity.Entity",datascript.impl.entity.Entity); //# sourceMappingURL=datascript.impl.entity.js.map