@symbo.ls/utils 3.14.776 → 3.14.777
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.
- package/dist/cjs/methods.js +5 -5
- package/dist/esm/methods.js +7 -7
- package/methods.js +16 -4
- package/package.json +1 -1
package/dist/cjs/methods.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
"use strict";var D=Object.create;var g=Object.defineProperty;var
|
|
2
|
-
`,"font-weight: bold",t[o])):(console.log(n.path),t.keys().forEach(r=>console.log(`%c${r}:`,"font-weight: bold",t[r]))),console.log(t),console.groupEnd(t.key),t}function
|
|
1
|
+
"use strict";var D=Object.create;var g=Object.defineProperty;var I=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var F=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var M=(e,t)=>{for(var n in t)g(e,n,{get:t[n],enumerable:!0})},$=(e,t,n,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of T(t))!L.call(e,r)&&r!==n&&g(e,r,{get:()=>t[r],enumerable:!(o=I(t,r))||o.enumerable});return e};var J=(e,t,n)=>(n=e!=null?D(F(e)):{},$(t||!e||!e.__esModule?g(n,"default",{value:e,enumerable:!0}):n,e)),G=e=>$(g({},"__esModule",{value:!0}),e);var Rt={};M(Rt,{call:()=>ht,defineSetter:()=>it,error:()=>R,get:()=>W,getChildren:()=>K,getContext:()=>st,getDB:()=>dt,getPath:()=>X,getQuery:()=>_t,getRef:()=>Z,getRoot:()=>nt,getRootContext:()=>rt,getRootData:()=>ot,getRootState:()=>et,isMethod:()=>Ot,keys:()=>N,log:()=>ct,lookdown:()=>z,lookdownAll:()=>H,lookup:()=>V,nextElement:()=>ft,parse:()=>j,parseDeep:()=>O,previousElement:()=>ut,promoteActiveRootState:()=>tt,remove:()=>U,setActiveRootState:()=>q,setNodeStyles:()=>C,setProps:()=>Y,spotByPath:()=>B,variables:()=>at,verbose:()=>Q,warn:()=>lt});module.exports=G(Rt);var w=require("./triggerEvent.js"),d=require("./keys.js"),f=require("./types.js"),y=require("./object.js"),P=require("./env.js"),A=require("./array.js"),b=require("./cache.js");const h="production";function B(e){const t=this,{__ref:n}=t,o=[].concat(e);let r=n.root[o[0]];if(!o||!o.length)return console.log(o,"on",t.key,"is undefined");for(;r.key===o[0]&&(o.shift(),!!o.length);)if(r=r[o[0]],!r)return;return r}function V(e){const t=this;let{parent:n}=t;if((0,f.isFunction)(e))return n.state&&e(n,n.state,n.context)?n:n.parent?n.lookup(e):void 0;if(t[e])return t[e];for(;n.param!==e;){if(n[e])return n[e];if(n=n.parent,!n)return}return n}function z(e){const t=this,{__ref:n}=t,o=n?.__children;if(o)for(let r=0;r<o.length;r++){const s=o[r],i=t[s];if(s===e)return i;if((0,f.isFunction)(e)){const l=e(i,i.state,i.context);if(i.state&&l)return i}const c=i?.lookdown?.(e);if(c)return c}}function H(e,t=[]){const n=this,{__ref:o}=n,r=o?.__children;if(r){for(let s=0;s<r.length;s++){const i=r[s],c=n[i];if(i===e)t.push(c);else if((0,f.isFunction)(e)){const l=e(c,c.state,c.context);c.state&&l&&t.push(c)}c?.lookdownAll?.(e,t)}return t.length?t:void 0}}function C(e={}){const t=this;if(t.node?.style){for(const n in e){const o=e[n],r=t[n];if((0,f.isObject)(o)&&r)C.call(r,o);else if(o!=null){const s=n.replace(/[A-Z]/g,c=>"-"+c.toLowerCase()),i=String(o).replace(/\s*!important\s*$/,"");t.node.style.setProperty(s,i,"important")}}return t}}function U(e){const t=this;if((0,w.triggerEventOn)("beforeRemove",t,e)===!1)return t;(0,f.isFunction)(t.node.remove)?t.node.remove():(0,P.isProduction)()||(console.warn("This item cant be removed"),t.log()),delete t.parent[t.key],t.parent.__ref&&(t.parent.__ref.__children=(0,A.removeValueFromArray)(t.parent.__ref.__children,t.key)),(0,w.triggerEventOn)("remove",t,e)}function W(e){return this[e]}function Y(e,t){const n=this;if(e)return n.update(e,t),n}function Z(e){return e?this.__ref&&this.__ref[e]:this.__ref}function K(){const e=this.getRef("__children");return Array.isArray(e)?e.map(t=>this[t]):[]}function X(){return this.getRef().path}let m=null;const q=e=>{m=e||null},tt=(e,t)=>{e&&t&&m===e&&(m=t)},k=()=>m||null;function et(e){let t=null;const n=o=>o.__element&&o.root?.isRootState;if(!this)t=k();else if(n(this))t=this.root;else if(this.__ref&&this.__ref.path){const o=this.state&&n(this.state),r=(0,f.isFunction)(this.state)&&this.parent.state&&n(this.parent.state);(o||r)&&(t=this.state.root||this.parent.state.root)}return t||(t=k()),e?t?.[e]:t}function nt(e){const t=this?.__ref?.root||this.getRootState()?.__element;if(!t)throw new Error(`[smbls] getRoot() could not resolve a root element for "${this?.key||"<unknown>"}" \u2014 it has no __ref (never went through create()) and no root state is registered. Answering undefined here used to no-op silently for every caller.`);return Object.keys(t).length>0&&e?t[e]:t}function ot(e){return this.getRoot("data")&&Object.keys(this.getRoot("data")).length>0&&e?this.getRoot("data")[e]:this.getRoot("data")}function rt(e){const t=this.getRoot()?.context;return e?t[e]:t}function st(e){const t=this.context;return e?t[e]:t}const it=(e,t,n,o)=>Object.defineProperty(e,t,{get:n,set:o});function N(){const e=this,t=[];for(const n in e)!Object.prototype.hasOwnProperty.call(e,n)||d.DOMQ_PROPERTIES.has(n)&&!d.PARSED_DOMQ_PROPERTIES.has(n)||t.push(n);return t}function j(e=[]){const t=this,n={},o=N.call(t),r=o.includes("children"),s=e.length?new Set(e):null;for(let i=0;i<o.length;i++){const c=o[i];if(s&&s.has(c)||!Object.prototype.hasOwnProperty.call(t,c)||r&&c==="content")continue;const l=t[c];if(c==="state"){if(t.__ref&&!t.__ref.__hasRootState)continue;const u=(0,f.isFunction)(l&&l.parse)?l.parse():l;n[c]=(0,f.isFunction)(u)?u:JSON.parse(JSON.stringify(u||{}))}else if(c==="scope"){if(t.__ref&&!t.__ref.__hasRootScope)continue;n[c]=JSON.parse(JSON.stringify(l||{}))}else if(c==="props"){const{__element:u,update:a,...p}=t[c];n[c]=p}else(0,f.isDefined)(l)&&Object.prototype.hasOwnProperty.call(t,c)&&(n[c]=l)}return n}function O(e=[],t=new WeakSet){const n=this;if(t.has(n))return;t.add(n);const o=j.call(n,e),r=e.length?new Set(e):null;for(const s in o){if(r&&r.has(s)||!Object.prototype.hasOwnProperty.call(n,s))continue;const i=o[s];Array.isArray(i)?o[s]=i.map(c=>(0,f.isObjectLike)(c)?O.call(c,e,t):c):(0,f.isObjectLike)(i)&&(o[s]=O.call(i,e,t))}return o}function Q(...e){if(h!=="test"&&h!=="development")return;const t=this,{__ref:n}=t;return console.groupCollapsed(t.key),e.length?e.forEach(o=>console.log(`%c${o}:
|
|
2
|
+
`,"font-weight: bold",t[o])):(console.log(n.path),t.keys().forEach(r=>console.log(`%c${r}:`,"font-weight: bold",t[r]))),console.log(t),console.groupEnd(t.key),t}function ct(...e){(h==="test"||h==="development")&&console.log(...e)}function lt(...e){(h==="test"||h==="development")&&console.warn(...e)}function R(...e){if(h==="test"||h==="development"){if(e[e.length-1]?.debugger)debugger;throw e[e.length-1]?.verbose&&Q.call(this),new Error(...e)}}function ft(){const e=this,{key:t,parent:n}=e,{__children:o}=n.__ref,r=o.indexOf(t),s=o[r+1];return n[s]}function ut(e){const t=e||this,{key:n,parent:o}=t,{__children:r}=o.__ref;if(!r)return;const s=r.indexOf(n);return o[r[s-1]]}function at(e={}){const t=this;t.data||(t.data={}),t.data.varCaches||(t.data.varCaches={});const n=t.data.varCaches,o={};let r;for(const s in e)e[s]!==n[s]&&(r=!0,o[s]=e[s]);return{changed:s=>{if(!r)return;const i=s(o,(0,y.deepClone)(n));for(const c in o)n[c]=o[c];return i},timeout:(s,i)=>{if(!r)return;const c=setTimeout(()=>{s(o),clearTimeout(c)},i)}}}function ht(e,...t){const n=this.context,o=n.utils?.[e]||n.functions?.[e]||n.methods?.[e]||n.snippets?.[e];if(o&&!(0,y.isFailedRevival)(o))try{const r=o.call(this,...t);return r&&typeof r.then=="function"&&r.catch(s=>{R.call(this,s)}),r}catch(r){if(R.call(this,r),n?.strictMode)throw r}}const pt="[smbls] getDB needs @symbo.ls/fetch, which the smbls embed bundle does not include: add @symbo.ls/fetch to the page's importmap (the runtime import then resolves) or use the full smbls bundle.",x=()=>import("@symbo.ls/fetch").catch(e=>{throw new Error(pt,{cause:e})});async function dt(){const e=this,t=e.context?.fetch;if(!t)return null;if(typeof t.select=="function"){if(!t.__authInitialized&&t.getSession){const{initAdapterAuth:r}=await x();await r(t,e.context)}return t}if(t.__resolved){if(!t.__resolved.__authInitialized&&t.__resolved.getSession){const{initAdapterAuth:r}=await x();await r(t.__resolved,e.context)}return t.__resolved}if(t.__resolving)return t.__resolving;const n=x().then(({resolveDb:r})=>r(t));t.__resolving=n;const o=await n;if(t.__resolved=o,e.context.fetch=o,delete t.__resolving,o?.getSession){const{initAdapterAuth:r}=await x();await r(o,e.context)}return o}function _t(e){const t=this,n=e||b.OPTIONS.useStateQuery||t.context?.useStateQuery;if(!n)return null;const o={};if(S(t,o),n===!0)return o;const r=wt[n];return r?r(o):o}const S=(e,t)=>{const n=e.__ref;if(!n)return;const o=n.__state;o&&typeof o=="string"&>(t,o);const r=n.__children;if(r)for(let c=0;c<r.length;c++){const l=e[r[c]];l&&l.__ref&&S(l,t)}const s=n.contentElementKey||"content",i=e[s];i&&i.__ref&&S(i,t)},gt=(e,t)=>{const o=t.replaceAll("../","").replaceAll("~/","").split("/");let r=e;for(let s=0;s<o.length;s++){const i=o[s];s===o.length-1?r[i]||(r[i]=!0):(r[i]===!0&&(r[i]={}),r[i]||(r[i]={}),r=r[i])}},E=(e,t=0)=>{const n=" ".repeat(t),o=Object.entries(e);return o.length?o.map(([s,i])=>i===!0?`${n}${s}`:`${n}${s} {
|
|
3
3
|
${E(i,t+1)}
|
|
4
4
|
${n}}`).join(`
|
|
5
|
-
`):""},
|
|
5
|
+
`):""},mt=e=>`{
|
|
6
6
|
${E(e,1)}
|
|
7
|
-
}`,
|
|
7
|
+
}`,xt=e=>{const t={fields:{},include:[]},n=(o,r)=>{const s=[];for(const i in o)if(o[i]===!0)s.push(i);else{const c=r?`${r}.${i}`:i;t.include.push(c),n(o[i],c)}s.length&&(t.fields[r||"_root"]=s)};return n(e,""),t},yt=e=>{const t=s=>{const i=[],c=[];for(const l in s)if(s[l]===!0)i.push(l);else{const u=t(s[l]),a=[];u.select&&a.push(`$select=${u.select}`),u.expand&&a.push(`$expand=${u.expand}`),c.push(a.length?`${l}(${a.join(";")})`:l)}return{select:i.length?i.join(","):"",expand:c.length?c.join(","):""}},{select:n,expand:o}=t(e),r=[];return n&&r.push(`$select=${n}`),o&&r.push(`$expand=${o}`),r.join("&")},vt=(e,t)=>{const n=[],o=[],r=new Set,s=(a,p,v)=>{r.add(p),v&&o.push(`LEFT JOIN ${p} ON ${p}.${v}_id = ${v}.id`);for(const _ in a)a[_]===!0?n.push(`${p}.${_}`):s(a[_],_,p)},i=Object.keys(e);i.length===1&&e[i[0]]!==!0?s(e[i[0]],i[0],null):s(e,"_root",null);const c=[...r][0]||"_root",l=n.length?n.join(", "):"*",u=o.length?`
|
|
8
8
|
`+o.join(`
|
|
9
9
|
`):"";return`SELECT ${l}
|
|
10
|
-
FROM ${c}${u}`},
|
|
10
|
+
FROM ${c}${u}`},St=e=>{const t=[],n=(o,r)=>{for(const s in o){const i=r?`${r}/${s}`:s;o[s]===!0?t.push(i):n(o[s],i)}};return n(e,""),t},wt={graphql:mt,"json-api":xt,odata:yt,sql:vt,paths:St};function Ot(e,t){return!!(d.METHODS.has(e)||t?.context?.methods?.[e])}
|
package/dist/esm/methods.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import{triggerEventOn as
|
|
2
|
-
`,"font-weight: bold",t[o])):(console.log(n.path),t.keys().forEach(r=>console.log(`%c${r}:`,"font-weight: bold",t[r]))),console.log(t),console.groupEnd(t.key),t}function
|
|
3
|
-
${
|
|
1
|
+
import{triggerEventOn as y}from"./triggerEvent.js";import{DOMQ_PROPERTIES as $,METHODS as k,PARSED_DOMQ_PROPERTIES as E}from"./keys.js";import{isDefined as P,isFunction as p,isObject as A,isObjectLike as v}from"./types.js";import{deepClone as b,isFailedRevival as C}from"./object.js";import{isProduction as N}from"./env.js";import{removeValueFromArray as j}from"./array.js";import{OPTIONS as Q}from"./cache.js";const a="production";function tt(e){const t=this,{__ref:n}=t,o=[].concat(e);let r=n.root[o[0]];if(!o||!o.length)return console.log(o,"on",t.key,"is undefined");for(;r.key===o[0]&&(o.shift(),!!o.length);)if(r=r[o[0]],!r)return;return r}function et(e){const t=this;let{parent:n}=t;if(p(e))return n.state&&e(n,n.state,n.context)?n:n.parent?n.lookup(e):void 0;if(t[e])return t[e];for(;n.param!==e;){if(n[e])return n[e];if(n=n.parent,!n)return}return n}function nt(e){const t=this,{__ref:n}=t,o=n?.__children;if(o)for(let r=0;r<o.length;r++){const s=o[r],i=t[s];if(s===e)return i;if(p(e)){const l=e(i,i.state,i.context);if(i.state&&l)return i}const c=i?.lookdown?.(e);if(c)return c}}function ot(e,t=[]){const n=this,{__ref:o}=n,r=o?.__children;if(r){for(let s=0;s<r.length;s++){const i=r[s],c=n[i];if(i===e)t.push(c);else if(p(e)){const l=e(c,c.state,c.context);c.state&&l&&t.push(c)}c?.lookdownAll?.(e,t)}return t.length?t:void 0}}function D(e={}){const t=this;if(t.node?.style){for(const n in e){const o=e[n],r=t[n];if(A(o)&&r)D.call(r,o);else if(o!=null){const s=n.replace(/[A-Z]/g,c=>"-"+c.toLowerCase()),i=String(o).replace(/\s*!important\s*$/,"");t.node.style.setProperty(s,i,"important")}}return t}}function rt(e){const t=this;if(y("beforeRemove",t,e)===!1)return t;p(t.node.remove)?t.node.remove():N()||(console.warn("This item cant be removed"),t.log()),delete t.parent[t.key],t.parent.__ref&&(t.parent.__ref.__children=j(t.parent.__ref.__children,t.key)),y("remove",t,e)}function st(e){return this[e]}function it(e,t){const n=this;if(e)return n.update(e,t),n}function ct(e){return e?this.__ref&&this.__ref[e]:this.__ref}function lt(){const e=this.getRef("__children");return Array.isArray(e)?e.map(t=>this[t]):[]}function ft(){return this.getRef().path}let _=null;const ut=e=>{_=e||null},at=(e,t)=>{e&&t&&_===e&&(_=t)},S=()=>_||null;function ht(e){let t=null;const n=o=>o.__element&&o.root?.isRootState;if(!this)t=S();else if(n(this))t=this.root;else if(this.__ref&&this.__ref.path){const o=this.state&&n(this.state),r=p(this.state)&&this.parent.state&&n(this.parent.state);(o||r)&&(t=this.state.root||this.parent.state.root)}return t||(t=S()),e?t?.[e]:t}function pt(e){const t=this?.__ref?.root||this.getRootState()?.__element;if(!t)throw new Error(`[smbls] getRoot() could not resolve a root element for "${this?.key||"<unknown>"}" \u2014 it has no __ref (never went through create()) and no root state is registered. Answering undefined here used to no-op silently for every caller.`);return Object.keys(t).length>0&&e?t[e]:t}function dt(e){return this.getRoot("data")&&Object.keys(this.getRoot("data")).length>0&&e?this.getRoot("data")[e]:this.getRoot("data")}function _t(e){const t=this.getRoot()?.context;return e?t[e]:t}function gt(e){const t=this.context;return e?t[e]:t}const mt=(e,t,n,o)=>Object.defineProperty(e,t,{get:n,set:o});function I(){const e=this,t=[];for(const n in e)!Object.prototype.hasOwnProperty.call(e,n)||$.has(n)&&!E.has(n)||t.push(n);return t}function T(e=[]){const t=this,n={},o=I.call(t),r=o.includes("children"),s=e.length?new Set(e):null;for(let i=0;i<o.length;i++){const c=o[i];if(s&&s.has(c)||!Object.prototype.hasOwnProperty.call(t,c)||r&&c==="content")continue;const l=t[c];if(c==="state"){if(t.__ref&&!t.__ref.__hasRootState)continue;const f=p(l&&l.parse)?l.parse():l;n[c]=p(f)?f:JSON.parse(JSON.stringify(f||{}))}else if(c==="scope"){if(t.__ref&&!t.__ref.__hasRootScope)continue;n[c]=JSON.parse(JSON.stringify(l||{}))}else if(c==="props"){const{__element:f,update:u,...h}=t[c];n[c]=h}else P(l)&&Object.prototype.hasOwnProperty.call(t,c)&&(n[c]=l)}return n}function w(e=[],t=new WeakSet){const n=this;if(t.has(n))return;t.add(n);const o=T.call(n,e),r=e.length?new Set(e):null;for(const s in o){if(r&&r.has(s)||!Object.prototype.hasOwnProperty.call(n,s))continue;const i=o[s];Array.isArray(i)?o[s]=i.map(c=>v(c)?w.call(c,e,t):c):v(i)&&(o[s]=w.call(i,e,t))}return o}function F(...e){if(a!=="test"&&a!=="development")return;const t=this,{__ref:n}=t;return console.groupCollapsed(t.key),e.length?e.forEach(o=>console.log(`%c${o}:
|
|
2
|
+
`,"font-weight: bold",t[o])):(console.log(n.path),t.keys().forEach(r=>console.log(`%c${r}:`,"font-weight: bold",t[r]))),console.log(t),console.groupEnd(t.key),t}function xt(...e){(a==="test"||a==="development")&&console.log(...e)}function yt(...e){(a==="test"||a==="development")&&console.warn(...e)}function O(...e){if(a==="test"||a==="development"){if(e[e.length-1]?.debugger)debugger;throw e[e.length-1]?.verbose&&F.call(this),new Error(...e)}}function vt(){const e=this,{key:t,parent:n}=e,{__children:o}=n.__ref,r=o.indexOf(t),s=o[r+1];return n[s]}function St(e){const t=e||this,{key:n,parent:o}=t,{__children:r}=o.__ref;if(!r)return;const s=r.indexOf(n);return o[r[s-1]]}function wt(e={}){const t=this;t.data||(t.data={}),t.data.varCaches||(t.data.varCaches={});const n=t.data.varCaches,o={};let r;for(const s in e)e[s]!==n[s]&&(r=!0,o[s]=e[s]);return{changed:s=>{if(!r)return;const i=s(o,b(n));for(const c in o)n[c]=o[c];return i},timeout:(s,i)=>{if(!r)return;const c=setTimeout(()=>{s(o),clearTimeout(c)},i)}}}function Ot(e,...t){const n=this.context,o=n.utils?.[e]||n.functions?.[e]||n.methods?.[e]||n.snippets?.[e];if(o&&!C(o))try{const r=o.call(this,...t);return r&&typeof r.then=="function"&&r.catch(s=>{O.call(this,s)}),r}catch(r){if(O.call(this,r),n?.strictMode)throw r}}const L="[smbls] getDB needs @symbo.ls/fetch, which the smbls embed bundle does not include: add @symbo.ls/fetch to the page's importmap (the runtime import then resolves) or use the full smbls bundle.",g=()=>import("@symbo.ls/fetch").catch(e=>{throw new Error(L,{cause:e})});async function Rt(){const e=this,t=e.context?.fetch;if(!t)return null;if(typeof t.select=="function"){if(!t.__authInitialized&&t.getSession){const{initAdapterAuth:r}=await g();await r(t,e.context)}return t}if(t.__resolved){if(!t.__resolved.__authInitialized&&t.__resolved.getSession){const{initAdapterAuth:r}=await g();await r(t.__resolved,e.context)}return t.__resolved}if(t.__resolving)return t.__resolving;const n=g().then(({resolveDb:r})=>r(t));t.__resolving=n;const o=await n;if(t.__resolved=o,e.context.fetch=o,delete t.__resolving,o?.getSession){const{initAdapterAuth:r}=await g();await r(o,e.context)}return o}function $t(e){const t=this,n=e||Q.useStateQuery||t.context?.useStateQuery;if(!n)return null;const o={};if(x(t,o),n===!0)return o;const r=H[n];return r?r(o):o}const x=(e,t)=>{const n=e.__ref;if(!n)return;const o=n.__state;o&&typeof o=="string"&&M(t,o);const r=n.__children;if(r)for(let c=0;c<r.length;c++){const l=e[r[c]];l&&l.__ref&&x(l,t)}const s=n.contentElementKey||"content",i=e[s];i&&i.__ref&&x(i,t)},M=(e,t)=>{const o=t.replaceAll("../","").replaceAll("~/","").split("/");let r=e;for(let s=0;s<o.length;s++){const i=o[s];s===o.length-1?r[i]||(r[i]=!0):(r[i]===!0&&(r[i]={}),r[i]||(r[i]={}),r=r[i])}},R=(e,t=0)=>{const n=" ".repeat(t),o=Object.entries(e);return o.length?o.map(([s,i])=>i===!0?`${n}${s}`:`${n}${s} {
|
|
3
|
+
${R(i,t+1)}
|
|
4
4
|
${n}}`).join(`
|
|
5
|
-
`):""},
|
|
6
|
-
${
|
|
7
|
-
}`,
|
|
5
|
+
`):""},J=e=>`{
|
|
6
|
+
${R(e,1)}
|
|
7
|
+
}`,G=e=>{const t={fields:{},include:[]},n=(o,r)=>{const s=[];for(const i in o)if(o[i]===!0)s.push(i);else{const c=r?`${r}.${i}`:i;t.include.push(c),n(o[i],c)}s.length&&(t.fields[r||"_root"]=s)};return n(e,""),t},B=e=>{const t=s=>{const i=[],c=[];for(const l in s)if(s[l]===!0)i.push(l);else{const f=t(s[l]),u=[];f.select&&u.push(`$select=${f.select}`),f.expand&&u.push(`$expand=${f.expand}`),c.push(u.length?`${l}(${u.join(";")})`:l)}return{select:i.length?i.join(","):"",expand:c.length?c.join(","):""}},{select:n,expand:o}=t(e),r=[];return n&&r.push(`$select=${n}`),o&&r.push(`$expand=${o}`),r.join("&")},V=(e,t)=>{const n=[],o=[],r=new Set,s=(u,h,m)=>{r.add(h),m&&o.push(`LEFT JOIN ${h} ON ${h}.${m}_id = ${m}.id`);for(const d in u)u[d]===!0?n.push(`${h}.${d}`):s(u[d],d,h)},i=Object.keys(e);i.length===1&&e[i[0]]!==!0?s(e[i[0]],i[0],null):s(e,"_root",null);const c=[...r][0]||"_root",l=n.length?n.join(", "):"*",f=o.length?`
|
|
8
8
|
`+o.join(`
|
|
9
9
|
`):"";return`SELECT ${l}
|
|
10
|
-
FROM ${c}${f}`},
|
|
10
|
+
FROM ${c}${f}`},z=e=>{const t=[],n=(o,r)=>{for(const s in o){const i=r?`${r}/${s}`:s;o[s]===!0?t.push(i):n(o[s],i)}};return n(e,""),t},H={graphql:J,"json-api":G,odata:B,sql:V,paths:z};function kt(e,t){return!!(k.has(e)||t?.context?.methods?.[e])}export{Ot as call,mt as defineSetter,O as error,st as get,lt as getChildren,gt as getContext,Rt as getDB,ft as getPath,$t as getQuery,ct as getRef,pt as getRoot,_t as getRootContext,dt as getRootData,ht as getRootState,kt as isMethod,I as keys,xt as log,nt as lookdown,ot as lookdownAll,et as lookup,vt as nextElement,T as parse,w as parseDeep,St as previousElement,at as promoteActiveRootState,rt as remove,ut as setActiveRootState,D as setNodeStyles,it as setProps,tt as spotByPath,wt as variables,F as verbose,yt as warn};
|
package/methods.js
CHANGED
|
@@ -509,20 +509,32 @@ export function call (fnKey, ...args) {
|
|
|
509
509
|
}
|
|
510
510
|
}
|
|
511
511
|
|
|
512
|
+
// The fetch plugin, loaded on demand — getDB needs it only when the context
|
|
513
|
+
// configures a database (`context.fetch`). A bundle that ships without
|
|
514
|
+
// plugins (the smbls embed IIFE keeps `@symbo.ls/fetch` external,
|
|
515
|
+
// FW-EMBED-BUNDLE-UNDER-64K-OR-JUSTIFY-72K-1) cannot resolve it, so the
|
|
516
|
+
// failure names the cause instead of a bare module-specifier error.
|
|
517
|
+
const FETCH_PLUGIN_MISSING_MESSAGE =
|
|
518
|
+
"[smbls] getDB needs @symbo.ls/fetch, which the smbls embed bundle does not include: " +
|
|
519
|
+
"add @symbo.ls/fetch to the page's importmap (the runtime import then resolves) or use the full smbls bundle."
|
|
520
|
+
const loadFetchPlugin = () => import('@symbo.ls/fetch').catch((err) => {
|
|
521
|
+
throw new Error(FETCH_PLUGIN_MISSING_MESSAGE, { cause: err })
|
|
522
|
+
})
|
|
523
|
+
|
|
512
524
|
export async function getDB () {
|
|
513
525
|
const element = this
|
|
514
526
|
const db = element.context?.fetch
|
|
515
527
|
if (!db) return null
|
|
516
528
|
if (typeof db.select === 'function') {
|
|
517
529
|
if (!db.__authInitialized && db.getSession) {
|
|
518
|
-
const { initAdapterAuth } = await
|
|
530
|
+
const { initAdapterAuth } = await loadFetchPlugin()
|
|
519
531
|
await initAdapterAuth(db, element.context)
|
|
520
532
|
}
|
|
521
533
|
return db
|
|
522
534
|
}
|
|
523
535
|
if (db.__resolved) {
|
|
524
536
|
if (!db.__resolved.__authInitialized && db.__resolved.getSession) {
|
|
525
|
-
const { initAdapterAuth } = await
|
|
537
|
+
const { initAdapterAuth } = await loadFetchPlugin()
|
|
526
538
|
await initAdapterAuth(db.__resolved, element.context)
|
|
527
539
|
}
|
|
528
540
|
return db.__resolved
|
|
@@ -530,7 +542,7 @@ export async function getDB () {
|
|
|
530
542
|
if (db.__resolving) return db.__resolving
|
|
531
543
|
// Set __resolving synchronously BEFORE the async import to prevent
|
|
532
544
|
// resolveAdapter() from starting a parallel resolveDb() during the yield
|
|
533
|
-
const resolvePromise =
|
|
545
|
+
const resolvePromise = loadFetchPlugin().then(({ resolveDb }) => resolveDb(db))
|
|
534
546
|
db.__resolving = resolvePromise
|
|
535
547
|
const resolved = await resolvePromise
|
|
536
548
|
db.__resolved = resolved
|
|
@@ -545,7 +557,7 @@ export async function getDB () {
|
|
|
545
557
|
// unwinds the entire fetch boot — silently breaking every consumer
|
|
546
558
|
// that depended on the adapter.
|
|
547
559
|
if (resolved?.getSession) {
|
|
548
|
-
const { initAdapterAuth } = await
|
|
560
|
+
const { initAdapterAuth } = await loadFetchPlugin()
|
|
549
561
|
await initAdapterAuth(resolved, element.context)
|
|
550
562
|
}
|
|
551
563
|
return resolved
|