@viamedici-spc/configurator-react 2.1.0-sessionUpdateErrorIsNotRemovedOnRetry-20250106091418 → 2.1.0-sessionUpdateErrorIsNotRemovedOnRetry-20250110085341

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/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("@viamedici-spc/configurator-ts"),l=require("@viamedici-spc/fp-ts-extensions"),g=require("jotai"),x=require("react"),gt=require("fp-ts-react-stable-hooks"),U=require("jotai/utils"),v=require("react/jsx-runtime"),At=require("dyna-guid"),X=require("jotai-effect"),ht=require("jotai-xstate"),F=require("xstate"),w="ConfigurationUninitialized";function I(t){return g.atom(e=>{try{const n=t(e,i=>{const o=e(i);if(o===w)throw w;return o});return n??w}catch(n){if(n===w)return w;throw n}})}function et(t){const{guardedConfigurationAtom:e,guardedAttributesAtom:n}=t;function i(o,s){const r=o==="all"?"all":l.pipe(o,l.RA.map(u=>typeof u=="string"?u:m.GlobalAttributeIdKeyBuilder(u)));return I((u,a)=>{if(r==="all")return l.pipe(e,a,f=>f.attributes,l.RM.values(l.Ord.trivial));const c=a(n);return l.pipe(r,l.RA.map(f=>u(c(f))),s?l.RA.filterMap(l.O.fromNullable):l.identity)})}return i}const st=globalThis.configuratorReactContexts??{AtomsContext:x.createContext(null),StoreContext:x.createContext(g.getDefaultStore())};globalThis.configuratorReactContexts=st;const ut=st.AtomsContext,ct=st.StoreContext,B=()=>x.useContext(ut),_=()=>x.useContext(ct);function rt(t,e,n){const i=l.Eq.tuple(l.Eq.eqNullable(l.Bool.Eq),n);return(o,...s)=>{const r=B(),u=_(),a=g.useSetAtom(r.selectors.subscriberAtom,{store:u}),c=gt.useStableMemo(()=>o??!0?e(r,...s):t(r,...s),[o,s],i),f=x.useMemo(()=>a(c),[a,c]);return x.useEffect(()=>()=>{f.unsubscribe()},[f]),g.useAtomValue(c,{store:u})}}function C(t,e){const n=rt(o=>t(o.selectors),o=>e(o.suspended),l.Eq.tuple());function i(o){return n(o)}return i}function Y(t,e){const n=rt((o,s)=>t(o.selectors)(s),(o,s)=>e(o.suspended)(s),l.Eq.tuple(l.Str.Eq));function i(o,s){const r=x.useMemo(()=>typeof o=="string"?o:m.GlobalAttributeIdKeyBuilder(o),[o]);return n(s,r)}return i}function pt(){const t={};return t.promise=new Promise((e,n)=>{t.resolve=e,t.reject=n}),t}function h(t){const e=U.selectAtom(t,(n,i)=>{if(n!==w)return(i==null?void 0:i.deferredPromise)!=null?(i.deferredPromise.resolve(n),{deferredPromise:null,result:i.deferredPromise.promise}):{deferredPromise:null,result:n};const o=(i==null?void 0:i.deferredPromise)??pt();return{deferredPromise:o,result:o.promise}});return g.atom(n=>n(e).result)}const bt=l.Eq.union().with(t=>typeof t=="string",m.globalAttributeIdKeyEq).with(t=>typeof t=="object",m.globalAttributeIdEq),St=l.Eq.union().with(t=>t==="all",l.Str.Eq).with(t=>Array.isArray(t),l.RA.getEq(bt)),yt=rt((t,e,n)=>et(t.selectors)(e,n),(t,e,n)=>h(et(t.selectors)(e,n)),l.Eq.tuple(St,l.Eq.eqNullable(l.Bool.Eq)));function Ct(t,e,n){const i=t=="all"?e:n,o=t=="all"?void 0:e;return yt(i,t,o)}const xt=Y(t=>t.choiceAttributeAtomFamily,t=>t.choiceAttributeAtomFamily),Et=Y(t=>t.numericAttributeAtomFamily,t=>t.numericAttributeAtomFamily),vt=Y(t=>t.booleanAttributeAtomFamily,t=>t.booleanAttributeAtomFamily),wt=Y(t=>t.componentAttributeAtomFamily,t=>t.componentAttributeAtomFamily);function Dt(){const{effects:t}=B(),{addSessionListenersEffect:e,cleanupAtomFamiliesEffect:n,atomSubscriberEffect:i,atomSubscriptionCleanupEffect:o}=t;return g.useAtom(e),g.useAtom(n),g.useAtom(i),g.useAtom(o),null}const Rt=30*1e3,It=WeakRef!=null?t=>new WeakRef(t):t=>({deref:()=>t});function kt(){return g.atom(l.RM.empty)}function Ft(t){return g.atom(null,(e,n,i)=>{const o=At.guid();m.Logger.debug("AtomSubscription:","Creating subscription with id",o);const r={unsubscribe:()=>{n(t.subscriptionsAtom,u=>{const a=u.get(i);if(a==null)return u;const c=new Map(a);c.delete(o);const f=new Map(u);return f.set(i,c),f})}};return n(t.subscriptionsAtom,u=>{const a=new Map(u.get(i)??l.RM.empty);a.set(o,It(r));const c=new Map(u);return c.set(i,a),c}),r})}function Mt(t){return X.atomEffect(e=>{const i=[...e(t.subscriptionsAtom).keys()];m.Logger.debug("AtomSubscriber:","There are",i.length,"Atoms to subscribe to.");for(const o of i)e(o)})}function qt(t){return X.atomEffect((e,n)=>{const i=setInterval(()=>{m.Logger.info("AtomSubscriptionCleanup:","Running cleanup");let o=!1;n(t.subscriptionsAtom,s=>{const r=new Map(s);for(const u of[...r.keys()]){const a=new Map(r.get(u)??l.RM.empty);for(const c of[...a.keys()]){const f=a.get(c);(f===void 0||f.deref()===void 0)&&(m.Logger.debug("AtomSubscriptionCleanup:","Deleting subscription",c,"because it got garbage collected."),a.delete(c),o=!0)}r.set(u,a),a.size===0&&(m.Logger.debug("AtomSubscriptionCleanup:","Delete Atom with 0 subscriptions."),r.delete(u),o=!0)}return m.Logger.debug("AtomSubscriptionCleanup:","There are",r.size,"Atoms with",[...r.values(),l.RA.flatten].length,"subscriptions left."),o?r:s})},Rt);return()=>{clearInterval(i)}})}const zt=F.fromPromise(({input:t})=>l.pipe(t.session,l.O.match(()=>()=>m.SessionFactory.createSession(t.sessionContext),e=>async()=>(await e.setSessionContext(t.sessionContext),e)),e=>l.TE.tryCatch(e,n=>n),l.TE.mapLeft(e=>({sessionContext:t.sessionContext,configurationError:e})))()),jt=F.setup({types:{context:{},events:{}},actors:{createOrUpdateSession:zt},guards:{shallProcess:({context:t})=>(t.sessionCreateOrUpdateError==null||t.sessionCreateOrUpdateError.sessionContext!==t.desiredSessionContext)&&(t.configurationSession==null&&t.desiredSessionContext!=null||t.configurationSession!=null&&t.configurationSession.getSessionContext()!==t.desiredSessionContext),shallDispose:({context:t})=>t.configurationSession!=null&&t.desiredSessionContext==null}}).createMachine({context:{desiredSessionContext:null,configurationSession:null,sessionCreateOrUpdateError:null},on:{Retry:{actions:[F.assign({sessionCreateOrUpdateError:()=>null})]},SessionContextChanged:{actions:[F.log("SessionContextChanged"),F.assign({desiredSessionContext:({event:t})=>t.sessionContext})]},Shutdown:{target:"#shutdown"}},initial:"Idle",states:{Idle:{always:[{target:"DisposeSession",guard:"shallDispose"},{target:"Processing",guard:"shallProcess"}]},Processing:{entry:[F.assign({sessionCreateOrUpdateError:()=>null})],invoke:{src:"createOrUpdateSession",input:({context:t})=>({sessionContext:t.desiredSessionContext,session:l.O.fromNullable(t.configurationSession)}),onDone:{target:"Idle",actions:[F.enqueueActions(({event:t,enqueue:e})=>{l.E.isRight(t.output)?e.assign({configurationSession:t.output.right}):e.assign({sessionCreateOrUpdateError:t.output.left})})]}}},DisposeSession:{always:[{target:"Idle",actions:[F.enqueueActions(({enqueue:t,context:e})=>{l.TE.tryCatch(async()=>{var n;return await((n=e.configurationSession)==null?void 0:n.close())},l.identity)(),t.assign({configurationSession:()=>null,sessionCreateOrUpdateError:()=>null})})]}]},Shutdown:{type:"final",id:"shutdown",entry:[F.enqueueActions(({context:t,enqueue:e})=>{t.configurationSession&&l.TE.tryCatch(async()=>{var n;return await((n=t.configurationSession)==null?void 0:n.close())},l.identity)(),e.assign({configurationSession:()=>null,desiredSessionContext:()=>null,sessionCreateOrUpdateError:()=>null})})]}}});function Pt(){return ht.atomWithMachine(jt)}function Tt(t){return g.atom(e=>e(t.sessionManagementMachineAtom).context.configurationSession)}function Ut(t){const e=g.atom((o,s)=>{var f;const r=o(t.sessionManagementMachineAtom),u=r.matches("Processing"),a=r.context.configurationSession!=null,c=(f=r.context.sessionCreateOrUpdateError)!=null&&f.configurationError?{...r.context.sessionCreateOrUpdateError.configurationError,retry:()=>{s.setSelf()}}:null;return{isProcessing:u,hasSession:a,error:c}},(o,s)=>{s(t.sessionManagementMachineAtom,{type:"Retry"})}),n=g.atom(o=>{const{hasSession:s,error:r,isProcessing:u}=o(e);return{isInitializing:!s&&u,error:!s&&r?r:void 0}}),i=g.atom(o=>{const{hasSession:s,error:r,isProcessing:u}=o(e);return{isUpdating:s&&u,error:s&&r?r:void 0}});return{sessionInitializationAtom:n,sessionUpdatingAtom:i}}const Lt=()=>U.atomFamily(()=>g.atom()),Vt=()=>g.atom(),Bt=()=>g.atom(),Ot=()=>g.atom(),Nt=()=>g.atom();function Qt(t,e){const{attributesAtom:n,configurationAtom:i,isSatisfiedAtom:o,canResetAtom:s}=t,{configurationSessionAtom:r}=e;return X.atomEffect((u,a)=>{const c=u(r);if(!c){a(i,void 0),a(o,void 0),a(n,void 0),a(s,void 0);return}const f=c.addConfigurationChangedListener((M,q)=>{m.Logger.debug("SessionSubscription:","Received ConfigurationChanged"),a(i,M),q.isSatisfied!=null&&a(o,q.isSatisfied);const W=u.peek(n),V=W??Lt();q.attributes.added.forEach(E=>{a(V(E.key),E)}),q.attributes.changed.forEach(E=>{a(V(E.key),E)}),q.attributes.removed.forEach(E=>{a(V(m.GlobalAttributeIdKeyBuilder(E)),void 0)}),W==null&&a(n,()=>V)}),K=c.addCanResetConfigurationChangedListener(M=>{m.Logger.debug("SessionSubscription:","Received CanResetConfigurationChanged"),a(s,M)});return()=>{f.unsubscribe(),K.unsubscribe()}})}function Z(t,e,n){const i=g.atom(o=>{const s=o(t);if(!s)return;const r=g.atom();return r.onMount=u=>{const a=e(s,(...c)=>{u(c)});return()=>{u(void 0),a.unsubscribe()}},r});return g.atom(o=>{const s=o(i);if(s==null)return;const r=o(s);if(r!=null)return n(...r)})}function _t(t){return Z(t,(e,n)=>e.addStoredConfigurationChangedListener(n),e=>e)}function Kt(t){return Z(t,(e,n)=>e.addDecisionsChangedListener(n),e=>e)}function Wt(t){return Z(t,(e,n)=>e.addDecisionsChangedListener(m.DecisionKind.Explicit,n),e=>e)}function $t(t){return Z(t,(e,n)=>e.addDecisionsChangedListener(m.DecisionKind.Implicit,n),e=>e)}const Jt=()=>({sessionManagementMachineAtom:Pt(),configurationAtom:Vt(),isSatisfiedAtom:Bt(),canResetAtom:Ot(),attributesAtom:Nt(),subscriptionsAtom:kt()});function Ht(t,e){return I((n,i)=>{const o=i(t);return{canResetConfiguration:i(e),resetConfiguration:o.resetConfiguration.bind(o)}})}function Gt(t){return I((e,n)=>{const i=n(t);return{explain:i.explain.bind(i),applySolution:i.applySolution.bind(i)}})}function Xt(t){return l.pipe(t.values,l.RM.values(l.Ord.trivial),l.RA.filter(e=>{var n;return((n=e.decision)==null?void 0:n.kind)===m.DecisionKind.Explicit}),l.RA.map(e=>({type:m.AttributeType.Choice,attributeId:t.id,choiceValueId:e.id,state:null})))}const S=Symbol.for("@ts-pattern/matcher"),lt=Symbol.for("@ts-pattern/isVariadic"),J="@ts-pattern/anonymous-select-key",nt=t=>!!(t&&typeof t=="object"),$=t=>t&&!!t[S],p=(t,e,n)=>{if($(t)){const i=t[S](),{matched:o,selections:s}=i.match(e);return o&&s&&Object.keys(s).forEach(r=>n(r,s[r])),o}if(nt(t)){if(!nt(e))return!1;if(Array.isArray(t)){if(!Array.isArray(e))return!1;let i=[],o=[],s=[];for(const r of t.keys()){const u=t[r];$(u)&&u[lt]?s.push(u):s.length?o.push(u):i.push(u)}if(s.length){if(s.length>1)throw new Error("Pattern error: Using `...P.array(...)` several times in a single pattern is not allowed.");if(e.length<i.length+o.length)return!1;const r=e.slice(0,i.length),u=o.length===0?[]:e.slice(-o.length),a=e.slice(i.length,o.length===0?1/0:-o.length);return i.every((c,f)=>p(c,r[f],n))&&o.every((c,f)=>p(c,u[f],n))&&(s.length===0||p(s[0],a,n))}return t.length===e.length&&t.every((r,u)=>p(r,e[u],n))}return Reflect.ownKeys(t).every(i=>{const o=t[i];return(i in e||$(s=o)&&s[S]().matcherType==="optional")&&p(o,e[i],n);var s})}return Object.is(e,t)},y=t=>{var e,n,i;return nt(t)?$(t)?(e=(n=(i=t[S]()).getSelectionKeys)==null?void 0:n.call(i))!=null?e:[]:Array.isArray(t)?N(t,y):N(Object.values(t),y):[]},N=(t,e)=>t.reduce((n,i)=>n.concat(e(i)),[]);function Yt(...t){if(t.length===1){const[e]=t;return n=>p(e,n,()=>{})}if(t.length===2){const[e,n]=t;return p(e,n,()=>{})}throw new Error(`isMatching wasn't given the right number of arguments: expected 1 or 2, received ${t.length}.`)}function b(t){return Object.assign(t,{optional:()=>at(t),and:e=>A(t,e),or:e=>mt(t,e),select:e=>e===void 0?Q(t):Q(e,t)})}function it(t){return Object.assign((e=>Object.assign(e,{[Symbol.iterator](){let n=0;const i=[{value:Object.assign(e,{[lt]:!0}),done:!1},{done:!0,value:void 0}];return{next:()=>{var o;return(o=i[n++])!=null?o:i.at(-1)}}}}))(t),{optional:()=>it(at(t)),select:e=>it(e===void 0?Q(t):Q(e,t))})}function at(t){return b({[S]:()=>({match:e=>{let n={};const i=(o,s)=>{n[o]=s};return e===void 0?(y(t).forEach(o=>i(o,void 0)),{matched:!0,selections:n}):{matched:p(t,e,i),selections:n}},getSelectionKeys:()=>y(t),matcherType:"optional"})})}const Zt=(t,e)=>{for(const n of t)if(!e(n))return!1;return!0},te=(t,e)=>{for(const[n,i]of t.entries())if(!e(i,n))return!1;return!0};function A(...t){return b({[S]:()=>({match:e=>{let n={};const i=(o,s)=>{n[o]=s};return{matched:t.every(o=>p(o,e,i)),selections:n}},getSelectionKeys:()=>N(t,y),matcherType:"and"})})}function mt(...t){return b({[S]:()=>({match:e=>{let n={};const i=(o,s)=>{n[o]=s};return N(t,y).forEach(o=>i(o,void 0)),{matched:t.some(o=>p(o,e,i)),selections:n}},getSelectionKeys:()=>N(t,y),matcherType:"or"})})}function d(t){return{[S]:()=>({match:e=>({matched:!!t(e)})})}}function Q(...t){const e=typeof t[0]=="string"?t[0]:void 0,n=t.length===2?t[1]:typeof t[0]=="string"?void 0:t[0];return b({[S]:()=>({match:i=>{let o={[e??J]:i};return{matched:n===void 0||p(n,i,(s,r)=>{o[s]=r}),selections:o}},getSelectionKeys:()=>[e??J].concat(n===void 0?[]:y(n))})})}function D(t){return typeof t=="number"}function z(t){return typeof t=="string"}function j(t){return typeof t=="bigint"}const dt=b(d(function(t){return!0})),ee=dt,P=t=>Object.assign(b(t),{startsWith:e=>{return P(A(t,(n=e,d(i=>z(i)&&i.startsWith(n)))));var n},endsWith:e=>{return P(A(t,(n=e,d(i=>z(i)&&i.endsWith(n)))));var n},minLength:e=>P(A(t,(n=>d(i=>z(i)&&i.length>=n))(e))),length:e=>P(A(t,(n=>d(i=>z(i)&&i.length===n))(e))),maxLength:e=>P(A(t,(n=>d(i=>z(i)&&i.length<=n))(e))),includes:e=>{return P(A(t,(n=e,d(i=>z(i)&&i.includes(n)))));var n},regex:e=>{return P(A(t,(n=e,d(i=>z(i)&&!!i.match(n)))));var n}}),ne=P(d(z)),R=t=>Object.assign(b(t),{between:(e,n)=>R(A(t,((i,o)=>d(s=>D(s)&&i<=s&&o>=s))(e,n))),lt:e=>R(A(t,(n=>d(i=>D(i)&&i<n))(e))),gt:e=>R(A(t,(n=>d(i=>D(i)&&i>n))(e))),lte:e=>R(A(t,(n=>d(i=>D(i)&&i<=n))(e))),gte:e=>R(A(t,(n=>d(i=>D(i)&&i>=n))(e))),int:()=>R(A(t,d(e=>D(e)&&Number.isInteger(e)))),finite:()=>R(A(t,d(e=>D(e)&&Number.isFinite(e)))),positive:()=>R(A(t,d(e=>D(e)&&e>0))),negative:()=>R(A(t,d(e=>D(e)&&e<0)))}),ie=R(d(D)),T=t=>Object.assign(b(t),{between:(e,n)=>T(A(t,((i,o)=>d(s=>j(s)&&i<=s&&o>=s))(e,n))),lt:e=>T(A(t,(n=>d(i=>j(i)&&i<n))(e))),gt:e=>T(A(t,(n=>d(i=>j(i)&&i>n))(e))),lte:e=>T(A(t,(n=>d(i=>j(i)&&i<=n))(e))),gte:e=>T(A(t,(n=>d(i=>j(i)&&i>=n))(e))),positive:()=>T(A(t,d(e=>j(e)&&e>0))),negative:()=>T(A(t,d(e=>j(e)&&e<0)))}),oe=T(d(j)),se=b(d(function(t){return typeof t=="boolean"})),re=b(d(function(t){return typeof t=="symbol"})),ae=b(d(function(t){return t==null})),ue=b(d(function(t){return t!=null}));var ce={__proto__:null,matcher:S,optional:at,array:function(...t){return it({[S]:()=>({match:e=>{if(!Array.isArray(e))return{matched:!1};if(t.length===0)return{matched:!0};const n=t[0];let i={};if(e.length===0)return y(n).forEach(s=>{i[s]=[]}),{matched:!0,selections:i};const o=(s,r)=>{i[s]=(i[s]||[]).concat([r])};return{matched:e.every(s=>p(n,s,o)),selections:i}},getSelectionKeys:()=>t.length===0?[]:y(t[0])})})},set:function(...t){return b({[S]:()=>({match:e=>{if(!(e instanceof Set))return{matched:!1};let n={};if(e.size===0)return{matched:!0,selections:n};if(t.length===0)return{matched:!0};const i=(s,r)=>{n[s]=(n[s]||[]).concat([r])},o=t[0];return{matched:Zt(e,s=>p(o,s,i)),selections:n}},getSelectionKeys:()=>t.length===0?[]:y(t[0])})})},map:function(...t){return b({[S]:()=>({match:e=>{if(!(e instanceof Map))return{matched:!1};let n={};if(e.size===0)return{matched:!0,selections:n};const i=(u,a)=>{n[u]=(n[u]||[]).concat([a])};if(t.length===0)return{matched:!0};var o;if(t.length===1)throw new Error(`\`P.map\` wasn't given enough arguments. Expected (key, value), received ${(o=t[0])==null?void 0:o.toString()}`);const[s,r]=t;return{matched:te(e,(u,a)=>{const c=p(s,a,i),f=p(r,u,i);return c&&f}),selections:n}},getSelectionKeys:()=>t.length===0?[]:[...y(t[0]),...y(t[1])]})})},intersection:A,union:mt,not:function(t){return b({[S]:()=>({match:e=>({matched:!p(t,e,()=>{})}),getSelectionKeys:()=>[],matcherType:"not"})})},when:d,select:Q,any:dt,_:ee,string:ne,number:ie,bigint:oe,boolean:se,symbol:re,nullish:ae,nonNullable:ue,instanceOf:function(t){return b(d(function(e){return n=>n instanceof e}(t)))},shape:function(t){return b(d(Yt(t)))}};class le extends Error{constructor(e){let n;try{n=JSON.stringify(e)}catch{n=e}super(`Pattern matching error: no pattern matches value ${n}`),this.input=void 0,this.input=e}}const ot={matched:!1,value:void 0};function H(t){return new G(t,ot)}class G{constructor(e,n){this.input=void 0,this.state=void 0,this.input=e,this.state=n}with(...e){if(this.state.matched)return this;const n=e[e.length-1],i=[e[0]];let o;e.length===3&&typeof e[1]=="function"?o=e[1]:e.length>2&&i.push(...e.slice(1,e.length-1));let s=!1,r={};const u=(c,f)=>{s=!0,r[c]=f},a=!i.some(c=>p(c,this.input,u))||o&&!o(this.input)?ot:{matched:!0,value:n(s?J in r?r[J]:r:this.input,this.input)};return new G(this.input,a)}when(e,n){if(this.state.matched)return this;const i=!!e(this.input);return new G(this.input,i?{matched:!0,value:n(this.input,this.input)}:ot)}otherwise(e){return this.state.matched?this.state.value:e(this.input)}exhaustive(){if(this.state.matched)return this.state.value;throw new le(this.input)}run(){return this.exhaustive()}returnType(){return this}}function L(t,e){var n=0,i,o;e=e||{};function s(){var r=i,u=arguments.length,a,c;t:for(;r;){if(r.args.length!==arguments.length){r=r.next;continue}for(c=0;c<u;c++)if(r.args[c]!==arguments[c]){r=r.next;continue t}return r!==i&&(r===o&&(o=r.prev),r.prev.next=r.next,r.next&&(r.next.prev=r.prev),r.next=i,r.prev=null,i.prev=r,i=r),r.val}for(a=new Array(u),c=0;c<u;c++)a[c]=arguments[c];return r={args:a,val:t.apply(null,a)},i?(i.prev=r,r.next=i):o=r,n===e.maxSize?(o=o.prev,o.next=null):n++,i=r,r.val}return s.clear=function(){i=null,o=null,n=0},s}function me(t,e,n){return tt(t,n,m.AttributeRefinements.choiceAttributeRefinement,m.ExplainQuestionSubject.choiceValue,(i,o,s)=>{const{makeDecision:r,makeManyDecisions:u}=s(e);return{makeDecision:(a,c)=>r({type:m.AttributeType.Choice,attributeId:i.id,choiceValueId:a,state:c}),clearDecisions:()=>l.pipe(i,Xt,l.O.fromPredicate(l.RA.isNonEmpty),l.O.match(()=>()=>Promise.resolve(),a=>l.pipe(()=>u(a,{type:"KeepExistingDecisions"}),l.T.map(l.constVoid))))(),isMultiSelect:L(()=>m.AttributeInterpreter.isChoiceAttributeMultiSelect(i)),getAllowedChoiceValues:L(()=>m.AttributeInterpreter.getAllowedChoiceValues(i)),getIncludedChoiceValues:L(()=>m.AttributeInterpreter.getIncludedChoiceValues(i)),getBlockedChoiceValues:L(()=>m.AttributeInterpreter.getBlockedChoiceValues(i)),isChoiceValueAllowed:L(a=>m.ChoiceValueInterpreter.isAllowed(a)),isChoiceValueBlocked:L(a=>m.ChoiceValueInterpreter.isBlocked(a))}})}function de(t,e,n){return tt(t,n,m.AttributeRefinements.numericAttributeRefinement,m.ExplainQuestionSubject.numeric,(i,o,s)=>{const{makeDecision:r}=s(e);return{makeDecision:u=>r({type:m.AttributeType.Numeric,attributeId:i.id,state:u})}})}function fe(t,e,n){return tt(t,n,m.AttributeRefinements.booleanAttributeRefinement,m.ExplainQuestionSubject.boolean,(i,o,s)=>{const{makeDecision:r}=s(e);return{makeDecision:u=>r({type:m.AttributeType.Boolean,attributeId:i.id,state:u})}})}function ge(t,e,n){return tt(t,n,m.AttributeRefinements.componentAttributeRefinement,m.ExplainQuestionSubject.component,(i,o,s)=>{const{makeDecision:r}=s(e);return{makeDecision:u=>r({type:m.AttributeType.Component,attributeId:i.id,state:u})}})}function tt(t,e,n,i,o){return U.atomFamily(s=>I((r,u)=>{const a=u(t),c=r(a(s));if(!c||!n(c))return;const{explain:f,applySolution:K}=u(e),M=o(c,r,u);return M===w?w:{attribute:c,isMandatory:L(()=>m.AttributeInterpreter.isMandatory(c)),explain:(q,W)=>{const V=H(q.question).with(m.ExplainQuestionType.whyIsNotSatisfied,()=>m.ExplainQuestionSubject.attribute).otherwise(()=>i),E={...q,subject:V,attributeId:c.id};return H(W).with("decisions",O=>f(E,O)).with("constraints",O=>f(E,O)).with("full",O=>f(E,O)).exhaustive()},applySolution:K,...M}}))}function ft(t,e){const n=U.selectAtom(t,l.identity,e.equals);return"write"in t?g.atom(i=>i(n),(i,o,...s)=>o(t,...s)):n}const Ae=l.Eq.struct({isInitializing:l.Bool.Eq,error:l.Eq.eqNullable(l.Eq.eqStrict)});function he(t,e,n,i,o,s){const r=[e,n,i,o,s],u=g.atom(a=>{const c=l.pipe(r,l.RA.every(M=>a(M)!==w)),f=a(t);return{isInitializing:!(!f.isInitializing&&c),error:f.error}});return ft(u,Ae)}const pe=l.Eq.struct({isUpdating:l.Bool.Eq,error:l.Eq.eqNullable(l.Eq.eqStrict)});function be(t){return ft(t,pe)}function Se(t){return I((e,n)=>{const i=n(t);return{storeConfiguration:i.storeConfiguration.bind(i),restoreConfiguration:i.restoreConfiguration.bind(i)}})}function ye(t,e){const n={question:m.ExplainQuestionType.whyIsNotSatisfied,subject:m.ExplainQuestionSubject.configuration};return I((i,o)=>{const s=o(t);return{isSatisfied:o(e),explain:u=>H(u).with("full",a=>s.explain(n,a)).with("decisions",a=>s.explain(n,a)).with("constraints",a=>s.explain(n,a)).exhaustive()}})}function Ce(t){return I((e,n)=>{const i=n(t);return{reinitializeSession:i.reinitialize.bind(i)}})}function xe(t){return I((e,n)=>{const i=n(t);return{scheduleTask:i.scheduleTask.bind(i)}})}function Ee(t){return I((e,n)=>{const i=n(t);return{getDecisions:i.getDecisions.bind(i)}})}function ve(t){return I((e,n)=>{const i=n(t);return{makeDecision:i.makeDecision.bind(i),makeManyDecisions:i.makeManyDecisions.bind(i)}})}function k(t){return g.atom(e=>e(t)??w)}function we(t){const{sessionInitializationAtom:e,sessionUpdatingAtom:n}=Ut(t),i=Tt(t),o={guardedConfigurationSessionAtom:k(i),guardedConfigurationAtom:k(t.configurationAtom),guardedIsSatisfiedAtom:k(t.isSatisfiedAtom),guardedCanResetAtom:k(t.canResetAtom),guardedAttributesAtom:k(t.attributesAtom),guardedStoredConfigurationAtom:k(_t(i)),guardedDecisionsAtom:k(Kt(i)),guardedExplicitDecisionsAtom:k(Wt(i)),guardedImplicitDecisionsAtom:k($t(i))},s=ve(o.guardedConfigurationSessionAtom),r=Gt(o.guardedConfigurationSessionAtom);return{...o,configurationSessionAtom:i,sessionInitializationAtom:e,sessionUpdatingAtom:n,configurationInitializationAtom:he(e,o.guardedConfigurationSessionAtom,o.guardedConfigurationAtom,o.guardedCanResetAtom,o.guardedIsSatisfiedAtom,o.guardedAttributesAtom),configurationUpdatingAtom:be(n),makeDecisionAtom:s,explainAtom:r,decisionQueriesAtom:Ee(o.guardedConfigurationSessionAtom),taskSchedulingAtom:xe(o.guardedConfigurationSessionAtom),configurationSatisfactionAtom:ye(o.guardedConfigurationSessionAtom,o.guardedIsSatisfiedAtom),configurationStoringAtom:Se(o.guardedConfigurationSessionAtom),configurationResetAtom:Ht(o.guardedConfigurationSessionAtom,o.guardedCanResetAtom),sessionReinitializationAtom:Ce(o.guardedConfigurationSessionAtom),choiceAttributeAtomFamily:me(o.guardedAttributesAtom,s,r),numericAttributeAtomFamily:de(o.guardedAttributesAtom,s,r),booleanAttributeAtomFamily:fe(o.guardedAttributesAtom,s,r),componentAttributeAtomFamily:ge(o.guardedAttributesAtom,s,r),subscriberAtom:Ft(t)}}const De=30*1e3;function Re(t,e,n){const i=[e.choiceAttributeAtomFamily,e.booleanAttributeAtomFamily,e.numericAttributeAtomFamily,e.componentAttributeAtomFamily,n.choiceAttributeAtomFamily,n.booleanAttributeAtomFamily,n.numericAttributeAtomFamily,n.componentAttributeAtomFamily];return X.atomEffect(o=>{o(t.configurationAtom);const s=o(t.attributesAtom);if(s==null)return;m.Logger.debug("Scheduling atomFamily cleanup");const r=setTimeout(()=>{m.Logger.debug("Cleaning up atomFamilies");for(const a of[...s.getParams()]){const c=s(a);o.peek(c)==null&&(m.Logger.debug("Removing attribute from attributes family because it is nullish",a),s.remove(a))}const u=[...s.getParams()];for(const a of i)for(const c of[...a.getParams()])u.includes(c)||a.remove(c)},De);return()=>{clearTimeout(r)}})}function Ie(t,e,n){return{addSessionListenersEffect:Qt(t,e),cleanupAtomFamiliesEffect:Re(t,e,n),atomSubscriberEffect:Mt(t),atomSubscriptionCleanupEffect:qt(t)}}function ke(t){return{configurationAtom:h(t.guardedConfigurationAtom),configurationStoringAtom:h(t.configurationStoringAtom),configurationSatisfactionAtom:h(t.configurationSatisfactionAtom),storedConfigurationAtom:h(t.guardedStoredConfigurationAtom),decisionsAtom:h(t.guardedDecisionsAtom),explicitDecisionsAtom:h(t.guardedExplicitDecisionsAtom),implicitDecisionsAtom:h(t.guardedImplicitDecisionsAtom),makeDecisionAtom:h(t.makeDecisionAtom),decisionQueriesAtom:h(t.decisionQueriesAtom),configurationResetAtom:h(t.configurationResetAtom),sessionReinitializationAtom:h(t.sessionReinitializationAtom),explainAtom:h(t.explainAtom),taskSchedulingAtom:h(t.taskSchedulingAtom),choiceAttributeAtomFamily:U.atomFamily(e=>h(t.choiceAttributeAtomFamily(e))),numericAttributeAtomFamily:U.atomFamily(e=>h(t.numericAttributeAtomFamily(e))),booleanAttributeAtomFamily:U.atomFamily(e=>h(t.booleanAttributeAtomFamily(e))),componentAttributeAtomFamily:U.atomFamily(e=>h(t.componentAttributeAtomFamily(e)))}}function Fe(){const t=Jt(),e=we(t),n=ke(e);return{primitives:t,selectors:e,suspended:n,effects:Ie(t,e,n)}}const Me="The session context is null or undefined. This will dispose the session that may exist. If this was not intended, make sure you pass valid session context data.";function qe(t){const{primitives:{sessionManagementMachineAtom:e}}=B(),n=g.useSetAtom(e);return x.useEffect(()=>{n({type:"SessionContextChanged",sessionContext:t.sessionContext}),t.sessionContext||console.warn(Me)},[t.sessionContext]),x.useEffect(()=>()=>{n({type:"Shutdown"})},[]),null}function ze(t){const e=x.useMemo(()=>Fe(),[]);return v.jsx(v.Fragment,{children:v.jsx(ut.Provider,{value:e,children:v.jsx(je,{jotaiStore:t.jotaiStore,children:v.jsxs(Pe,{children:[v.jsx(qe,{sessionContext:t.sessionContext}),v.jsx(Dt,{}),t.children]})})})})}function je(t){return t.jotaiStore?v.jsx(ct.Provider,{value:t.jotaiStore,children:t.children}):v.jsx(v.Fragment,{children:t.children})}function Pe(t){const e=_();return v.jsx(g.Provider,{store:e,children:t.children})}function Te(){const{selectors:{configurationInitializationAtom:t}}=B(),e=_();return g.useAtomValue(t,{store:e})}function Ue(){const{selectors:{configurationUpdatingAtom:t}}=B(),e=_();return g.useAtomValue(t,{store:e})}const Le=C(t=>t.explainAtom,t=>t.explainAtom),Ve=C(t=>t.guardedConfigurationAtom,t=>t.configurationAtom),Be=C(t=>t.configurationSatisfactionAtom,t=>t.configurationSatisfactionAtom),Oe=C(t=>t.configurationStoringAtom,t=>t.configurationStoringAtom),Ne=C(t=>t.configurationResetAtom,t=>t.configurationResetAtom),Qe=C(t=>t.sessionReinitializationAtom,t=>t.sessionReinitializationAtom),_e=C(t=>t.taskSchedulingAtom,t=>t.taskSchedulingAtom),Ke=C(t=>t.guardedStoredConfigurationAtom,t=>t.storedConfigurationAtom),We=C(t=>t.makeDecisionAtom,t=>t.makeDecisionAtom),$e=C(t=>t.decisionQueriesAtom,t=>t.decisionQueriesAtom),Je=C(t=>t.guardedDecisionsAtom,t=>t.decisionsAtom),He=C(t=>t.guardedExplicitDecisionsAtom,t=>t.explicitDecisionsAtom),Ge=C(t=>t.guardedImplicitDecisionsAtom,t=>t.implicitDecisionsAtom);function Xe(t,e){const n=typeof t=="string"?t:void 0,i=typeof t=="boolean"?t:e,o=x.useMemo(()=>H(n).returnType().with(ce.nullish,()=>Je).with(m.DecisionKind.Explicit,()=>He).with(m.DecisionKind.Implicit,()=>Ge).exhaustive(),[n]);return i===!1?o(!1):o()}function Ye(){const{selectors:t}=B();return x.useMemo(()=>({getConfigurationInitializationAtom:t.configurationInitializationAtom,getConfigurationUpdatingAtom:t.configurationUpdatingAtom,createAttributesAtom:et(t),getChoiceAttributeAtomFamily:t.choiceAttributeAtomFamily,getNumericAttributeAtomFamily:t.numericAttributeAtomFamily,getBooleanAttributeAtomFamily:t.booleanAttributeAtomFamily,getComponentAttributeAtomFamily:t.componentAttributeAtomFamily,getConfigurationAtom:t.guardedConfigurationAtom,getConfigurationSatisfactionAtom:t.configurationSatisfactionAtom,getConfigurationStoringAtom:t.configurationStoringAtom,getMakeDecisionAtom:t.makeDecisionAtom,getDecisionQueriesAtom:t.decisionQueriesAtom,getConfigurationResetAtom:t.configurationResetAtom,getSessionReinitializationAtom:t.sessionReinitializationAtom,getExplainAtom:t.explainAtom,getTaskSchedulingAtom:t.taskSchedulingAtom,getStoredConfigurationAtom:t.guardedStoredConfigurationAtom,getDecisionsAtom:t.guardedDecisionsAtom,getExplicitDecisionsAtom:t.guardedExplicitDecisionsAtom,getImplicitDecisionsAtom:t.guardedImplicitDecisionsAtom}),[t])}exports.Configuration=ze;exports.ConfigurationUninitialized=w;exports.useAttributes=Ct;exports.useBooleanAttribute=vt;exports.useChoiceAttribute=xt;exports.useComponentAttribute=wt;exports.useConfiguration=Ve;exports.useConfigurationInitialization=Te;exports.useConfigurationReset=Ne;exports.useConfigurationSatisfaction=Be;exports.useConfigurationStoring=Oe;exports.useConfigurationUpdating=Ue;exports.useConfiguratorStore=_;exports.useDecisionQueries=$e;exports.useDecisions=Xe;exports.useExplain=Le;exports.useJotaiAtoms=Ye;exports.useMakeDecision=We;exports.useNumericAttribute=Et;exports.useSessionReinitialization=Qe;exports.useStoredConfiguration=Ke;exports.useTaskScheduling=_e;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const m=require("@viamedici-spc/configurator-ts"),l=require("@viamedici-spc/fp-ts-extensions"),g=require("jotai"),E=require("react"),gt=require("fp-ts-react-stable-hooks"),U=require("jotai/utils"),w=require("react/jsx-runtime"),At=require("dyna-guid"),X=require("jotai-effect"),ht=require("jotai-xstate"),F=require("xstate"),x="ConfigurationUninitialized";function I(t){return g.atom(e=>{try{const n=t(e,i=>{const o=e(i);if(o===x)throw x;return o});return n??x}catch(n){if(n===x)return x;throw n}})}function et(t){const{guardedConfigurationAtom:e,guardedAttributesAtom:n}=t;function i(o,s){const r=o==="all"?"all":l.pipe(o,l.RA.map(u=>typeof u=="string"?u:m.GlobalAttributeIdKeyBuilder(u)));return I((u,a)=>{if(r==="all")return l.pipe(e,a,f=>f.attributes,l.RM.values(l.Ord.trivial));const c=a(n);return l.pipe(r,l.RA.map(f=>u(c(f))),s?l.RA.filterMap(l.O.fromNullable):l.identity)})}return i}const st=globalThis.configuratorReactContexts??{AtomsContext:E.createContext(null),StoreContext:E.createContext(g.getDefaultStore())};globalThis.configuratorReactContexts=st;const ut=st.AtomsContext,ct=st.StoreContext,B=()=>E.useContext(ut),_=()=>E.useContext(ct);function rt(t,e,n){const i=l.Eq.tuple(l.Eq.eqNullable(l.Bool.Eq),n);return(o,...s)=>{const r=B(),u=_(),a=g.useSetAtom(r.selectors.subscriberAtom,{store:u}),c=gt.useStableMemo(()=>o??!0?e(r,...s):t(r,...s),[o,s],i),f=E.useMemo(()=>a(c),[a,c]);return E.useEffect(()=>()=>{f.unsubscribe()},[f]),g.useAtomValue(c,{store:u})}}function C(t,e){const n=rt(o=>t(o.selectors),o=>e(o.suspended),l.Eq.tuple());function i(o){return n(o)}return i}function Y(t,e){const n=rt((o,s)=>t(o.selectors)(s),(o,s)=>e(o.suspended)(s),l.Eq.tuple(l.Str.Eq));function i(o,s){const r=E.useMemo(()=>typeof o=="string"?o:m.GlobalAttributeIdKeyBuilder(o),[o]);return n(s,r)}return i}function pt(){const t={};return t.promise=new Promise((e,n)=>{t.resolve=e,t.reject=n}),t}function h(t){const e=U.selectAtom(t,(n,i)=>{if(n!==x)return(i==null?void 0:i.deferredPromise)!=null?(i.deferredPromise.resolve(n),{deferredPromise:null,result:i.deferredPromise.promise}):{deferredPromise:null,result:n};const o=(i==null?void 0:i.deferredPromise)??pt();return{deferredPromise:o,result:o.promise}});return g.atom(n=>n(e).result)}const bt=l.Eq.union().with(t=>typeof t=="string",m.globalAttributeIdKeyEq).with(t=>typeof t=="object",m.globalAttributeIdEq),St=l.Eq.union().with(t=>t==="all",l.Str.Eq).with(t=>Array.isArray(t),l.RA.getEq(bt)),yt=rt((t,e,n)=>et(t.selectors)(e,n),(t,e,n)=>h(et(t.selectors)(e,n)),l.Eq.tuple(St,l.Eq.eqNullable(l.Bool.Eq)));function Ct(t,e,n){const i=t=="all"?e:n,o=t=="all"?void 0:e;return yt(i,t,o)}const xt=Y(t=>t.choiceAttributeAtomFamily,t=>t.choiceAttributeAtomFamily),Et=Y(t=>t.numericAttributeAtomFamily,t=>t.numericAttributeAtomFamily),vt=Y(t=>t.booleanAttributeAtomFamily,t=>t.booleanAttributeAtomFamily),wt=Y(t=>t.componentAttributeAtomFamily,t=>t.componentAttributeAtomFamily);function Dt(){const{effects:t}=B(),{addSessionListenersEffect:e,cleanupAtomFamiliesEffect:n,atomSubscriberEffect:i,atomSubscriptionCleanupEffect:o}=t;return g.useAtom(e),g.useAtom(n),g.useAtom(i),g.useAtom(o),null}const Rt=30*1e3,It=WeakRef!=null?t=>new WeakRef(t):t=>({deref:()=>t});function kt(){return g.atom(l.RM.empty)}function Ft(t){return g.atom(null,(e,n,i)=>{const o=At.guid();m.Logger.debug("AtomSubscription:","Creating subscription with id",o);const r={unsubscribe:()=>{n(t.subscriptionsAtom,u=>{const a=u.get(i);if(a==null)return u;const c=new Map(a);c.delete(o);const f=new Map(u);return f.set(i,c),f})}};return n(t.subscriptionsAtom,u=>{const a=new Map(u.get(i)??l.RM.empty);a.set(o,It(r));const c=new Map(u);return c.set(i,a),c}),r})}function Mt(t){return X.atomEffect(e=>{const i=[...e(t.subscriptionsAtom).keys()];m.Logger.debug("AtomSubscriber:","There are",i.length,"Atoms to subscribe to.");for(const o of i)e(o)})}function qt(t){return X.atomEffect((e,n)=>{const i=setInterval(()=>{m.Logger.info("AtomSubscriptionCleanup:","Running cleanup");let o=!1;n(t.subscriptionsAtom,s=>{const r=new Map(s);for(const u of[...r.keys()]){const a=new Map(r.get(u)??l.RM.empty);for(const c of[...a.keys()]){const f=a.get(c);(f===void 0||f.deref()===void 0)&&(m.Logger.debug("AtomSubscriptionCleanup:","Deleting subscription",c,"because it got garbage collected."),a.delete(c),o=!0)}r.set(u,a),a.size===0&&(m.Logger.debug("AtomSubscriptionCleanup:","Delete Atom with 0 subscriptions."),r.delete(u),o=!0)}return m.Logger.debug("AtomSubscriptionCleanup:","There are",r.size,"Atoms with",[...r.values(),l.RA.flatten].length,"subscriptions left."),o?r:s})},Rt);return()=>{clearInterval(i)}})}const zt=F.fromPromise(({input:t})=>l.pipe(t.session,l.O.match(()=>()=>m.SessionFactory.createSession(t.sessionContext),e=>async()=>(await e.setSessionContext(t.sessionContext),e)),e=>l.TE.tryCatch(e,n=>n),l.TE.mapLeft(e=>({sessionContext:t.sessionContext,configurationError:e})))()),jt=F.setup({types:{context:{},events:{}},actors:{createOrUpdateSession:zt},guards:{shallProcess:({context:t})=>(t.sessionCreateOrUpdateError==null||t.sessionCreateOrUpdateError.sessionContext!==t.desiredSessionContext)&&(t.configurationSession==null&&t.desiredSessionContext!=null||t.configurationSession!=null&&t.configurationSession.getSessionContext()!==t.desiredSessionContext),shallDispose:({context:t})=>t.configurationSession!=null&&t.desiredSessionContext==null}}).createMachine({context:{desiredSessionContext:null,configurationSession:null,sessionCreateOrUpdateError:null},on:{Retry:{actions:[F.assign({sessionCreateOrUpdateError:()=>null})]},SessionContextChanged:{actions:[F.log("SessionContextChanged"),F.assign({desiredSessionContext:({event:t})=>t.sessionContext})]},Shutdown:{target:"#shutdown"}},initial:"Idle",states:{Idle:{always:[{target:"DisposeSession",guard:"shallDispose"},{target:"Processing",guard:"shallProcess"}]},Processing:{entry:[F.assign({sessionCreateOrUpdateError:()=>null})],invoke:{src:"createOrUpdateSession",input:({context:t})=>({sessionContext:t.desiredSessionContext,session:l.O.fromNullable(t.configurationSession)}),onDone:{target:"Idle",actions:[F.enqueueActions(({event:t,enqueue:e})=>{l.E.isRight(t.output)?e.assign({configurationSession:t.output.right}):e.assign({sessionCreateOrUpdateError:t.output.left})})]}}},DisposeSession:{always:[{target:"Idle",actions:[F.enqueueActions(({enqueue:t,context:e})=>{l.TE.tryCatch(async()=>{var n;return await((n=e.configurationSession)==null?void 0:n.close())},l.identity)(),t.assign({configurationSession:()=>null,sessionCreateOrUpdateError:()=>null})})]}]},Shutdown:{type:"final",id:"shutdown",entry:[F.enqueueActions(({context:t,enqueue:e})=>{t.configurationSession&&l.TE.tryCatch(async()=>{var n;return await((n=t.configurationSession)==null?void 0:n.close())},l.identity)(),e.assign({configurationSession:()=>null,desiredSessionContext:()=>null,sessionCreateOrUpdateError:()=>null})})]}}});function Pt(){return ht.atomWithMachine(jt)}function Tt(t){return g.atom(e=>e(t.sessionManagementMachineAtom).context.configurationSession)}function Ut(t){const e=g.atom((o,s)=>{var f;const r=o(t.sessionManagementMachineAtom),u=r.matches("Processing"),a=r.context.configurationSession!=null,c=(f=r.context.sessionCreateOrUpdateError)!=null&&f.configurationError?{...r.context.sessionCreateOrUpdateError.configurationError,retry:()=>{s.setSelf()}}:null;return{isProcessing:u,hasSession:a,error:c}},(o,s)=>{s(t.sessionManagementMachineAtom,{type:"Retry"})}),n=g.atom(o=>{const{hasSession:s,error:r,isProcessing:u}=o(e);return{isInitializing:!s&&u,error:!s&&r?r:void 0}}),i=g.atom(o=>{const{hasSession:s,error:r,isProcessing:u}=o(e);return{isUpdating:s&&u,error:s&&r?r:void 0}});return{sessionInitializationAtom:n,sessionUpdatingAtom:i}}const Lt=()=>U.atomFamily(()=>g.atom()),Vt=()=>g.atom(),Bt=()=>g.atom(),Ot=()=>g.atom(),Nt=()=>g.atom();function Qt(t,e){const{attributesAtom:n,configurationAtom:i,isSatisfiedAtom:o,canResetAtom:s}=t,{configurationSessionAtom:r}=e;return X.atomEffect((u,a)=>{const c=u(r);if(!c){a(i,void 0),a(o,void 0),a(n,void 0),a(s,void 0);return}const f=c.addConfigurationChangedListener((M,q)=>{m.Logger.debug("SessionSubscription:","Received ConfigurationChanged"),a(i,M),q.isSatisfied!=null&&a(o,q.isSatisfied);const W=u.peek(n),V=W??Lt();q.attributes.added.forEach(v=>{a(V(v.key),v)}),q.attributes.changed.forEach(v=>{a(V(v.key),v)}),q.attributes.removed.forEach(v=>{a(V(m.GlobalAttributeIdKeyBuilder(v)),void 0)}),W==null&&a(n,()=>V)}),K=c.addCanResetConfigurationChangedListener(M=>{m.Logger.debug("SessionSubscription:","Received CanResetConfigurationChanged"),a(s,M)});return()=>{f.unsubscribe(),K.unsubscribe()}})}function Z(t,e,n){const i=g.atom(o=>{const s=o(t);if(!s)return;const r=g.atom();return r.onMount=u=>{const a=e(s,(...c)=>{u(c)});return()=>{u(void 0),a.unsubscribe()}},r});return g.atom(o=>{const s=o(i);if(s==null)return;const r=o(s);if(r!=null)return n(...r)})}function _t(t){return Z(t,(e,n)=>e.addStoredConfigurationChangedListener(n),e=>e)}function Kt(t){return Z(t,(e,n)=>e.addDecisionsChangedListener(n),e=>e)}function Wt(t){return Z(t,(e,n)=>e.addDecisionsChangedListener(m.DecisionKind.Explicit,n),e=>e)}function $t(t){return Z(t,(e,n)=>e.addDecisionsChangedListener(m.DecisionKind.Implicit,n),e=>e)}const Jt=()=>({sessionManagementMachineAtom:Pt(),configurationAtom:Vt(),isSatisfiedAtom:Bt(),canResetAtom:Ot(),attributesAtom:Nt(),subscriptionsAtom:kt()});function Ht(t,e){return I((n,i)=>{const o=i(t);return{canResetConfiguration:i(e),resetConfiguration:o.resetConfiguration.bind(o)}})}function Gt(t){return I((e,n)=>{const i=n(t);return{explain:i.explain.bind(i),applySolution:i.applySolution.bind(i)}})}function Xt(t){return l.pipe(t.values,l.RM.values(l.Ord.trivial),l.RA.filter(e=>{var n;return((n=e.decision)==null?void 0:n.kind)===m.DecisionKind.Explicit}),l.RA.map(e=>({type:m.AttributeType.Choice,attributeId:t.id,choiceValueId:e.id,state:null})))}const S=Symbol.for("@ts-pattern/matcher"),lt=Symbol.for("@ts-pattern/isVariadic"),J="@ts-pattern/anonymous-select-key",nt=t=>!!(t&&typeof t=="object"),$=t=>t&&!!t[S],p=(t,e,n)=>{if($(t)){const i=t[S](),{matched:o,selections:s}=i.match(e);return o&&s&&Object.keys(s).forEach(r=>n(r,s[r])),o}if(nt(t)){if(!nt(e))return!1;if(Array.isArray(t)){if(!Array.isArray(e))return!1;let i=[],o=[],s=[];for(const r of t.keys()){const u=t[r];$(u)&&u[lt]?s.push(u):s.length?o.push(u):i.push(u)}if(s.length){if(s.length>1)throw new Error("Pattern error: Using `...P.array(...)` several times in a single pattern is not allowed.");if(e.length<i.length+o.length)return!1;const r=e.slice(0,i.length),u=o.length===0?[]:e.slice(-o.length),a=e.slice(i.length,o.length===0?1/0:-o.length);return i.every((c,f)=>p(c,r[f],n))&&o.every((c,f)=>p(c,u[f],n))&&(s.length===0||p(s[0],a,n))}return t.length===e.length&&t.every((r,u)=>p(r,e[u],n))}return Reflect.ownKeys(t).every(i=>{const o=t[i];return(i in e||$(s=o)&&s[S]().matcherType==="optional")&&p(o,e[i],n);var s})}return Object.is(e,t)},y=t=>{var e,n,i;return nt(t)?$(t)?(e=(n=(i=t[S]()).getSelectionKeys)==null?void 0:n.call(i))!=null?e:[]:Array.isArray(t)?N(t,y):N(Object.values(t),y):[]},N=(t,e)=>t.reduce((n,i)=>n.concat(e(i)),[]);function Yt(...t){if(t.length===1){const[e]=t;return n=>p(e,n,()=>{})}if(t.length===2){const[e,n]=t;return p(e,n,()=>{})}throw new Error(`isMatching wasn't given the right number of arguments: expected 1 or 2, received ${t.length}.`)}function b(t){return Object.assign(t,{optional:()=>at(t),and:e=>A(t,e),or:e=>mt(t,e),select:e=>e===void 0?Q(t):Q(e,t)})}function it(t){return Object.assign((e=>Object.assign(e,{[Symbol.iterator](){let n=0;const i=[{value:Object.assign(e,{[lt]:!0}),done:!1},{done:!0,value:void 0}];return{next:()=>{var o;return(o=i[n++])!=null?o:i.at(-1)}}}}))(t),{optional:()=>it(at(t)),select:e=>it(e===void 0?Q(t):Q(e,t))})}function at(t){return b({[S]:()=>({match:e=>{let n={};const i=(o,s)=>{n[o]=s};return e===void 0?(y(t).forEach(o=>i(o,void 0)),{matched:!0,selections:n}):{matched:p(t,e,i),selections:n}},getSelectionKeys:()=>y(t),matcherType:"optional"})})}const Zt=(t,e)=>{for(const n of t)if(!e(n))return!1;return!0},te=(t,e)=>{for(const[n,i]of t.entries())if(!e(i,n))return!1;return!0};function A(...t){return b({[S]:()=>({match:e=>{let n={};const i=(o,s)=>{n[o]=s};return{matched:t.every(o=>p(o,e,i)),selections:n}},getSelectionKeys:()=>N(t,y),matcherType:"and"})})}function mt(...t){return b({[S]:()=>({match:e=>{let n={};const i=(o,s)=>{n[o]=s};return N(t,y).forEach(o=>i(o,void 0)),{matched:t.some(o=>p(o,e,i)),selections:n}},getSelectionKeys:()=>N(t,y),matcherType:"or"})})}function d(t){return{[S]:()=>({match:e=>({matched:!!t(e)})})}}function Q(...t){const e=typeof t[0]=="string"?t[0]:void 0,n=t.length===2?t[1]:typeof t[0]=="string"?void 0:t[0];return b({[S]:()=>({match:i=>{let o={[e??J]:i};return{matched:n===void 0||p(n,i,(s,r)=>{o[s]=r}),selections:o}},getSelectionKeys:()=>[e??J].concat(n===void 0?[]:y(n))})})}function D(t){return typeof t=="number"}function z(t){return typeof t=="string"}function j(t){return typeof t=="bigint"}const dt=b(d(function(t){return!0})),ee=dt,P=t=>Object.assign(b(t),{startsWith:e=>{return P(A(t,(n=e,d(i=>z(i)&&i.startsWith(n)))));var n},endsWith:e=>{return P(A(t,(n=e,d(i=>z(i)&&i.endsWith(n)))));var n},minLength:e=>P(A(t,(n=>d(i=>z(i)&&i.length>=n))(e))),length:e=>P(A(t,(n=>d(i=>z(i)&&i.length===n))(e))),maxLength:e=>P(A(t,(n=>d(i=>z(i)&&i.length<=n))(e))),includes:e=>{return P(A(t,(n=e,d(i=>z(i)&&i.includes(n)))));var n},regex:e=>{return P(A(t,(n=e,d(i=>z(i)&&!!i.match(n)))));var n}}),ne=P(d(z)),R=t=>Object.assign(b(t),{between:(e,n)=>R(A(t,((i,o)=>d(s=>D(s)&&i<=s&&o>=s))(e,n))),lt:e=>R(A(t,(n=>d(i=>D(i)&&i<n))(e))),gt:e=>R(A(t,(n=>d(i=>D(i)&&i>n))(e))),lte:e=>R(A(t,(n=>d(i=>D(i)&&i<=n))(e))),gte:e=>R(A(t,(n=>d(i=>D(i)&&i>=n))(e))),int:()=>R(A(t,d(e=>D(e)&&Number.isInteger(e)))),finite:()=>R(A(t,d(e=>D(e)&&Number.isFinite(e)))),positive:()=>R(A(t,d(e=>D(e)&&e>0))),negative:()=>R(A(t,d(e=>D(e)&&e<0)))}),ie=R(d(D)),T=t=>Object.assign(b(t),{between:(e,n)=>T(A(t,((i,o)=>d(s=>j(s)&&i<=s&&o>=s))(e,n))),lt:e=>T(A(t,(n=>d(i=>j(i)&&i<n))(e))),gt:e=>T(A(t,(n=>d(i=>j(i)&&i>n))(e))),lte:e=>T(A(t,(n=>d(i=>j(i)&&i<=n))(e))),gte:e=>T(A(t,(n=>d(i=>j(i)&&i>=n))(e))),positive:()=>T(A(t,d(e=>j(e)&&e>0))),negative:()=>T(A(t,d(e=>j(e)&&e<0)))}),oe=T(d(j)),se=b(d(function(t){return typeof t=="boolean"})),re=b(d(function(t){return typeof t=="symbol"})),ae=b(d(function(t){return t==null})),ue=b(d(function(t){return t!=null}));var ce={__proto__:null,matcher:S,optional:at,array:function(...t){return it({[S]:()=>({match:e=>{if(!Array.isArray(e))return{matched:!1};if(t.length===0)return{matched:!0};const n=t[0];let i={};if(e.length===0)return y(n).forEach(s=>{i[s]=[]}),{matched:!0,selections:i};const o=(s,r)=>{i[s]=(i[s]||[]).concat([r])};return{matched:e.every(s=>p(n,s,o)),selections:i}},getSelectionKeys:()=>t.length===0?[]:y(t[0])})})},set:function(...t){return b({[S]:()=>({match:e=>{if(!(e instanceof Set))return{matched:!1};let n={};if(e.size===0)return{matched:!0,selections:n};if(t.length===0)return{matched:!0};const i=(s,r)=>{n[s]=(n[s]||[]).concat([r])},o=t[0];return{matched:Zt(e,s=>p(o,s,i)),selections:n}},getSelectionKeys:()=>t.length===0?[]:y(t[0])})})},map:function(...t){return b({[S]:()=>({match:e=>{if(!(e instanceof Map))return{matched:!1};let n={};if(e.size===0)return{matched:!0,selections:n};const i=(u,a)=>{n[u]=(n[u]||[]).concat([a])};if(t.length===0)return{matched:!0};var o;if(t.length===1)throw new Error(`\`P.map\` wasn't given enough arguments. Expected (key, value), received ${(o=t[0])==null?void 0:o.toString()}`);const[s,r]=t;return{matched:te(e,(u,a)=>{const c=p(s,a,i),f=p(r,u,i);return c&&f}),selections:n}},getSelectionKeys:()=>t.length===0?[]:[...y(t[0]),...y(t[1])]})})},intersection:A,union:mt,not:function(t){return b({[S]:()=>({match:e=>({matched:!p(t,e,()=>{})}),getSelectionKeys:()=>[],matcherType:"not"})})},when:d,select:Q,any:dt,_:ee,string:ne,number:ie,bigint:oe,boolean:se,symbol:re,nullish:ae,nonNullable:ue,instanceOf:function(t){return b(d(function(e){return n=>n instanceof e}(t)))},shape:function(t){return b(d(Yt(t)))}};class le extends Error{constructor(e){let n;try{n=JSON.stringify(e)}catch{n=e}super(`Pattern matching error: no pattern matches value ${n}`),this.input=void 0,this.input=e}}const ot={matched:!1,value:void 0};function H(t){return new G(t,ot)}class G{constructor(e,n){this.input=void 0,this.state=void 0,this.input=e,this.state=n}with(...e){if(this.state.matched)return this;const n=e[e.length-1],i=[e[0]];let o;e.length===3&&typeof e[1]=="function"?o=e[1]:e.length>2&&i.push(...e.slice(1,e.length-1));let s=!1,r={};const u=(c,f)=>{s=!0,r[c]=f},a=!i.some(c=>p(c,this.input,u))||o&&!o(this.input)?ot:{matched:!0,value:n(s?J in r?r[J]:r:this.input,this.input)};return new G(this.input,a)}when(e,n){if(this.state.matched)return this;const i=!!e(this.input);return new G(this.input,i?{matched:!0,value:n(this.input,this.input)}:ot)}otherwise(e){return this.state.matched?this.state.value:e(this.input)}exhaustive(){if(this.state.matched)return this.state.value;throw new le(this.input)}run(){return this.exhaustive()}returnType(){return this}}function L(t,e){var n=0,i,o;e=e||{};function s(){var r=i,u=arguments.length,a,c;t:for(;r;){if(r.args.length!==arguments.length){r=r.next;continue}for(c=0;c<u;c++)if(r.args[c]!==arguments[c]){r=r.next;continue t}return r!==i&&(r===o&&(o=r.prev),r.prev.next=r.next,r.next&&(r.next.prev=r.prev),r.next=i,r.prev=null,i.prev=r,i=r),r.val}for(a=new Array(u),c=0;c<u;c++)a[c]=arguments[c];return r={args:a,val:t.apply(null,a)},i?(i.prev=r,r.next=i):o=r,n===e.maxSize?(o=o.prev,o.next=null):n++,i=r,r.val}return s.clear=function(){i=null,o=null,n=0},s}function me(t,e,n){return tt(t,n,m.AttributeRefinements.choiceAttributeRefinement,m.ExplainQuestionSubject.choiceValue,(i,o,s)=>{const{makeDecision:r,makeManyDecisions:u}=s(e);return{makeDecision:(a,c)=>r({type:m.AttributeType.Choice,attributeId:i.id,choiceValueId:a,state:c}),clearDecisions:()=>l.pipe(i,Xt,l.O.fromPredicate(l.RA.isNonEmpty),l.O.match(()=>()=>Promise.resolve(),a=>l.pipe(()=>u(a,{type:"KeepExistingDecisions"}),l.T.map(l.constVoid))))(),isMultiSelect:L(()=>m.AttributeInterpreter.isChoiceAttributeMultiSelect(i)),getAllowedChoiceValues:L(()=>m.AttributeInterpreter.getAllowedChoiceValues(i)),getIncludedChoiceValues:L(()=>m.AttributeInterpreter.getIncludedChoiceValues(i)),getBlockedChoiceValues:L(()=>m.AttributeInterpreter.getBlockedChoiceValues(i)),isChoiceValueAllowed:L(a=>m.ChoiceValueInterpreter.isAllowed(a)),isChoiceValueBlocked:L(a=>m.ChoiceValueInterpreter.isBlocked(a))}})}function de(t,e,n){return tt(t,n,m.AttributeRefinements.numericAttributeRefinement,m.ExplainQuestionSubject.numeric,(i,o,s)=>{const{makeDecision:r}=s(e);return{makeDecision:u=>r({type:m.AttributeType.Numeric,attributeId:i.id,state:u})}})}function fe(t,e,n){return tt(t,n,m.AttributeRefinements.booleanAttributeRefinement,m.ExplainQuestionSubject.boolean,(i,o,s)=>{const{makeDecision:r}=s(e);return{makeDecision:u=>r({type:m.AttributeType.Boolean,attributeId:i.id,state:u})}})}function ge(t,e,n){return tt(t,n,m.AttributeRefinements.componentAttributeRefinement,m.ExplainQuestionSubject.component,(i,o,s)=>{const{makeDecision:r}=s(e);return{makeDecision:u=>r({type:m.AttributeType.Component,attributeId:i.id,state:u})}})}function tt(t,e,n,i,o){return U.atomFamily(s=>I((r,u)=>{const a=u(t),c=r(a(s));if(!c||!n(c))return;const{explain:f,applySolution:K}=u(e),M=o(c,r,u);return M===x?x:{attribute:c,isMandatory:L(()=>m.AttributeInterpreter.isMandatory(c)),explain:(q,W)=>{const V=H(q.question).with(m.ExplainQuestionType.whyIsNotSatisfied,()=>m.ExplainQuestionSubject.attribute).otherwise(()=>i),v={...q,subject:V,attributeId:c.id};return H(W).with("decisions",O=>f(v,O)).with("constraints",O=>f(v,O)).with("full",O=>f(v,O)).exhaustive()},applySolution:K,...M}}))}function ft(t,e){const n=U.selectAtom(t,l.identity,e.equals);return"write"in t?g.atom(i=>i(n),(i,o,...s)=>o(t,...s)):n}const Ae=l.Eq.struct({isInitializing:l.Bool.Eq,error:l.Eq.eqNullable(l.Eq.eqStrict)});function he(t,e,n,i,o,s){const r=[e,n,i,o,s],u=g.atom(a=>{const c=l.pipe(r,l.RA.every(M=>a(M)!==x)),f=a(t);return{isInitializing:!(!f.isInitializing&&c),error:f.error}});return ft(u,Ae)}const pe=l.Eq.struct({isUpdating:l.Bool.Eq,error:l.Eq.eqNullable(l.Eq.eqStrict)});function be(t){return ft(t,pe)}function Se(t){return I((e,n)=>{const i=n(t);return{storeConfiguration:i.storeConfiguration.bind(i),restoreConfiguration:i.restoreConfiguration.bind(i)}})}function ye(t,e){const n={question:m.ExplainQuestionType.whyIsNotSatisfied,subject:m.ExplainQuestionSubject.configuration};return I((i,o)=>{const s=o(t);return{isSatisfied:o(e),explain:u=>H(u).with("full",a=>s.explain(n,a)).with("decisions",a=>s.explain(n,a)).with("constraints",a=>s.explain(n,a)).exhaustive()}})}function Ce(t){return I((e,n)=>{const i=n(t);return{reinitializeSession:i.reinitialize.bind(i)}})}function xe(t){return I((e,n)=>{const i=n(t);return{scheduleTask:i.scheduleTask.bind(i)}})}function Ee(t){return I((e,n)=>{const i=n(t);return{getDecisions:i.getDecisions.bind(i)}})}function ve(t){return I((e,n)=>{const i=n(t);return{makeDecision:i.makeDecision.bind(i),makeManyDecisions:i.makeManyDecisions.bind(i)}})}function k(t){return g.atom(e=>e(t)??x)}function we(t){const{sessionInitializationAtom:e,sessionUpdatingAtom:n}=Ut(t),i=Tt(t),o={guardedConfigurationSessionAtom:k(i),guardedConfigurationAtom:k(t.configurationAtom),guardedIsSatisfiedAtom:k(t.isSatisfiedAtom),guardedCanResetAtom:k(t.canResetAtom),guardedAttributesAtom:k(t.attributesAtom),guardedStoredConfigurationAtom:k(_t(i)),guardedDecisionsAtom:k(Kt(i)),guardedExplicitDecisionsAtom:k(Wt(i)),guardedImplicitDecisionsAtom:k($t(i))},s=ve(o.guardedConfigurationSessionAtom),r=Gt(o.guardedConfigurationSessionAtom);return{...o,configurationSessionAtom:i,sessionInitializationAtom:e,sessionUpdatingAtom:n,configurationInitializationAtom:he(e,o.guardedConfigurationSessionAtom,o.guardedConfigurationAtom,o.guardedCanResetAtom,o.guardedIsSatisfiedAtom,o.guardedAttributesAtom),configurationUpdatingAtom:be(n),makeDecisionAtom:s,explainAtom:r,decisionQueriesAtom:Ee(o.guardedConfigurationSessionAtom),taskSchedulingAtom:xe(o.guardedConfigurationSessionAtom),configurationSatisfactionAtom:ye(o.guardedConfigurationSessionAtom,o.guardedIsSatisfiedAtom),configurationStoringAtom:Se(o.guardedConfigurationSessionAtom),configurationResetAtom:Ht(o.guardedConfigurationSessionAtom,o.guardedCanResetAtom),sessionReinitializationAtom:Ce(o.guardedConfigurationSessionAtom),choiceAttributeAtomFamily:me(o.guardedAttributesAtom,s,r),numericAttributeAtomFamily:de(o.guardedAttributesAtom,s,r),booleanAttributeAtomFamily:fe(o.guardedAttributesAtom,s,r),componentAttributeAtomFamily:ge(o.guardedAttributesAtom,s,r),subscriberAtom:Ft(t)}}const De=30*1e3;function Re(t,e,n){const i=[e.choiceAttributeAtomFamily,e.booleanAttributeAtomFamily,e.numericAttributeAtomFamily,e.componentAttributeAtomFamily,n.choiceAttributeAtomFamily,n.booleanAttributeAtomFamily,n.numericAttributeAtomFamily,n.componentAttributeAtomFamily];return X.atomEffect(o=>{o(t.configurationAtom);const s=o(t.attributesAtom);if(s==null)return;m.Logger.debug("Scheduling atomFamily cleanup");const r=setTimeout(()=>{m.Logger.debug("Cleaning up atomFamilies");for(const a of[...s.getParams()]){const c=s(a);o.peek(c)==null&&(m.Logger.debug("Removing attribute from attributes family because it is nullish",a),s.remove(a))}const u=[...s.getParams()];for(const a of i)for(const c of[...a.getParams()])u.includes(c)||a.remove(c)},De);return()=>{clearTimeout(r)}})}function Ie(t,e,n){return{addSessionListenersEffect:Qt(t,e),cleanupAtomFamiliesEffect:Re(t,e,n),atomSubscriberEffect:Mt(t),atomSubscriptionCleanupEffect:qt(t)}}function ke(t){return{configurationAtom:h(t.guardedConfigurationAtom),configurationStoringAtom:h(t.configurationStoringAtom),configurationSatisfactionAtom:h(t.configurationSatisfactionAtom),storedConfigurationAtom:h(t.guardedStoredConfigurationAtom),decisionsAtom:h(t.guardedDecisionsAtom),explicitDecisionsAtom:h(t.guardedExplicitDecisionsAtom),implicitDecisionsAtom:h(t.guardedImplicitDecisionsAtom),makeDecisionAtom:h(t.makeDecisionAtom),decisionQueriesAtom:h(t.decisionQueriesAtom),configurationResetAtom:h(t.configurationResetAtom),sessionReinitializationAtom:h(t.sessionReinitializationAtom),explainAtom:h(t.explainAtom),taskSchedulingAtom:h(t.taskSchedulingAtom),choiceAttributeAtomFamily:U.atomFamily(e=>h(t.choiceAttributeAtomFamily(e))),numericAttributeAtomFamily:U.atomFamily(e=>h(t.numericAttributeAtomFamily(e))),booleanAttributeAtomFamily:U.atomFamily(e=>h(t.booleanAttributeAtomFamily(e))),componentAttributeAtomFamily:U.atomFamily(e=>h(t.componentAttributeAtomFamily(e)))}}function Fe(){const t=Jt(),e=we(t),n=ke(e);return{primitives:t,selectors:e,suspended:n,effects:Ie(t,e,n)}}const Me="The session context is null or undefined. This will dispose the session that may exist. If this was not intended, make sure you pass valid session context data.";function qe(t){const{primitives:{sessionManagementMachineAtom:e}}=B(),n=g.useSetAtom(e);return E.useEffect(()=>{n({type:"SessionContextChanged",sessionContext:t.sessionContext}),t.sessionContext||console.warn(Me)},[t.sessionContext]),E.useEffect(()=>()=>{n({type:"Shutdown"})},[]),null}function ze(t){const e=E.useMemo(()=>Fe(),[]);return w.jsx(w.Fragment,{children:w.jsx(ut.Provider,{value:e,children:w.jsx(je,{jotaiStore:t.jotaiStore,children:w.jsxs(Pe,{children:[w.jsx(qe,{sessionContext:t.sessionContext}),w.jsx(Dt,{}),t.children]})})})})}function je(t){return t.jotaiStore?w.jsx(ct.Provider,{value:t.jotaiStore,children:t.children}):w.jsx(w.Fragment,{children:t.children})}function Pe(t){const e=_();return w.jsx(g.Provider,{store:e,children:t.children})}function Te(){const{selectors:{configurationInitializationAtom:t}}=B(),e=_();return g.useAtomValue(t,{store:e})}function Ue(){const{selectors:{configurationUpdatingAtom:t}}=B(),e=_();return g.useAtomValue(t,{store:e})}const Le=C(t=>t.explainAtom,t=>t.explainAtom),Ve=C(t=>t.guardedConfigurationAtom,t=>t.configurationAtom),Be=C(t=>t.configurationSatisfactionAtom,t=>t.configurationSatisfactionAtom),Oe=C(t=>t.configurationStoringAtom,t=>t.configurationStoringAtom),Ne=C(t=>t.configurationResetAtom,t=>t.configurationResetAtom),Qe=C(t=>t.sessionReinitializationAtom,t=>t.sessionReinitializationAtom),_e=C(t=>t.taskSchedulingAtom,t=>t.taskSchedulingAtom),Ke=C(t=>t.guardedStoredConfigurationAtom,t=>t.storedConfigurationAtom),We=C(t=>t.makeDecisionAtom,t=>t.makeDecisionAtom),$e=C(t=>t.decisionQueriesAtom,t=>t.decisionQueriesAtom),Je=C(t=>t.guardedDecisionsAtom,t=>t.decisionsAtom),He=C(t=>t.guardedExplicitDecisionsAtom,t=>t.explicitDecisionsAtom),Ge=C(t=>t.guardedImplicitDecisionsAtom,t=>t.implicitDecisionsAtom);function Xe(t,e){const n=typeof t=="string"?t:void 0,i=typeof t=="boolean"?t:e,o=E.useMemo(()=>H(n).returnType().with(ce.nullish,()=>Je).with(m.DecisionKind.Explicit,()=>He).with(m.DecisionKind.Implicit,()=>Ge).exhaustive(),[n]);return i===!1?o(!1):o()}function Ye(){const{selectors:t}=B();return E.useMemo(()=>({getConfigurationInitializationAtom:t.configurationInitializationAtom,getConfigurationUpdatingAtom:t.configurationUpdatingAtom,createAttributesAtom:et(t),getChoiceAttributeAtomFamily:t.choiceAttributeAtomFamily,getNumericAttributeAtomFamily:t.numericAttributeAtomFamily,getBooleanAttributeAtomFamily:t.booleanAttributeAtomFamily,getComponentAttributeAtomFamily:t.componentAttributeAtomFamily,getConfigurationAtom:t.guardedConfigurationAtom,getConfigurationSatisfactionAtom:t.configurationSatisfactionAtom,getConfigurationStoringAtom:t.configurationStoringAtom,getMakeDecisionAtom:t.makeDecisionAtom,getDecisionQueriesAtom:t.decisionQueriesAtom,getConfigurationResetAtom:t.configurationResetAtom,getSessionReinitializationAtom:t.sessionReinitializationAtom,getExplainAtom:t.explainAtom,getTaskSchedulingAtom:t.taskSchedulingAtom,getStoredConfigurationAtom:t.guardedStoredConfigurationAtom,getDecisionsAtom:t.guardedDecisionsAtom,getExplicitDecisionsAtom:t.guardedExplicitDecisionsAtom,getImplicitDecisionsAtom:t.guardedImplicitDecisionsAtom}),[t])}function Ze(){return t=>t!==x}exports.Configuration=ze;exports.ConfigurationUninitialized=x;exports.isInitialized=Ze;exports.useAttributes=Ct;exports.useBooleanAttribute=vt;exports.useChoiceAttribute=xt;exports.useComponentAttribute=wt;exports.useConfiguration=Ve;exports.useConfigurationInitialization=Te;exports.useConfigurationReset=Ne;exports.useConfigurationSatisfaction=Be;exports.useConfigurationStoring=Oe;exports.useConfigurationUpdating=Ue;exports.useConfiguratorStore=_;exports.useDecisionQueries=$e;exports.useDecisions=Xe;exports.useExplain=Le;exports.useJotaiAtoms=Ye;exports.useMakeDecision=We;exports.useNumericAttribute=Et;exports.useSessionReinitialization=Qe;exports.useStoredConfiguration=Ke;exports.useTaskScheduling=_e;
package/dist/index.d.ts CHANGED
@@ -89,6 +89,16 @@ declare type ExplainQuestionParam<T extends WhyIsStateNotPossible> = SimplifiedE
89
89
  */
90
90
  export declare type GuardedAtom<Value> = Atom<NonNullable<Value> | ConfigurationUninitialized>;
91
91
 
92
+ /**
93
+ * Creates a type guard that checks if the given value is initialized.
94
+ *
95
+ * This type guard is useful for narrowing a union type containing {@link ConfigurationUninitialized}
96
+ * to only include the initialized type `T`.
97
+ *
98
+ * @returns A type guard function that returns `true` if the value is of type `T`.
99
+ */
100
+ export declare function isInitialized<T>(): (v: T | ConfigurationUninitialized) => v is T;
101
+
92
102
  declare type SimplifiedExplainQuestion<T extends ExplainQuestion> = Omit<T, "attributeId" | "subject">;
93
103
 
94
104
  declare type UseAttributeExplainResult<T extends WhyIsStateNotPossible> = {
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { GlobalAttributeIdKeyBuilder as yt, globalAttributeIdKeyEq as Nt, globalAttributeIdEq as Wt, Logger as x, SessionFactory as Ot, DecisionKind as L, AttributeType as J, ExplainQuestionSubject as N, AttributeRefinements as rt, AttributeInterpreter as B, ExplainQuestionType as It, ChoiceValueInterpreter as Et } from "@viamedici-spc/configurator-ts";
1
+ import { GlobalAttributeIdKeyBuilder as yt, globalAttributeIdKeyEq as Nt, globalAttributeIdEq as Wt, Logger as v, SessionFactory as Ot, DecisionKind as L, AttributeType as J, ExplainQuestionSubject as N, AttributeRefinements as st, AttributeInterpreter as B, ExplainQuestionType as It, ChoiceValueInterpreter as Et } from "@viamedici-spc/configurator-ts";
2
2
  import { pipe as j, RA as k, RM as H, Ord as kt, O as K, identity as et, Eq as b, Bool as at, Str as Rt, TE as nt, E as Bt, T as Lt, constVoid as Kt } from "@viamedici-spc/fp-ts-extensions";
3
3
  import { atom as f, getDefaultStore as Qt, useSetAtom as Ft, useAtomValue as Ct, useAtom as G, Provider as $t } from "jotai";
4
4
  import { createContext as Dt, useContext as Mt, useMemo as X, useEffect as At } from "react";
@@ -9,39 +9,39 @@ import { guid as Xt } from "dyna-guid";
9
9
  import { atomEffect as ut } from "jotai-effect";
10
10
  import { atomWithMachine as Yt } from "jotai-xstate";
11
11
  import { fromPromise as Zt, setup as Gt, assign as ft, log as te, enqueueActions as gt } from "xstate";
12
- const E = "ConfigurationUninitialized";
12
+ const x = "ConfigurationUninitialized";
13
13
  function D(t) {
14
14
  return f((e) => {
15
15
  try {
16
16
  const n = t(e, (i) => {
17
17
  const o = e(i);
18
- if (o === E)
19
- throw E;
18
+ if (o === x)
19
+ throw x;
20
20
  return o;
21
21
  });
22
- return n ?? E;
22
+ return n ?? x;
23
23
  } catch (n) {
24
- if (n === E)
25
- return E;
24
+ if (n === x)
25
+ return x;
26
26
  throw n;
27
27
  }
28
28
  });
29
29
  }
30
30
  function ht(t) {
31
31
  const { guardedConfigurationAtom: e, guardedAttributesAtom: n } = t;
32
- function i(o, s) {
33
- const r = o === "all" ? "all" : j(
32
+ function i(o, r) {
33
+ const s = o === "all" ? "all" : j(
34
34
  o,
35
35
  k.map((u) => typeof u == "string" ? u : yt(u))
36
36
  );
37
37
  return D((u, a) => {
38
- if (r === "all")
38
+ if (s === "all")
39
39
  return j(e, a, (m) => m.attributes, H.values(kt.trivial));
40
40
  const c = a(n);
41
41
  return j(
42
- r,
42
+ s,
43
43
  k.map((m) => u(c(m))),
44
- s ? k.filterMap(K.fromNullable) : et
44
+ r ? k.filterMap(K.fromNullable) : et
45
45
  );
46
46
  });
47
47
  }
@@ -55,8 +55,8 @@ globalThis.configuratorReactContexts = xt;
55
55
  const Ut = xt.AtomsContext, qt = xt.StoreContext, W = () => Mt(Ut), ct = () => Mt(qt);
56
56
  function vt(t, e, n) {
57
57
  const i = b.tuple(b.eqNullable(at.Eq), n);
58
- return (o, ...s) => {
59
- const r = W(), u = ct(), a = Ft(r.selectors.subscriberAtom, { store: u }), c = Jt(() => o ?? !0 ? e(r, ...s) : t(r, ...s), [o, s], i), m = X(() => a(c), [a, c]);
58
+ return (o, ...r) => {
59
+ const s = W(), u = ct(), a = Ft(s.selectors.subscriberAtom, { store: u }), c = Jt(() => o ?? !0 ? e(s, ...r) : t(s, ...r), [o, r], i), m = X(() => a(c), [a, c]);
60
60
  return At(() => () => {
61
61
  m.unsubscribe();
62
62
  }, [m]), Ct(c, { store: u });
@@ -70,10 +70,10 @@ function y(t, e) {
70
70
  return i;
71
71
  }
72
72
  function lt(t, e) {
73
- const n = vt((o, s) => t(o.selectors)(s), (o, s) => e(o.suspended)(s), b.tuple(Rt.Eq));
74
- function i(o, s) {
75
- const r = X(() => typeof o == "string" ? o : yt(o), [o]);
76
- return n(s, r);
73
+ const n = vt((o, r) => t(o.selectors)(r), (o, r) => e(o.suspended)(r), b.tuple(Rt.Eq));
74
+ function i(o, r) {
75
+ const s = X(() => typeof o == "string" ? o : yt(o), [o]);
76
+ return n(r, s);
77
77
  }
78
78
  return i;
79
79
  }
@@ -85,7 +85,7 @@ function ee() {
85
85
  }
86
86
  function g(t) {
87
87
  const e = zt(t, (n, i) => {
88
- if (n !== E)
88
+ if (n !== x)
89
89
  return (i == null ? void 0 : i.deferredPromise) != null ? (i.deferredPromise.resolve(n), {
90
90
  deferredPromise: null,
91
91
  result: i.deferredPromise.promise
@@ -111,11 +111,11 @@ function Rn(t, e, n) {
111
111
  return oe(i, t, o);
112
112
  }
113
113
  const Fn = lt((t) => t.choiceAttributeAtomFamily, (t) => t.choiceAttributeAtomFamily), Mn = lt((t) => t.numericAttributeAtomFamily, (t) => t.numericAttributeAtomFamily), zn = lt((t) => t.booleanAttributeAtomFamily, (t) => t.booleanAttributeAtomFamily), Pn = lt((t) => t.componentAttributeAtomFamily, (t) => t.componentAttributeAtomFamily);
114
- function se() {
114
+ function re() {
115
115
  const { effects: t } = W(), { addSessionListenersEffect: e, cleanupAtomFamiliesEffect: n, atomSubscriberEffect: i, atomSubscriptionCleanupEffect: o } = t;
116
116
  return G(e), G(n), G(i), G(o), null;
117
117
  }
118
- const re = 30 * 1e3, ae = WeakRef != null ? (t) => new WeakRef(t) : (t) => ({
118
+ const se = 30 * 1e3, ae = WeakRef != null ? (t) => new WeakRef(t) : (t) => ({
119
119
  deref: () => t
120
120
  });
121
121
  function ue() {
@@ -124,8 +124,8 @@ function ue() {
124
124
  function ce(t) {
125
125
  return f(null, (e, n, i) => {
126
126
  const o = Xt();
127
- x.debug("AtomSubscription:", "Creating subscription with id", o);
128
- const r = {
127
+ v.debug("AtomSubscription:", "Creating subscription with id", o);
128
+ const s = {
129
129
  unsubscribe: () => {
130
130
  n(t.subscriptionsAtom, (u) => {
131
131
  const a = u.get(i);
@@ -140,16 +140,16 @@ function ce(t) {
140
140
  };
141
141
  return n(t.subscriptionsAtom, (u) => {
142
142
  const a = new Map(u.get(i) ?? H.empty);
143
- a.set(o, ae(r));
143
+ a.set(o, ae(s));
144
144
  const c = new Map(u);
145
145
  return c.set(i, a), c;
146
- }), r;
146
+ }), s;
147
147
  });
148
148
  }
149
149
  function le(t) {
150
150
  return ut((e) => {
151
151
  const i = [...e(t.subscriptionsAtom).keys()];
152
- x.debug("AtomSubscriber:", "There are", i.length, "Atoms to subscribe to.");
152
+ v.debug("AtomSubscriber:", "There are", i.length, "Atoms to subscribe to.");
153
153
  for (const o of i)
154
154
  e(o);
155
155
  });
@@ -157,21 +157,21 @@ function le(t) {
157
157
  function me(t) {
158
158
  return ut((e, n) => {
159
159
  const i = setInterval(() => {
160
- x.info("AtomSubscriptionCleanup:", "Running cleanup");
160
+ v.info("AtomSubscriptionCleanup:", "Running cleanup");
161
161
  let o = !1;
162
- n(t.subscriptionsAtom, (s) => {
163
- const r = new Map(s);
164
- for (const u of [...r.keys()]) {
165
- const a = new Map(r.get(u) ?? H.empty);
162
+ n(t.subscriptionsAtom, (r) => {
163
+ const s = new Map(r);
164
+ for (const u of [...s.keys()]) {
165
+ const a = new Map(s.get(u) ?? H.empty);
166
166
  for (const c of [...a.keys()]) {
167
167
  const m = a.get(c);
168
- (m === void 0 || m.deref() === void 0) && (x.debug("AtomSubscriptionCleanup:", "Deleting subscription", c, "because it got garbage collected."), a.delete(c), o = !0);
168
+ (m === void 0 || m.deref() === void 0) && (v.debug("AtomSubscriptionCleanup:", "Deleting subscription", c, "because it got garbage collected."), a.delete(c), o = !0);
169
169
  }
170
- r.set(u, a), a.size === 0 && (x.debug("AtomSubscriptionCleanup:", "Delete Atom with 0 subscriptions."), r.delete(u), o = !0);
170
+ s.set(u, a), a.size === 0 && (v.debug("AtomSubscriptionCleanup:", "Delete Atom with 0 subscriptions."), s.delete(u), o = !0);
171
171
  }
172
- return x.debug("AtomSubscriptionCleanup:", "There are", r.size, "Atoms with", [...r.values(), k.flatten].length, "subscriptions left."), o ? r : s;
172
+ return v.debug("AtomSubscriptionCleanup:", "There are", s.size, "Atoms with", [...s.values(), k.flatten].length, "subscriptions left."), o ? s : r;
173
173
  });
174
- }, re);
174
+ }, se);
175
175
  return () => {
176
176
  clearInterval(i);
177
177
  };
@@ -305,12 +305,12 @@ function Ae(t) {
305
305
  return f((e) => e(t.sessionManagementMachineAtom).context.configurationSession);
306
306
  }
307
307
  function he(t) {
308
- const e = f((o, s) => {
308
+ const e = f((o, r) => {
309
309
  var m;
310
- const r = o(t.sessionManagementMachineAtom), u = r.matches("Processing"), a = r.context.configurationSession != null, c = (m = r.context.sessionCreateOrUpdateError) != null && m.configurationError ? {
311
- ...r.context.sessionCreateOrUpdateError.configurationError,
310
+ const s = o(t.sessionManagementMachineAtom), u = s.matches("Processing"), a = s.context.configurationSession != null, c = (m = s.context.sessionCreateOrUpdateError) != null && m.configurationError ? {
311
+ ...s.context.sessionCreateOrUpdateError.configurationError,
312
312
  retry: () => {
313
- s.setSelf();
313
+ r.setSelf();
314
314
  }
315
315
  } : null;
316
316
  return {
@@ -318,19 +318,19 @@ function he(t) {
318
318
  hasSession: a,
319
319
  error: c
320
320
  };
321
- }, (o, s) => {
322
- s(t.sessionManagementMachineAtom, { type: "Retry" });
321
+ }, (o, r) => {
322
+ r(t.sessionManagementMachineAtom, { type: "Retry" });
323
323
  }), n = f((o) => {
324
- const { hasSession: s, error: r, isProcessing: u } = o(e);
324
+ const { hasSession: r, error: s, isProcessing: u } = o(e);
325
325
  return {
326
- isInitializing: !s && u,
327
- error: !s && r ? r : void 0
326
+ isInitializing: !r && u,
327
+ error: !r && s ? s : void 0
328
328
  };
329
329
  }), i = f((o) => {
330
- const { hasSession: s, error: r, isProcessing: u } = o(e);
330
+ const { hasSession: r, error: s, isProcessing: u } = o(e);
331
331
  return {
332
- isUpdating: s && u,
333
- error: s && r ? r : void 0
332
+ isUpdating: r && u,
333
+ error: r && s ? s : void 0
334
334
  };
335
335
  });
336
336
  return {
@@ -340,15 +340,15 @@ function he(t) {
340
340
  }
341
341
  const pe = () => _(() => f()), be = () => f(), Se = () => f(), ye = () => f(), Ce = () => f();
342
342
  function xe(t, e) {
343
- const { attributesAtom: n, configurationAtom: i, isSatisfiedAtom: o, canResetAtom: s } = t, { configurationSessionAtom: r } = e;
343
+ const { attributesAtom: n, configurationAtom: i, isSatisfiedAtom: o, canResetAtom: r } = t, { configurationSessionAtom: s } = e;
344
344
  return ut((u, a) => {
345
- const c = u(r);
345
+ const c = u(s);
346
346
  if (!c) {
347
- a(i, void 0), a(o, void 0), a(n, void 0), a(s, void 0);
347
+ a(i, void 0), a(o, void 0), a(n, void 0), a(r, void 0);
348
348
  return;
349
349
  }
350
350
  const m = c.addConfigurationChangedListener((R, F) => {
351
- x.debug("SessionSubscription:", "Received ConfigurationChanged"), a(i, R), F.isSatisfied != null && a(o, F.isSatisfied);
351
+ v.debug("SessionSubscription:", "Received ConfigurationChanged"), a(i, R), F.isSatisfied != null && a(o, F.isSatisfied);
352
352
  const Z = u.peek(n), V = Z ?? pe();
353
353
  F.attributes.added.forEach((C) => {
354
354
  a(V(C.key), C);
@@ -358,7 +358,7 @@ function xe(t, e) {
358
358
  a(V(yt(C)), void 0);
359
359
  }), Z == null && a(n, () => V);
360
360
  }), Y = c.addCanResetConfigurationChangedListener((R) => {
361
- x.debug("SessionSubscription:", "Received CanResetConfigurationChanged"), a(s, R);
361
+ v.debug("SessionSubscription:", "Received CanResetConfigurationChanged"), a(r, R);
362
362
  });
363
363
  return () => {
364
364
  m.unsubscribe(), Y.unsubscribe();
@@ -367,26 +367,26 @@ function xe(t, e) {
367
367
  }
368
368
  function mt(t, e, n) {
369
369
  const i = f((o) => {
370
- const s = o(t);
371
- if (!s)
370
+ const r = o(t);
371
+ if (!r)
372
372
  return;
373
- const r = f();
374
- return r.onMount = (u) => {
375
- const a = e(s, (...c) => {
373
+ const s = f();
374
+ return s.onMount = (u) => {
375
+ const a = e(r, (...c) => {
376
376
  u(c);
377
377
  });
378
378
  return () => {
379
379
  u(void 0), a.unsubscribe();
380
380
  };
381
- }, r;
381
+ }, s;
382
382
  });
383
383
  return f((o) => {
384
- const s = o(i);
385
- if (s == null)
384
+ const r = o(i);
385
+ if (r == null)
386
386
  return;
387
- const r = o(s);
388
- if (r != null)
389
- return n(...r);
387
+ const s = o(r);
388
+ if (s != null)
389
+ return n(...s);
390
390
  });
391
391
  }
392
392
  function ve(t) {
@@ -445,30 +445,30 @@ function Fe(t) {
445
445
  }
446
446
  const p = Symbol.for("@ts-pattern/matcher"), jt = Symbol.for("@ts-pattern/isVariadic"), it = "@ts-pattern/anonymous-select-key", pt = (t) => !!(t && typeof t == "object"), tt = (t) => t && !!t[p], A = (t, e, n) => {
447
447
  if (tt(t)) {
448
- const i = t[p](), { matched: o, selections: s } = i.match(e);
449
- return o && s && Object.keys(s).forEach((r) => n(r, s[r])), o;
448
+ const i = t[p](), { matched: o, selections: r } = i.match(e);
449
+ return o && r && Object.keys(r).forEach((s) => n(s, r[s])), o;
450
450
  }
451
451
  if (pt(t)) {
452
452
  if (!pt(e)) return !1;
453
453
  if (Array.isArray(t)) {
454
454
  if (!Array.isArray(e)) return !1;
455
- let i = [], o = [], s = [];
456
- for (const r of t.keys()) {
457
- const u = t[r];
458
- tt(u) && u[jt] ? s.push(u) : s.length ? o.push(u) : i.push(u);
455
+ let i = [], o = [], r = [];
456
+ for (const s of t.keys()) {
457
+ const u = t[s];
458
+ tt(u) && u[jt] ? r.push(u) : r.length ? o.push(u) : i.push(u);
459
459
  }
460
- if (s.length) {
461
- if (s.length > 1) throw new Error("Pattern error: Using `...P.array(...)` several times in a single pattern is not allowed.");
460
+ if (r.length) {
461
+ if (r.length > 1) throw new Error("Pattern error: Using `...P.array(...)` several times in a single pattern is not allowed.");
462
462
  if (e.length < i.length + o.length) return !1;
463
- const r = e.slice(0, i.length), u = o.length === 0 ? [] : e.slice(-o.length), a = e.slice(i.length, o.length === 0 ? 1 / 0 : -o.length);
464
- return i.every((c, m) => A(c, r[m], n)) && o.every((c, m) => A(c, u[m], n)) && (s.length === 0 || A(s[0], a, n));
463
+ const s = e.slice(0, i.length), u = o.length === 0 ? [] : e.slice(-o.length), a = e.slice(i.length, o.length === 0 ? 1 / 0 : -o.length);
464
+ return i.every((c, m) => A(c, s[m], n)) && o.every((c, m) => A(c, u[m], n)) && (r.length === 0 || A(r[0], a, n));
465
465
  }
466
- return t.length === e.length && t.every((r, u) => A(r, e[u], n));
466
+ return t.length === e.length && t.every((s, u) => A(s, e[u], n));
467
467
  }
468
468
  return Reflect.ownKeys(t).every((i) => {
469
469
  const o = t[i];
470
- return (i in e || tt(s = o) && s[p]().matcherType === "optional") && A(o, e[i], n);
471
- var s;
470
+ return (i in e || tt(r = o) && r[p]().matcherType === "optional") && A(o, e[i], n);
471
+ var r;
472
472
  });
473
473
  }
474
474
  return Object.is(e, t);
@@ -505,8 +505,8 @@ function bt(t) {
505
505
  function wt(t) {
506
506
  return h({ [p]: () => ({ match: (e) => {
507
507
  let n = {};
508
- const i = (o, s) => {
509
- n[o] = s;
508
+ const i = (o, r) => {
509
+ n[o] = r;
510
510
  };
511
511
  return e === void 0 ? (S(t).forEach((o) => i(o, void 0)), { matched: !0, selections: n }) : { matched: A(t, e, i), selections: n };
512
512
  }, getSelectionKeys: () => S(t), matcherType: "optional" }) });
@@ -521,8 +521,8 @@ const ze = (t, e) => {
521
521
  function d(...t) {
522
522
  return h({ [p]: () => ({ match: (e) => {
523
523
  let n = {};
524
- const i = (o, s) => {
525
- n[o] = s;
524
+ const i = (o, r) => {
525
+ n[o] = r;
526
526
  };
527
527
  return { matched: t.every((o) => A(o, e, i)), selections: n };
528
528
  }, getSelectionKeys: () => Q(t, S), matcherType: "and" }) });
@@ -530,8 +530,8 @@ function d(...t) {
530
530
  function Tt(...t) {
531
531
  return h({ [p]: () => ({ match: (e) => {
532
532
  let n = {};
533
- const i = (o, s) => {
534
- n[o] = s;
533
+ const i = (o, r) => {
534
+ n[o] = r;
535
535
  };
536
536
  return Q(t, S).forEach((o) => i(o, void 0)), { matched: t.some((o) => A(o, e, i)), selections: n };
537
537
  }, getSelectionKeys: () => Q(t, S), matcherType: "or" }) });
@@ -543,12 +543,12 @@ function $(...t) {
543
543
  const e = typeof t[0] == "string" ? t[0] : void 0, n = t.length === 2 ? t[1] : typeof t[0] == "string" ? void 0 : t[0];
544
544
  return h({ [p]: () => ({ match: (i) => {
545
545
  let o = { [e ?? it]: i };
546
- return { matched: n === void 0 || A(n, i, (s, r) => {
547
- o[s] = r;
546
+ return { matched: n === void 0 || A(n, i, (r, s) => {
547
+ o[r] = s;
548
548
  }), selections: o };
549
549
  }, getSelectionKeys: () => [e ?? it].concat(n === void 0 ? [] : S(n)) }) });
550
550
  }
551
- function v(t) {
551
+ function w(t) {
552
552
  return typeof t == "number";
553
553
  }
554
554
  function M(t) {
@@ -571,7 +571,7 @@ const Vt = h(l(function(t) {
571
571
  }, regex: (e) => {
572
572
  return P(d(t, (n = e, l((i) => M(i) && !!i.match(n)))));
573
573
  var n;
574
- } }), qe = P(l(M)), w = (t) => Object.assign(h(t), { between: (e, n) => w(d(t, ((i, o) => l((s) => v(s) && i <= s && o >= s))(e, n))), lt: (e) => w(d(t, ((n) => l((i) => v(i) && i < n))(e))), gt: (e) => w(d(t, ((n) => l((i) => v(i) && i > n))(e))), lte: (e) => w(d(t, ((n) => l((i) => v(i) && i <= n))(e))), gte: (e) => w(d(t, ((n) => l((i) => v(i) && i >= n))(e))), int: () => w(d(t, l((e) => v(e) && Number.isInteger(e)))), finite: () => w(d(t, l((e) => v(e) && Number.isFinite(e)))), positive: () => w(d(t, l((e) => v(e) && e > 0))), negative: () => w(d(t, l((e) => v(e) && e < 0))) }), je = w(l(v)), U = (t) => Object.assign(h(t), { between: (e, n) => U(d(t, ((i, o) => l((s) => z(s) && i <= s && o >= s))(e, n))), lt: (e) => U(d(t, ((n) => l((i) => z(i) && i < n))(e))), gt: (e) => U(d(t, ((n) => l((i) => z(i) && i > n))(e))), lte: (e) => U(d(t, ((n) => l((i) => z(i) && i <= n))(e))), gte: (e) => U(d(t, ((n) => l((i) => z(i) && i >= n))(e))), positive: () => U(d(t, l((e) => z(e) && e > 0))), negative: () => U(d(t, l((e) => z(e) && e < 0))) }), Te = U(l(z)), Ve = h(l(function(t) {
574
+ } }), qe = P(l(M)), E = (t) => Object.assign(h(t), { between: (e, n) => E(d(t, ((i, o) => l((r) => w(r) && i <= r && o >= r))(e, n))), lt: (e) => E(d(t, ((n) => l((i) => w(i) && i < n))(e))), gt: (e) => E(d(t, ((n) => l((i) => w(i) && i > n))(e))), lte: (e) => E(d(t, ((n) => l((i) => w(i) && i <= n))(e))), gte: (e) => E(d(t, ((n) => l((i) => w(i) && i >= n))(e))), int: () => E(d(t, l((e) => w(e) && Number.isInteger(e)))), finite: () => E(d(t, l((e) => w(e) && Number.isFinite(e)))), positive: () => E(d(t, l((e) => w(e) && e > 0))), negative: () => E(d(t, l((e) => w(e) && e < 0))) }), je = E(l(w)), U = (t) => Object.assign(h(t), { between: (e, n) => U(d(t, ((i, o) => l((r) => z(r) && i <= r && o >= r))(e, n))), lt: (e) => U(d(t, ((n) => l((i) => z(i) && i < n))(e))), gt: (e) => U(d(t, ((n) => l((i) => z(i) && i > n))(e))), lte: (e) => U(d(t, ((n) => l((i) => z(i) && i <= n))(e))), gte: (e) => U(d(t, ((n) => l((i) => z(i) && i >= n))(e))), positive: () => U(d(t, l((e) => z(e) && e > 0))), negative: () => U(d(t, l((e) => z(e) && e < 0))) }), Te = U(l(z)), Ve = h(l(function(t) {
575
575
  return typeof t == "boolean";
576
576
  })), _e = h(l(function(t) {
577
577
  return typeof t == "symbol";
@@ -586,13 +586,13 @@ var Oe = { __proto__: null, matcher: p, optional: wt, array: function(...t) {
586
586
  if (t.length === 0) return { matched: !0 };
587
587
  const n = t[0];
588
588
  let i = {};
589
- if (e.length === 0) return S(n).forEach((s) => {
590
- i[s] = [];
589
+ if (e.length === 0) return S(n).forEach((r) => {
590
+ i[r] = [];
591
591
  }), { matched: !0, selections: i };
592
- const o = (s, r) => {
593
- i[s] = (i[s] || []).concat([r]);
592
+ const o = (r, s) => {
593
+ i[r] = (i[r] || []).concat([s]);
594
594
  };
595
- return { matched: e.every((s) => A(n, s, o)), selections: i };
595
+ return { matched: e.every((r) => A(n, r, o)), selections: i };
596
596
  }, getSelectionKeys: () => t.length === 0 ? [] : S(t[0]) }) });
597
597
  }, set: function(...t) {
598
598
  return h({ [p]: () => ({ match: (e) => {
@@ -600,10 +600,10 @@ var Oe = { __proto__: null, matcher: p, optional: wt, array: function(...t) {
600
600
  let n = {};
601
601
  if (e.size === 0) return { matched: !0, selections: n };
602
602
  if (t.length === 0) return { matched: !0 };
603
- const i = (s, r) => {
604
- n[s] = (n[s] || []).concat([r]);
603
+ const i = (r, s) => {
604
+ n[r] = (n[r] || []).concat([s]);
605
605
  }, o = t[0];
606
- return { matched: ze(e, (s) => A(o, s, i)), selections: n };
606
+ return { matched: ze(e, (r) => A(o, r, i)), selections: n };
607
607
  }, getSelectionKeys: () => t.length === 0 ? [] : S(t[0]) }) });
608
608
  }, map: function(...t) {
609
609
  return h({ [p]: () => ({ match: (e) => {
@@ -616,9 +616,9 @@ var Oe = { __proto__: null, matcher: p, optional: wt, array: function(...t) {
616
616
  if (t.length === 0) return { matched: !0 };
617
617
  var o;
618
618
  if (t.length === 1) throw new Error(`\`P.map\` wasn't given enough arguments. Expected (key, value), received ${(o = t[0]) == null ? void 0 : o.toString()}`);
619
- const [s, r] = t;
619
+ const [r, s] = t;
620
620
  return { matched: Pe(e, (u, a) => {
621
- const c = A(s, a, i), m = A(r, u, i);
621
+ const c = A(r, a, i), m = A(s, u, i);
622
622
  return c && m;
623
623
  }), selections: n };
624
624
  }, getSelectionKeys: () => t.length === 0 ? [] : [...S(t[0]), ...S(t[1])] }) });
@@ -645,9 +645,9 @@ class Be extends Error {
645
645
  }
646
646
  const St = { matched: !1, value: void 0 };
647
647
  function ot(t) {
648
- return new st(t, St);
648
+ return new rt(t, St);
649
649
  }
650
- class st {
650
+ class rt {
651
651
  constructor(e, n) {
652
652
  this.input = void 0, this.state = void 0, this.input = e, this.state = n;
653
653
  }
@@ -656,16 +656,16 @@ class st {
656
656
  const n = e[e.length - 1], i = [e[0]];
657
657
  let o;
658
658
  e.length === 3 && typeof e[1] == "function" ? o = e[1] : e.length > 2 && i.push(...e.slice(1, e.length - 1));
659
- let s = !1, r = {};
659
+ let r = !1, s = {};
660
660
  const u = (c, m) => {
661
- s = !0, r[c] = m;
662
- }, a = !i.some((c) => A(c, this.input, u)) || o && !o(this.input) ? St : { matched: !0, value: n(s ? it in r ? r[it] : r : this.input, this.input) };
663
- return new st(this.input, a);
661
+ r = !0, s[c] = m;
662
+ }, a = !i.some((c) => A(c, this.input, u)) || o && !o(this.input) ? St : { matched: !0, value: n(r ? it in s ? s[it] : s : this.input, this.input) };
663
+ return new rt(this.input, a);
664
664
  }
665
665
  when(e, n) {
666
666
  if (this.state.matched) return this;
667
667
  const i = !!e(this.input);
668
- return new st(this.input, i ? { matched: !0, value: n(this.input, this.input) } : St);
668
+ return new rt(this.input, i ? { matched: !0, value: n(this.input, this.input) } : St);
669
669
  }
670
670
  otherwise(e) {
671
671
  return this.state.matched ? this.state.value : e(this.input);
@@ -684,44 +684,44 @@ class st {
684
684
  function T(t, e) {
685
685
  var n = 0, i, o;
686
686
  e = e || {};
687
- function s() {
688
- var r = i, u = arguments.length, a, c;
689
- t: for (; r; ) {
690
- if (r.args.length !== arguments.length) {
691
- r = r.next;
687
+ function r() {
688
+ var s = i, u = arguments.length, a, c;
689
+ t: for (; s; ) {
690
+ if (s.args.length !== arguments.length) {
691
+ s = s.next;
692
692
  continue;
693
693
  }
694
694
  for (c = 0; c < u; c++)
695
- if (r.args[c] !== arguments[c]) {
696
- r = r.next;
695
+ if (s.args[c] !== arguments[c]) {
696
+ s = s.next;
697
697
  continue t;
698
698
  }
699
- return r !== i && (r === o && (o = r.prev), r.prev.next = r.next, r.next && (r.next.prev = r.prev), r.next = i, r.prev = null, i.prev = r, i = r), r.val;
699
+ return s !== i && (s === o && (o = s.prev), s.prev.next = s.next, s.next && (s.next.prev = s.prev), s.next = i, s.prev = null, i.prev = s, i = s), s.val;
700
700
  }
701
701
  for (a = new Array(u), c = 0; c < u; c++)
702
702
  a[c] = arguments[c];
703
- return r = {
703
+ return s = {
704
704
  args: a,
705
705
  // Generate the result from original function
706
706
  val: t.apply(null, a)
707
- }, i ? (i.prev = r, r.next = i) : o = r, n === /** @type {MemizeOptions} */
707
+ }, i ? (i.prev = s, s.next = i) : o = s, n === /** @type {MemizeOptions} */
708
708
  e.maxSize ? (o = /** @type {MemizeCacheNode} */
709
- o.prev, o.next = null) : n++, i = r, r.val;
709
+ o.prev, o.next = null) : n++, i = s, s.val;
710
710
  }
711
- return s.clear = function() {
711
+ return r.clear = function() {
712
712
  i = null, o = null, n = 0;
713
- }, s;
713
+ }, r;
714
714
  }
715
715
  function Le(t, e, n) {
716
716
  return dt(
717
717
  t,
718
718
  n,
719
- rt.choiceAttributeRefinement,
719
+ st.choiceAttributeRefinement,
720
720
  N.choiceValue,
721
- (i, o, s) => {
722
- const { makeDecision: r, makeManyDecisions: u } = s(e);
721
+ (i, o, r) => {
722
+ const { makeDecision: s, makeManyDecisions: u } = r(e);
723
723
  return {
724
- makeDecision: (a, c) => r({
724
+ makeDecision: (a, c) => s({
725
725
  type: J.Choice,
726
726
  attributeId: i.id,
727
727
  choiceValueId: a,
@@ -751,12 +751,12 @@ function Ke(t, e, n) {
751
751
  return dt(
752
752
  t,
753
753
  n,
754
- rt.numericAttributeRefinement,
754
+ st.numericAttributeRefinement,
755
755
  N.numeric,
756
- (i, o, s) => {
757
- const { makeDecision: r } = s(e);
756
+ (i, o, r) => {
757
+ const { makeDecision: s } = r(e);
758
758
  return {
759
- makeDecision: (u) => r({
759
+ makeDecision: (u) => s({
760
760
  type: J.Numeric,
761
761
  attributeId: i.id,
762
762
  state: u
@@ -769,12 +769,12 @@ function Qe(t, e, n) {
769
769
  return dt(
770
770
  t,
771
771
  n,
772
- rt.booleanAttributeRefinement,
772
+ st.booleanAttributeRefinement,
773
773
  N.boolean,
774
- (i, o, s) => {
775
- const { makeDecision: r } = s(e);
774
+ (i, o, r) => {
775
+ const { makeDecision: s } = r(e);
776
776
  return {
777
- makeDecision: (u) => r({
777
+ makeDecision: (u) => s({
778
778
  type: J.Boolean,
779
779
  attributeId: i.id,
780
780
  state: u
@@ -787,12 +787,12 @@ function $e(t, e, n) {
787
787
  return dt(
788
788
  t,
789
789
  n,
790
- rt.componentAttributeRefinement,
790
+ st.componentAttributeRefinement,
791
791
  N.component,
792
- (i, o, s) => {
793
- const { makeDecision: r } = s(e);
792
+ (i, o, r) => {
793
+ const { makeDecision: s } = r(e);
794
794
  return {
795
- makeDecision: (u) => r({
795
+ makeDecision: (u) => s({
796
796
  type: J.Component,
797
797
  attributeId: i.id,
798
798
  state: u
@@ -802,12 +802,12 @@ function $e(t, e, n) {
802
802
  );
803
803
  }
804
804
  function dt(t, e, n, i, o) {
805
- return _((s) => D((r, u) => {
806
- const a = u(t), c = r(a(s));
805
+ return _((r) => D((s, u) => {
806
+ const a = u(t), c = s(a(r));
807
807
  if (!c || !n(c))
808
808
  return;
809
- const { explain: m, applySolution: Y } = u(e), R = o(c, r, u);
810
- return R === E ? E : {
809
+ const { explain: m, applySolution: Y } = u(e), R = o(c, s, u);
810
+ return R === x ? x : {
811
811
  attribute: c,
812
812
  isMandatory: T(() => B.isMandatory(c)),
813
813
  explain: (F, Z) => {
@@ -825,23 +825,23 @@ function dt(t, e, n, i, o) {
825
825
  }
826
826
  function _t(t, e) {
827
827
  const n = zt(t, et, e.equals);
828
- return "write" in t ? f((i) => i(n), (i, o, ...s) => o(t, ...s)) : n;
828
+ return "write" in t ? f((i) => i(n), (i, o, ...r) => o(t, ...r)) : n;
829
829
  }
830
830
  const Je = b.struct({
831
831
  isInitializing: at.Eq,
832
832
  error: b.eqNullable(b.eqStrict)
833
833
  });
834
- function He(t, e, n, i, o, s) {
835
- const r = [
834
+ function He(t, e, n, i, o, r) {
835
+ const s = [
836
836
  e,
837
837
  n,
838
838
  i,
839
839
  o,
840
- s
840
+ r
841
841
  ], u = f((a) => {
842
842
  const c = j(
843
- r,
844
- k.every((R) => a(R) !== E)
843
+ s,
844
+ k.every((R) => a(R) !== x)
845
845
  ), m = a(t);
846
846
  return {
847
847
  isInitializing: !(!m.isInitializing && c),
@@ -872,10 +872,10 @@ function Ge(t, e) {
872
872
  subject: N.configuration
873
873
  };
874
874
  return D((i, o) => {
875
- const s = o(t);
875
+ const r = o(t);
876
876
  return {
877
877
  isSatisfied: o(e),
878
- explain: (u) => ot(u).with("full", (a) => s.explain(n, a)).with("decisions", (a) => s.explain(n, a)).with("constraints", (a) => s.explain(n, a)).exhaustive()
878
+ explain: (u) => ot(u).with("full", (a) => r.explain(n, a)).with("decisions", (a) => r.explain(n, a)).with("constraints", (a) => r.explain(n, a)).exhaustive()
879
879
  };
880
880
  });
881
881
  }
@@ -913,9 +913,9 @@ function on(t) {
913
913
  });
914
914
  }
915
915
  function I(t) {
916
- return f((e) => e(t) ?? E);
916
+ return f((e) => e(t) ?? x);
917
917
  }
918
- function sn(t) {
918
+ function rn(t) {
919
919
  const { sessionInitializationAtom: e, sessionUpdatingAtom: n } = he(t), i = Ae(t), o = {
920
920
  guardedConfigurationSessionAtom: I(i),
921
921
  guardedConfigurationAtom: I(t.configurationAtom),
@@ -926,7 +926,7 @@ function sn(t) {
926
926
  guardedDecisionsAtom: I(we(i)),
927
927
  guardedExplicitDecisionsAtom: I(Ee(i)),
928
928
  guardedImplicitDecisionsAtom: I(De(i))
929
- }, s = on(o.guardedConfigurationSessionAtom), r = Re(o.guardedConfigurationSessionAtom);
929
+ }, r = on(o.guardedConfigurationSessionAtom), s = Re(o.guardedConfigurationSessionAtom);
930
930
  return {
931
931
  ...o,
932
932
  configurationSessionAtom: i,
@@ -934,22 +934,22 @@ function sn(t) {
934
934
  sessionUpdatingAtom: n,
935
935
  configurationInitializationAtom: He(e, o.guardedConfigurationSessionAtom, o.guardedConfigurationAtom, o.guardedCanResetAtom, o.guardedIsSatisfiedAtom, o.guardedAttributesAtom),
936
936
  configurationUpdatingAtom: Ye(n),
937
- makeDecisionAtom: s,
938
- explainAtom: r,
937
+ makeDecisionAtom: r,
938
+ explainAtom: s,
939
939
  decisionQueriesAtom: nn(o.guardedConfigurationSessionAtom),
940
940
  taskSchedulingAtom: en(o.guardedConfigurationSessionAtom),
941
941
  configurationSatisfactionAtom: Ge(o.guardedConfigurationSessionAtom, o.guardedIsSatisfiedAtom),
942
942
  configurationStoringAtom: Ze(o.guardedConfigurationSessionAtom),
943
943
  configurationResetAtom: ke(o.guardedConfigurationSessionAtom, o.guardedCanResetAtom),
944
944
  sessionReinitializationAtom: tn(o.guardedConfigurationSessionAtom),
945
- choiceAttributeAtomFamily: Le(o.guardedAttributesAtom, s, r),
946
- numericAttributeAtomFamily: Ke(o.guardedAttributesAtom, s, r),
947
- booleanAttributeAtomFamily: Qe(o.guardedAttributesAtom, s, r),
948
- componentAttributeAtomFamily: $e(o.guardedAttributesAtom, s, r),
945
+ choiceAttributeAtomFamily: Le(o.guardedAttributesAtom, r, s),
946
+ numericAttributeAtomFamily: Ke(o.guardedAttributesAtom, r, s),
947
+ booleanAttributeAtomFamily: Qe(o.guardedAttributesAtom, r, s),
948
+ componentAttributeAtomFamily: $e(o.guardedAttributesAtom, r, s),
949
949
  subscriberAtom: ce(t)
950
950
  };
951
951
  }
952
- const rn = 30 * 1e3;
952
+ const sn = 30 * 1e3;
953
953
  function an(t, e, n) {
954
954
  const i = [
955
955
  e.choiceAttributeAtomFamily,
@@ -963,23 +963,23 @@ function an(t, e, n) {
963
963
  ];
964
964
  return ut((o) => {
965
965
  o(t.configurationAtom);
966
- const s = o(t.attributesAtom);
967
- if (s == null)
966
+ const r = o(t.attributesAtom);
967
+ if (r == null)
968
968
  return;
969
- x.debug("Scheduling atomFamily cleanup");
970
- const r = setTimeout(() => {
971
- x.debug("Cleaning up atomFamilies");
972
- for (const a of [...s.getParams()]) {
973
- const c = s(a);
974
- o.peek(c) == null && (x.debug("Removing attribute from attributes family because it is nullish", a), s.remove(a));
969
+ v.debug("Scheduling atomFamily cleanup");
970
+ const s = setTimeout(() => {
971
+ v.debug("Cleaning up atomFamilies");
972
+ for (const a of [...r.getParams()]) {
973
+ const c = r(a);
974
+ o.peek(c) == null && (v.debug("Removing attribute from attributes family because it is nullish", a), r.remove(a));
975
975
  }
976
- const u = [...s.getParams()];
976
+ const u = [...r.getParams()];
977
977
  for (const a of i)
978
978
  for (const c of [...a.getParams()])
979
979
  u.includes(c) || a.remove(c);
980
- }, rn);
980
+ }, sn);
981
981
  return () => {
982
- clearTimeout(r);
982
+ clearTimeout(s);
983
983
  };
984
984
  });
985
985
  }
@@ -1013,7 +1013,7 @@ function cn(t) {
1013
1013
  };
1014
1014
  }
1015
1015
  function ln() {
1016
- const t = Ie(), e = sn(t), n = cn(e);
1016
+ const t = Ie(), e = rn(t), n = cn(e);
1017
1017
  return {
1018
1018
  primitives: t,
1019
1019
  selectors: e,
@@ -1034,7 +1034,7 @@ function Un(t) {
1034
1034
  const e = X(() => ln(), []);
1035
1035
  return /* @__PURE__ */ q(Pt, { children: /* @__PURE__ */ q(Ut.Provider, { value: e, children: /* @__PURE__ */ q(fn, { jotaiStore: t.jotaiStore, children: /* @__PURE__ */ Ht(gn, { children: [
1036
1036
  /* @__PURE__ */ q(dn, { sessionContext: t.sessionContext }),
1037
- /* @__PURE__ */ q(se, {}),
1037
+ /* @__PURE__ */ q(re, {}),
1038
1038
  t.children
1039
1039
  ] }) }) }) });
1040
1040
  }
@@ -1083,9 +1083,13 @@ function Jn() {
1083
1083
  getImplicitDecisionsAtom: t.guardedImplicitDecisionsAtom
1084
1084
  }), [t]);
1085
1085
  }
1086
+ function Hn() {
1087
+ return (t) => t !== x;
1088
+ }
1086
1089
  export {
1087
1090
  Un as Configuration,
1088
- E as ConfigurationUninitialized,
1091
+ x as ConfigurationUninitialized,
1092
+ Hn as isInitialized,
1089
1093
  Rn as useAttributes,
1090
1094
  zn as useBooleanAttribute,
1091
1095
  Fn as useChoiceAttribute,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viamedici-spc/configurator-react",
3
- "version": "2.1.0-sessionUpdateErrorIsNotRemovedOnRetry-20250106091418",
3
+ "version": "2.1.0-sessionUpdateErrorIsNotRemovedOnRetry-20250110085341",
4
4
  "description": "React library to build configurator web applications based on the Viamedici Headless Configuration Engine (HCE).",
5
5
  "sideEffects": false,
6
6
  "files": [