@lmjs/core 2.1.3 → 2.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -31,7 +31,7 @@ var cl=console.log;class _v{static name;static type;static vars;static fns;stati
31
31
  <div class="ov la pointer" close-notify><span class="cc mdi fs18 mdi-close"></span></div>
32
32
  {{Title}}
33
33
  {{Text}}
34
- </div>`;if(!al)al="topCenter";if(!ty)ty="";if(!$("[notify]").length)$("body").append("<div notify class='"+al+"'></div>");else $("[notify]").attr("class","").addClass(al);$("[notify]").prepend(notify2.split("{{Title}}").join(ti!=""?"<h5>"+ti+"</h5>":"").split("{{Icon}}").join(i2).split("{{Text}}").join(tx).split("{{Type}}").join(ty).split("{{Type}}").join(ti).split("{{Type}}").join(ti));$(".notify").fadeIn();setTimeout(function(){$("[close-notify]:last").click()},5e3)}function _isScrollable(el2){let o1=el2.css("overflow-y")=="scroll"||el2.css("overflow-y")=="auto"&&el2[0].scrollHeight>el2.height()+15;let o2=el2.css("overflow-x")=="scroll"||el2.css("overflow-x")=="auto"&&el2[0].scrollWidth>el2.width()+15;return o1||o2}function _setPos(self,p,el2){var left=self.offset().left;var top=self.offset().top;if(p==""||p=="bottom"){left+=self.innerWidth()/2;top+=self.innerHeight()}else if(p=="left"){top+=self.innerHeight()/2}else if(p=="top"){left+=self.innerWidth()/2}else{left+=self.innerWidth();top+=self.innerHeight()/2}$("tip").css({left,top,right:"unset",bottom:"unset"});if(top+15<el2.offset().top||top>el2.offset().top+el2.height()+10||left+15<el2.offset().left||left>el2.offset().left+el2.width()+10)$("tip").hide();else $("tip").show()}String.prototype.rtrim=function(s){if(s==void 0)s="\\s";try{return this.replace(new RegExp("["+s+"]+$"),"")}catch{return this.replace(new RegExp("[\\"+s+"]+$"),"")}};String.prototype.ltrim=function(s){if(s==void 0)s="\\s";try{return this.replace(new RegExp("^["+s+"]+"),"")}catch{return this.replace(new RegExp("^[\\"+s+"]+"),"")}};
34
+ </div>`;if(!al)al="topCenter";if(!ty)ty="";if(!$("[notify]").length)$("body").append("<div notify class='"+al+"'></div>");else $("[notify]").attr("class","").addClass(al);$("[notify]").prepend(notify2.split("{{Title}}").join(ti!=""?"<h5>"+ti+"</h5>":"").split("{{Icon}}").join(i2).split("{{Text}}").join(tx).split("{{Type}}").join(ty).split("{{Type}}").join(ti).split("{{Type}}").join(ti));$(".notify").fadeIn();setTimeout(function(){$("[close-notify]:last").click()},5e3)}function _isScrollable(el2){let o1=el2.css("overflow-y")=="scroll"||el2.css("overflow-y")=="auto"&&el2[0].scrollHeight>el2.height()+15;let o2=el2.css("overflow-x")=="scroll"||el2.css("overflow-x")=="auto"&&el2[0].scrollWidth>el2.width()+15;return o1||o2}function _setPos(self,p,el2){var left=self.offset().left;var top=self.offset().top;if(p==""||p=="bottom"){left+=self.innerWidth()/2;top+=self.innerHeight()}else if(p=="left"){top+=self.innerHeight()/2}else if(p=="top"){left+=self.innerWidth()/2}else{left+=self.innerWidth();top+=self.innerHeight()/2}$("tip").css({left,top,right:"unset",bottom:"unset"});if(top+15<el2.offset().top||top>el2.offset().top+el2.height()+10||left+15<el2.offset().left||left>el2.offset().left+el2.width()+10)$("tip").hide();else $("tip").show()}String.prototype.rtrim=function(s){if(s==void 0)s="\\s";try{return this.replace(new RegExp("["+s+"]+$"),"")}catch{return this.replace(new RegExp("[\\"+s+"]+$"),"")}};String.prototype.ltrim=function(s){if(s==void 0)s="\\s";try{return this.replace(new RegExp("^["+s+"]+"),"")}catch{return this.replace(new RegExp("^[\\"+s+"]+"),"")}};function paramsToObj(url){try{var entries=new URL(url).searchParams.entries();const result={};for(const[key,value]of entries){result[key]=value}return result}catch(x2){return{}}}function Arr2Obj(arr,key){if(!Array.isArray(arr))return{};return Object.assign({},...arr.map(x2=>({[x2[key]]:x2})))}function ObjFromArr(a,v,k="objectId"){let obj;try{obj=a.find(x2=>x2[k]==v)}catch(e){obj={}}return obj}
35
35
 
36
36
  class AbstractWebSocket{constructor(url,connectionTimeout=5e3){this.url=url;this.socket=null;this.reconnectInterval=3e3;this.reconnectTimeout=null;this.connectionTimeout=connectionTimeout;this.connectionTimeoutId=null;this.connected=false;this.messageQueue=[]}connect(){this.socket=new WebSocket(this.url);this.connectionTimeoutId=setTimeout(()=>{this.handleConnectionTimeout()},this.connectionTimeout);this.socket.onopen=()=>{clearTimeout(this.connectionTimeoutId);this.connected=true;this.onOpen();this.processMessageQueue()};this.socket.onmessage=event=>{this.onMessage(event.data)};this.socket.onclose=event=>{clearTimeout(this.connectionTimeoutId);this.connected=false;this.onClose(event.code);this.reconnect()};this.socket.onerror=error=>{clearTimeout(this.connectionTimeoutId);this.onError(error)}}send(message){cl("Sending ",message);if(this.connected){this.socket.send(message)}else{this.messageQueue.push(message);console.error("WebSocket is not open. Unable to send message.")}}processMessageQueue(){while(this.messageQueue.length>0){const message=this.messageQueue.shift();cl("Sending From Queue ",message);this.socket.send(message)}}handleConnectionTimeout(){this.socket.close()}disconnect(){if(this.socket){this.socket.close()}clearTimeout(this.reconnectTimeout)}onOpen(){}onMessage(message){}onClose(code){}onError(error){}reconnect(){clearTimeout(this.reconnectTimeout);this.reconnectTimeout=setTimeout(()=>{this.connect()},this.reconnectInterval)}}class MyWebSocket extends AbstractWebSocket{constructor(url){super(url)}onOpen(){super.onOpen()}onMessage(message){super.onMessage(message)}onClose(code){super.onClose(code)}onError(error){super.onError(error)}}class Nuclear{_iter=0;reconnectAttempts=0;timeoutInterval=4e3;cbs={};_cbs={};lstnrs={};_ws;srvr=void 0;constructor(srvr){this.srvr=srvr;this.init();return this}on(e,cb){if(!this.lstnrs.hasOwnProperty(e))this.lstnrs[e]=[];this.lstnrs[e].push(cb);if(e=="open"&&this._ws?.readyState==1){this.trigger("open",this._ws)}return this}off(e){if(e=="connect")return this;if(this.lstnrs.hasOwnProperty(e))delete this.lstnrs[e];return this}subscribe(e,cb){return this.on(e,cb)}unsubscribe(e,cb){return this.off(e,cb)}trigger(n,e){if(this.lstnrs.hasOwnProperty(n)){for(let x=0;x<this.lstnrs[n].length;x++){this.lstnrs[n][x](e)}}return this}emit(e,data,cb){try{this._iter++;if(cb)this.cbs["cb_"+this._iter]=cb;if(this.ready()){this._ws.send(JSON.stringify({e,payload:data,_iter:this._iter}))}else{this._send(JSON.stringify({e,payload:data,_iter:this._iter}))}}catch(error){if(_debugMode)cl(error)}return this}_emit(e,data){this._iter++;let prom=defer();this._cbs["cb_"+this._iter]=prom;if(this.ready()){this._ws.send(JSON.stringify({e,payload:data,_iter:this._iter}))}else{this._send(JSON.stringify({e,payload:data,_iter:this._iter}))}return prom}_send(m){let _s=this;setTimeout(function(){if(_s.ready())_s._ws.send(m);else _s._send(m)},500)}ready(){return this._ws!==void 0&&this._ws.readyState==WebSocket.OPEN}connecting(){return this._ws!==void 0&&this._ws.readyState==WebSocket.CONNECTING}init(){var _s=this;this._ws=new ReconnectingWebSocket(this.srvr?this.srvr:"wss://www.beaapis.com/");this._ws.addEventListener("error",event=>{return false});this._ws.onopen=function(e){_s.trigger("connect",e);_s.trigger("open",e)};this._ws.onclose=function(e){_s._iter=0;_s.cbs={};_gn=0;barSet(1,200);_s.reconnectAttempts++};this._ws.onmessage=function(e){try{let data=JSON.parse(e.data);if(data.hasOwnProperty("e")){let event=data["e"];let iter=data["_iter"];const customEvent=new CustomEvent(event,{detail:data["payload"]});customEvent.data=data["payload"];if(event!="rooms")_s.trigger(event,customEvent);if(_s.cbs["cb_"+iter])_s.cbs["cb_"+iter](customEvent);if(_s._cbs["cb_"+iter])_s._cbs["cb_"+iter].resolve(customEvent)}}catch(e2){if(_debugMode)cl(e2)}};this._ws.onerror=function(e){_gn=0;barSet(1,200)}}}class _Ticker{id="";tick=1e3;duration=1e4;data={};status="created";user=void 0;channel=void 0;_cbs={};constructor(obj,channel,user){this.id=obj.id;this.tick=obj?.tick??1e3;this.duration=obj?.duration??1e4;this.data=obj?.data??{};this.user=user;this.channel=channel;this.user.id=this.user.id;this.init();return this}init(opts,lstnrs){let t=this.tick;let d=this.duration;let data=this.data;if(opts){if(opts.hasOwnProperty("tick"))t=opts.tick;if(opts.hasOwnProperty("duration"))d=opts.duration;if(opts.hasOwnProperty("data"))data=opts.data}this.user.nuke.emit("subscribe",{type:"ticker",ticker:this.id,channel:this.channel.id,user:this.user.id,data:{tick:t,duration:d,data}});if(!this.user.nuke._tickers.hasOwnProperty(this.channel.id))this.user.nuke._tickers[this.channel.id]={};this.user.nuke._tickers[this.channel.id][this.id]=this;if(!lstnrs){var self=this;this.on("create.class",function(e){self.status="created"});this.on("start.class",function(e){self.status="started"});this.on("tick.class",function(e){self.status="started"});this.on("pause.class",function(e){self.status="paused"});this.on("finish.class",function(e){self.status="finished"})}}start(){if(this.status=="started"){setError(null,`This ticker is already started`);return this}if(this.status=="finished"){setError(null,`This ticker is finished`);return this}this.user.nuke.emit("ticker",{ticker:this.id,channel:this.channel.id,user:this.user.id,ev:"start"})}pause(){if(this.status=="paused"){setError(null,`This ticker is already paused`);return this}if(this.status!="started"){setError(null,`This ticker is not started yet!`);return this}this.user.nuke.emit("ticker",{ticker:this.id,channel:this.channel.id,user:this.user.id,ev:"pause"})}restart(opts){if(this.status!="finished"){setError(null,`This ticker is not finished yet!`);return this}this.init(opts,true)}delete(){this.user.nuke.emit("unsubscribe",{type:"ticker",ticker:this.id,channel:this.channel.id,user:this.user.id,ev:"delete"})}extend(t){this.user.nuke.emit("ticker",{ticker:this.id,channel:this.channel.id,user:this.user.id,ev:"extend",data:{time:t}})}on(e,cb){let myRef2=document.createElement("live");myRef2.dataset["cb"]=cb;document.body.append(myRef2);if(this._cbs.hasOwnProperty(e)){this._cbs[e].push(cb)}else this._cbs[e]=[cb];return this}off(e){if(this._cbs.hasOwnProperty(e))delete this._cbs[e];return this}trigger(e,customEvent){if(this._cbs.hasOwnProperty(e)){for(let i=0;i<this._cbs[e].length;i++){const cb=this._cbs[e][i];cb(customEvent)}}return this}}class _Channel{id="/";user=void 0;type="room";_cbs={};constructor(id,type,user){this.id=id;this.type=type;this.user=user;this.user.id=this.user.id??"Guest";return this}trigger(e,customEvent){if(this._cbs.hasOwnProperty(e)){for(let i=0;i<this._cbs[e].length;i++){const cb=this._cbs[e][i];cb(customEvent)}}return this}join(){this.user.nuke.emit("subscribe",{type:this.type,channel:this.id,user:this.user.id});if(!this.user.nuke._chnls.hasOwnProperty(this.user.id))this.user.nuke._chnls[this.user.id]={};this.user.nuke._chnls[this.user.id][this.id]=this}leave(){this.user.nuke.emit("unsubscribe",{type:this.type,channel:this.id,user:this.user.id,ev:"leave"});if(this.user.nuke._chnls.hasOwnProperty(this.user.id)){delete this.user.nuke._chnls[this.user.id][this.id]}}broadcast(ev,options){this.user.nuke.emit("broadcast",{type:"room",channel:this.id,user:this.user.id,ev,includeMe:options?.includeMe??true,data:options?.data??{}})}off(e){if(e=="connect")return this;if(this._cbs.hasOwnProperty(e))delete this._cbs[e];return this}on(e,cb){let myRef2=document.createElement("live");myRef2.dataset["cb"]=cb;document.body.append(myRef2);if(this._cbs.hasOwnProperty(e)){this._cbs[e].push(cb)}else this._cbs[e]=[cb];return this}createTicker(obj){if(!this.user.nuke._tickers.hasOwnProperty(this.id)){this.user.nuke._tickers[this.id]={}}let t=new _Ticker(obj,this,this.user);return t}getTicker(id){this.user.nuke.emit("get",{type:"ticker",channel:this.id,user:this.user.id,ticker:id})}}class _User{id="";nuke=void 0;_cbs={};constructor(id,nuke){this.id=id;this.nuke=nuke;this.init();return this}init(){this.nuke.emit("subscribe",{type:"user",channel:this.id,user:this.id});if(!this.nuke._users.hasOwnProperty("/"+this.id))this.nuke._users["/"+this.id]=this}on(e,cb){if(this.nuke._users["/"+this.id]._cbs.hasOwnProperty(e)){this.nuke._users["/"+this.id]._cbs[e].push(cb)}else this.nuke._users["/"+this.id]._cbs[e]=[cb];return this}off(e){if(this._cbs.hasOwnProperty(e))delete this._cbs[e];return this}broadcast(ev,options){this.nuke.emit("broadcast",{type:"user",channel:this.id,user:this.id,ev,includeMe:options?.includeMe??true,data:options?.data??{}})}trigger(e,customEvent){if(this._cbs.hasOwnProperty(e)){for(let i=0;i<this._cbs[e].length;i++){const cb=this._cbs[e][i];cb(customEvent)}}return this}_broadcastToAll(IDs,e,d,t){this.nuke.emit("broadcast",{type:t=="u"?"user":"room",user:this.id,ev:e,includeMe:d["includeMe"]??true,data:d["data"],...t=="u"?{users:IDs.join(",")}:{channels:IDs.join(",")}})}broadcastToUsers(uIDs,e,d){this._broadcastToAll(uIDs,e,d,"u")}broadcastToChannels(cIDs,e,d){this._broadcastToAll(cIDs,e,d,"c")}unsubscribe(c){if(this.nuke._chnls.hasOwnProperty(this.id)){if(this.nuke._chnls[this.id].hasOwnProperty(c))this.nuke._chnls[this.id][c].leave()}}subscribe(e,cb){if(!this.nuke._chnls.hasOwnProperty(this.id)){this.nuke._chnls[this.id]={}}let channel=new _Channel(e,"room",this);channel.join();return channel}destroy(){this._cbs={};if(this.nuke._chnls.hasOwnProperty(this.id)){let chnls=this.nuke._chnls[this.id];for(const chnl in chnls){this.unsubscribe(chnl)}}}}class _Live{_chnls={};_users={};_tickers={};_iter=0;reconnectAttempts=0;timeoutInterval=4e3;cbs={};_cbs={};lstnrs={};_ws;srvr=void 0;constructor(srvr){this.srvr=srvr;this.init();return this}on(e,cb){if(!this.lstnrs.hasOwnProperty(e))this.lstnrs[e]=[];this.lstnrs[e].push(cb);if(e=="open"&&this._ws?.readyState==1){this.trigger("open",this._ws)}return this}off(e){if(e=="connect")return this;if(this.lstnrs.hasOwnProperty(e))delete this.lstnrs[e];return this}createUser(id){let user=new _User(id,this);return user}subscribe(e,cb){return this.on(e,cb)}unsubscribe(e,cb){return this.off(e,cb)}trigger(n,e){if(this.lstnrs.hasOwnProperty(n)){for(let x=0;x<this.lstnrs[n].length;x++){this.lstnrs[n][x](e)}}return this}emit(e,data,cb){try{this._iter++;if(cb)this.cbs["cb_"+this._iter]=cb;if(this.ready()){this._ws.send(JSON.stringify({e,payload:data,_iter:this._iter}))}else{this._send(JSON.stringify({e,payload:data,_iter:this._iter}))}}catch(error){if(_debugMode)cl(error)}return this}_emit(e,data){this._iter++;let prom=defer();this._cbs["cb_"+this._iter]=prom;if(this.ready()){this._ws.send(JSON.stringify({e,payload:data,_iter:this._iter}))}else{this._send(JSON.stringify({e,payload:data,_iter:this._iter}))}return prom}_send(m){let _s=this;setTimeout(function(){if(_s.ready())_s._ws.send(m);else _s._send(m)},500)}ready(){return this._ws!==void 0&&this._ws.readyState==WebSocket.OPEN}connecting(){return this._ws!==void 0&&this._ws.readyState==WebSocket.CONNECTING}init(){var _s=this;if(_s.ready()||_s.connecting()){return}this._ws=new ReconnectingWebSocket(this.srvr?this.srvr:"wss://www.beaapis.com/");this._ws.addEventListener("error",event=>{});this._ws.onopen=function(e){_s.trigger("connect",e);_s.trigger("open",e)};this._ws.onclose=function(e){_s._iter=0;_s.cbs={};_gn=0;barSet(1,200);_s.reconnectAttempts++};this._ws.onmessage=function(e){try{let data=JSON.parse(e.data);if(data.hasOwnProperty("for")){let t=data["type"]??"room";let ev=data["ev"]??"message";const customEvent=new CustomEvent(ev,{detail:data["payload"]});customEvent.data=data["payload"];let payload=data["payload"];if(payload.hasOwnProperty("user")){if(t=="user"){_s._users[data["for"]].trigger(ev,customEvent)}else if(t=="room")_s._chnls[payload.user.id][data["for"]].trigger(ev,customEvent);else if(t=="ticker"){_s._tickers[data["for"]][payload?.ticker?.id].trigger(ev,customEvent);_s._tickers[data["for"]][payload?.ticker?.id].trigger(ev+".class",customEvent)}}}else if(data.hasOwnProperty("e")){let event=data["e"];let iter=data["_iter"];const customEvent=new CustomEvent(event,{detail:data["payload"]});customEvent.data=data["payload"];if(event!="rooms")_s.trigger(event,customEvent);if(_s.cbs["cb_"+iter])_s.cbs["cb_"+iter](customEvent);if(_s._cbs["cb_"+iter])_s._cbs["cb_"+iter].resolve(customEvent)}}catch(e2){if(_debugMode)cl(e2)}};this._ws.onerror=function(e){_gn=0;barSet(1,200)}}}let LIVE;let Nuke;LIVE=new _Live("wss://www.beaapis.com/");Nuke=new Nuclear(_beaTn?void 0:(window.location.protocol==="https:"?"wss://":"ws://")+window.location.hostname+(window.location.port?":"+window.location.port:""));let _ovcD,_vcD;function syncViewFiles(){Nuke.emit("getfiles",{},function(e){var _files=e.data;let views=_files["views"];let layouts=_files["layouts"];_vcD=_files;if(!_ovcD)_ovcD=clone(_vcD);else{for(var key in views){if(_ovcD["views"].hasOwnProperty(key)){if(!deepCompare(clone(_ovcD["views"][key]),clone(views[key]))){cl("Changed the view "+atob(key));let n=atob(key).split("src/views/").join("").split(".view").join("");let nodes=getURLNodes();_ovcD["views"][key]=views[key];cl("view",n,atob(key));if(n.indexOf("widgets/")===0){let changedWidgetName=n.split("widgets/").join("");for(let regionName in _vt.Widgets){if(_vt.Widgets[regionName]._resolvedFile===changedWidgetName){_vt.Widgets[regionName]._resolvedFile=void 0}}renderView(nodes[0],null,View.props??{})}else if(nodes[0]==n){renderView(nodes[0],null,View.props??{})}else{renderView(n,true,{})}}}}for(var key in layouts){if(_ovcD["layouts"].hasOwnProperty(key)){if(!deepCompare(clone(_ovcD["layouts"][key]),clone(layouts[key]))){cl("Changed the layout "+atob(key));let n=atob(key).split("src/layouts/").join("").split(".layout").join("");let nodes=getURLNodes();_ovcD["layouts"][key]=layouts[key];cl("layout",n,atob(key));renderView(n,false,{},"layouts")}}}}})}Nuke.on("connect",function(){if(_beaTn){Nuke.emit("get_uniquer",{beajsToken:_beaTn,uniquer:globals.uniquer},function(e){let d=e.data;let data=d.uniquer;globals.uniquer=data})}else{syncViewFiles()}});Nuke.on("files-changed",function(){if(!_beaTn)syncViewFiles()});var API={get:function(u,d,h,a,opts){return this.req(u,d,h,"GET",a,opts)},put:function(u,d,h,a,opts){return this.req(u,d,h,"PUT",a,opts)},post:function(u,d,h,a,opts){return this.req(u,d,h,"POST",a,opts)},delete:function(u,d,h,a,opts){return this.req(u,d,h,"DELETE",a,opts)},patch:function(u,d,h,a,opts){return this.req(u,d,h,"PATCH",a,opts)},req:function(u,d,h,m,a,opts,_prom){if(!opts)opts={full:false,progress:true};let prog=opts.hasOwnProperty("progress")?opts.progress:true;let full=opts.hasOwnProperty("full")?opts.full:false;let prom=_prom?_prom:defer();try{return prom}finally{if(Nuke&&Nuke._ws&&Nuke._ws.readyState==1&&(_beaTn?globals.uniquer>0:true)){if(prog){_gn=0;_work()}Nuke.emit("request",{body:{method:m,path:u,api:a??0,headers:h,full},uniquer:globals.uniquer??0,data:d},function(e){if(prog){_gn=0;barSet(1,200)}var r=e.data;prom.resolve(r)})}else{if(_beaTn&&_beaTn!=""){$.ajax({"url":"https://www.beaapis.com/req",headers:{},type:"POST",dataType:"json",data:{body:{method:m,path:u,api:a??0,headers:h,full},uniquer:globals.uniquer??0,_beaTn,data:d},cache:false,success:function(r,s){prom.resolve(r)},error:function(){prom.reject("error")}})}else{setTimeout(()=>{this.req(u,d,h,m,a,opts,prom)},_tickTime)}}}}};
37
37
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lmjs/core",
3
- "version": "2.1.3",
3
+ "version": "2.1.4",
4
4
  "description": "LumenJS reactive core runtime — the reactive engine, HTML/JS AST compiler, realtime socket client, and delegated event listeners powering LumenJS applications.",
5
5
  "files": [
6
6
  "dist/",
@@ -4140,4 +4140,47 @@ String.prototype.ltrim = function (s) {
4140
4140
  }
4141
4141
  };
4142
4142
 
4143
+ // 2026-09-21: three real V1 global utilities (beajs/core.js), confirmed
4144
+ // missing here while migrating a real V1 project (Arr2Obj is actively used
4145
+ // in that project's own index.js) — a full audit against every one of
4146
+ // core.js's other 61 top-level functions (plus re.js/listeners.js) found
4147
+ // no other gaps; everything else was already ported or is V1 engine-
4148
+ // internal code V2's own rewritten engine already supersedes.
4149
+ function paramsToObj(url) {
4150
+ try {
4151
+ var entries = new URL(url).searchParams.entries();
4152
+ const result = {}
4153
+ for (const [key, value] of entries) {
4154
+ result[key] = value;
4155
+ }
4156
+ return result;
4157
+ } catch (x) {
4158
+ return {};
4159
+ }
4160
+ }
4161
+
4162
+ function Arr2Obj(arr, key) {
4163
+ // Real improvement over the V1 original, which threw on anything but
4164
+ // a real array (arr.map on undefined/null/a single object) — every
4165
+ // other small utility in this immediate area (paramsToObj/ObjFromArr
4166
+ // above/below) already fails safe to {} the same way; this one just
4167
+ // hadn't caught up. Observable behavior for any already-correct V1
4168
+ // call site is unchanged.
4169
+ if (!Array.isArray(arr)) return {};
4170
+ return Object.assign(
4171
+ {},
4172
+ ...arr.map((x) => ({ [x[key]]: x }))
4173
+ );
4174
+ }
4175
+
4176
+ function ObjFromArr(a, v, k = 'objectId') {
4177
+ let obj;
4178
+ try {
4179
+ obj = a.find((x) => x[k] == v);
4180
+ } catch (e) {
4181
+ obj = {};
4182
+ }
4183
+ return obj;
4184
+ }
4185
+
4143
4186