@viamedici-spc/configurator-react 2.1.0-fixWindowNotDefined-20241112132136 → 2.1.0-sessionUpdateErrorIsNotRemovedOnRetry-20250106091418

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"),At=require("p-defer"),v=require("react/jsx-runtime"),ht=require("dyna-guid"),X=require("jotai-effect"),pt=require("jotai-xstate"),q=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 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)??At();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=ht.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=q.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=q.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:[q.assign({sessionCreateOrUpdateError:()=>null})]},SessionContextChanged:{actions:[q.log("SessionContextChanged"),q.assign({desiredSessionContext:({event:t})=>t.sessionContext})]},Shutdown:{target:"#shutdown"}},initial:"Idle",states:{Idle:{always:[{target:"DisposeSession",guard:"shallDispose"},{target:"Processing",guard:"shallProcess"}]},Processing:{invoke:{src:"createOrUpdateSession",input:({context:t})=>({sessionContext:t.desiredSessionContext,session:l.O.fromNullable(t.configurationSession)}),onDone:{target:"Idle",actions:[q.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:[q.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:[q.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 Tt(){return pt.atomWithMachine(jt)}function Pt(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((F,M)=>{m.Logger.debug("SessionSubscription:","Received ConfigurationChanged"),a(i,F),M.isSatisfied!=null&&a(o,M.isSatisfied);const W=u.peek(n),V=W??Lt();M.attributes.added.forEach(E=>{a(V(E.key),E)}),M.attributes.changed.forEach(E=>{a(V(E.key),E)}),M.attributes.removed.forEach(E=>{a(V(m.GlobalAttributeIdKeyBuilder(E)),void 0)}),W==null&&a(n,()=>V)}),K=c.addCanResetConfigurationChangedListener(F=>{m.Logger.debug("SessionSubscription:","Received CanResetConfigurationChanged"),a(s,F)});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:Tt(),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,T=t=>Object.assign(b(t),{startsWith:e=>{return T(A(t,(n=e,d(i=>z(i)&&i.startsWith(n)))));var n},endsWith:e=>{return T(A(t,(n=e,d(i=>z(i)&&i.endsWith(n)))));var n},minLength:e=>T(A(t,(n=>d(i=>z(i)&&i.length>=n))(e))),length:e=>T(A(t,(n=>d(i=>z(i)&&i.length===n))(e))),maxLength:e=>T(A(t,(n=>d(i=>z(i)&&i.length<=n))(e))),includes:e=>{return T(A(t,(n=e,d(i=>z(i)&&i.includes(n)))));var n},regex:e=>{return T(A(t,(n=e,d(i=>z(i)&&!!i.match(n)))));var n}}),ne=T(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)),P=t=>Object.assign(b(t),{between:(e,n)=>P(A(t,((i,o)=>d(s=>j(s)&&i<=s&&o>=s))(e,n))),lt:e=>P(A(t,(n=>d(i=>j(i)&&i<n))(e))),gt:e=>P(A(t,(n=>d(i=>j(i)&&i>n))(e))),lte:e=>P(A(t,(n=>d(i=>j(i)&&i<=n))(e))),gte:e=>P(A(t,(n=>d(i=>j(i)&&i>=n))(e))),positive:()=>P(A(t,d(e=>j(e)&&e>0))),negative:()=>P(A(t,d(e=>j(e)&&e<0)))}),oe=P(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),F=o(c,r,u);return F===w?w:{attribute:c,isMandatory:L(()=>m.AttributeInterpreter.isMandatory(c)),explain:(M,W)=>{const V=H(M.question).with(m.ExplainQuestionType.whyIsNotSatisfied,()=>m.ExplainQuestionSubject.attribute).otherwise(()=>i),E={...M,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,...F}}))}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(F=>a(F)!==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=Pt(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(Te,{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 Te(t){const e=_();return v.jsx(g.Provider,{store:e,children:t.children})}function Pe(){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=Pe;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"),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;
package/dist/index.d.ts CHANGED
@@ -397,7 +397,7 @@ export declare type UseExplainResult = {
397
397
  */
398
398
  export declare function useJotaiAtoms(): UseJotaiAtomsResult;
399
399
 
400
- declare type UseJotaiAtomsResult = {
400
+ export declare type UseJotaiAtomsResult = {
401
401
  createAttributesAtom: {
402
402
  (attributes: "all"): GuardedAtom<ReadonlyArray<Attribute>>;
403
403
  (attributes: ReadonlyArray<GlobalAttributeId | GlobalAttributeIdKey>, filterMissingAttributes: true): GuardedAtom<ReadonlyArray<Attribute>>;
package/dist/index.js CHANGED
@@ -1,15 +1,14 @@
1
- import { GlobalAttributeIdKeyBuilder as St, globalAttributeIdKeyEq as Nt, globalAttributeIdEq as Wt, Logger as x, SessionFactory as Bt, DecisionKind as L, AttributeType as J, ExplainQuestionSubject as N, AttributeRefinements as rt, AttributeInterpreter as O, ExplainQuestionType as It, ChoiceValueInterpreter as wt } from "@viamedici-spc/configurator-ts";
2
- import { pipe as T, 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 Ot, T as Lt, constVoid as Kt } from "@viamedici-spc/fp-ts-extensions";
3
- import { atom as f, getDefaultStore as Qt, useSetAtom as Ft, useAtomValue as yt, useAtom as G, Provider as $t } from "jotai";
4
- import { createContext as Et, useContext as Mt, useMemo as X, useEffect as gt } from "react";
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";
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
+ import { atom as f, getDefaultStore as Qt, useSetAtom as Ft, useAtomValue as Ct, useAtom as G, Provider as $t } from "jotai";
4
+ import { createContext as Dt, useContext as Mt, useMemo as X, useEffect as At } from "react";
5
5
  import { useStableMemo as Jt } from "fp-ts-react-stable-hooks";
6
6
  import { selectAtom as zt, atomFamily as _ } from "jotai/utils";
7
- import Ht from "p-defer";
8
- import { jsx as q, Fragment as Pt, jsxs as Xt } from "react/jsx-runtime";
9
- import { guid as Yt } from "dyna-guid";
7
+ import { jsx as q, Fragment as Pt, jsxs as Ht } from "react/jsx-runtime";
8
+ import { guid as Xt } from "dyna-guid";
10
9
  import { atomEffect as ut } from "jotai-effect";
11
- import { atomWithMachine as Zt } from "jotai-xstate";
12
- import { fromPromise as Gt, setup as te, assign as Dt, log as ee, enqueueActions as ft } from "xstate";
10
+ import { atomWithMachine as Yt } from "jotai-xstate";
11
+ import { fromPromise as Zt, setup as Gt, assign as ft, log as te, enqueueActions as gt } from "xstate";
13
12
  const E = "ConfigurationUninitialized";
14
13
  function D(t) {
15
14
  return f((e) => {
@@ -28,18 +27,18 @@ function D(t) {
28
27
  }
29
28
  });
30
29
  }
31
- function At(t) {
30
+ function ht(t) {
32
31
  const { guardedConfigurationAtom: e, guardedAttributesAtom: n } = t;
33
32
  function i(o, s) {
34
- const r = o === "all" ? "all" : T(
33
+ const r = o === "all" ? "all" : j(
35
34
  o,
36
- k.map((u) => typeof u == "string" ? u : St(u))
35
+ k.map((u) => typeof u == "string" ? u : yt(u))
37
36
  );
38
37
  return D((u, a) => {
39
38
  if (r === "all")
40
- return T(e, a, (m) => m.attributes, H.values(kt.trivial));
39
+ return j(e, a, (m) => m.attributes, H.values(kt.trivial));
41
40
  const c = a(n);
42
- return T(
41
+ return j(
43
42
  r,
44
43
  k.map((m) => u(c(m))),
45
44
  s ? k.filterMap(K.fromNullable) : et
@@ -48,36 +47,42 @@ function At(t) {
48
47
  }
49
48
  return i;
50
49
  }
51
- const Ct = globalThis.configuratorReactContexts ?? {
52
- AtomsContext: Et(null),
53
- StoreContext: Et(Qt())
50
+ const xt = globalThis.configuratorReactContexts ?? {
51
+ AtomsContext: Dt(null),
52
+ StoreContext: Dt(Qt())
54
53
  };
55
- globalThis.configuratorReactContexts = Ct;
56
- const Ut = Ct.AtomsContext, qt = Ct.StoreContext, W = () => Mt(Ut), ct = () => Mt(qt);
57
- function xt(t, e, n) {
54
+ globalThis.configuratorReactContexts = xt;
55
+ const Ut = xt.AtomsContext, qt = xt.StoreContext, W = () => Mt(Ut), ct = () => Mt(qt);
56
+ function vt(t, e, n) {
58
57
  const i = b.tuple(b.eqNullable(at.Eq), n);
59
58
  return (o, ...s) => {
60
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]);
61
- return gt(() => () => {
60
+ return At(() => () => {
62
61
  m.unsubscribe();
63
- }, [m]), yt(c, { store: u });
62
+ }, [m]), Ct(c, { store: u });
64
63
  };
65
64
  }
66
65
  function y(t, e) {
67
- const n = xt((o) => t(o.selectors), (o) => e(o.suspended), b.tuple());
66
+ const n = vt((o) => t(o.selectors), (o) => e(o.suspended), b.tuple());
68
67
  function i(o) {
69
68
  return n(o);
70
69
  }
71
70
  return i;
72
71
  }
73
72
  function lt(t, e) {
74
- const n = xt((o, s) => t(o.selectors)(s), (o, s) => e(o.suspended)(s), b.tuple(Rt.Eq));
73
+ const n = vt((o, s) => t(o.selectors)(s), (o, s) => e(o.suspended)(s), b.tuple(Rt.Eq));
75
74
  function i(o, s) {
76
- const r = X(() => typeof o == "string" ? o : St(o), [o]);
75
+ const r = X(() => typeof o == "string" ? o : yt(o), [o]);
77
76
  return n(s, r);
78
77
  }
79
78
  return i;
80
79
  }
80
+ function ee() {
81
+ const t = {};
82
+ return t.promise = new Promise((e, n) => {
83
+ t.resolve = e, t.reject = n;
84
+ }), t;
85
+ }
81
86
  function g(t) {
82
87
  const e = zt(t, (n, i) => {
83
88
  if (n !== E)
@@ -88,7 +93,7 @@ function g(t) {
88
93
  deferredPromise: null,
89
94
  result: n
90
95
  };
91
- const o = (i == null ? void 0 : i.deferredPromise) ?? Ht();
96
+ const o = (i == null ? void 0 : i.deferredPromise) ?? ee();
92
97
  return {
93
98
  deferredPromise: o,
94
99
  result: o.promise
@@ -96,16 +101,16 @@ function g(t) {
96
101
  });
97
102
  return f((n) => n(e).result);
98
103
  }
99
- const ne = b.union().with((t) => typeof t == "string", Nt).with((t) => typeof t == "object", Wt), ie = b.union().with((t) => t === "all", Rt.Eq).with((t) => Array.isArray(t), k.getEq(ne)), oe = xt(
100
- (t, e, n) => At(t.selectors)(e, n),
101
- (t, e, n) => g(At(t.selectors)(e, n)),
104
+ const ne = b.union().with((t) => typeof t == "string", Nt).with((t) => typeof t == "object", Wt), ie = b.union().with((t) => t === "all", Rt.Eq).with((t) => Array.isArray(t), k.getEq(ne)), oe = vt(
105
+ (t, e, n) => ht(t.selectors)(e, n),
106
+ (t, e, n) => g(ht(t.selectors)(e, n)),
102
107
  b.tuple(ie, b.eqNullable(at.Eq))
103
108
  );
104
- function Fn(t, e, n) {
109
+ function Rn(t, e, n) {
105
110
  const i = t == "all" ? e : n, o = t == "all" ? void 0 : e;
106
111
  return oe(i, t, o);
107
112
  }
108
- const Mn = lt((t) => t.choiceAttributeAtomFamily, (t) => t.choiceAttributeAtomFamily), zn = lt((t) => t.numericAttributeAtomFamily, (t) => t.numericAttributeAtomFamily), Pn = lt((t) => t.booleanAttributeAtomFamily, (t) => t.booleanAttributeAtomFamily), Un = lt((t) => t.componentAttributeAtomFamily, (t) => t.componentAttributeAtomFamily);
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);
109
114
  function se() {
110
115
  const { effects: t } = W(), { addSessionListenersEffect: e, cleanupAtomFamiliesEffect: n, atomSubscriberEffect: i, atomSubscriptionCleanupEffect: o } = t;
111
116
  return G(e), G(n), G(i), G(o), null;
@@ -118,7 +123,7 @@ function ue() {
118
123
  }
119
124
  function ce(t) {
120
125
  return f(null, (e, n, i) => {
121
- const o = Yt();
126
+ const o = Xt();
122
127
  x.debug("AtomSubscription:", "Creating subscription with id", o);
123
128
  const r = {
124
129
  unsubscribe: () => {
@@ -172,10 +177,10 @@ function me(t) {
172
177
  };
173
178
  });
174
179
  }
175
- const de = Gt(({ input: t }) => T(
180
+ const de = Zt(({ input: t }) => j(
176
181
  t.session,
177
182
  K.match(
178
- () => () => Bt.createSession(t.sessionContext),
183
+ () => () => Ot.createSession(t.sessionContext),
179
184
  (e) => async () => (await e.setSessionContext(t.sessionContext), e)
180
185
  ),
181
186
  (e) => nt.tryCatch(e, (n) => n),
@@ -183,7 +188,7 @@ const de = Gt(({ input: t }) => T(
183
188
  sessionContext: t.sessionContext,
184
189
  configurationError: e
185
190
  }))
186
- )()), fe = te({
191
+ )()), fe = Gt({
187
192
  types: {
188
193
  context: {},
189
194
  events: {}
@@ -208,15 +213,15 @@ const de = Gt(({ input: t }) => T(
208
213
  on: {
209
214
  Retry: {
210
215
  actions: [
211
- Dt({
216
+ ft({
212
217
  sessionCreateOrUpdateError: () => null
213
218
  })
214
219
  ]
215
220
  },
216
221
  SessionContextChanged: {
217
222
  actions: [
218
- ee("SessionContextChanged"),
219
- Dt({
223
+ te("SessionContextChanged"),
224
+ ft({
220
225
  desiredSessionContext: ({ event: t }) => t.sessionContext
221
226
  })
222
227
  ]
@@ -234,6 +239,11 @@ const de = Gt(({ input: t }) => T(
234
239
  ]
235
240
  },
236
241
  Processing: {
242
+ entry: [
243
+ ft({
244
+ sessionCreateOrUpdateError: () => null
245
+ })
246
+ ],
237
247
  invoke: {
238
248
  src: "createOrUpdateSession",
239
249
  input: ({ context: t }) => ({
@@ -243,8 +253,8 @@ const de = Gt(({ input: t }) => T(
243
253
  onDone: {
244
254
  target: "Idle",
245
255
  actions: [
246
- ft(({ event: t, enqueue: e }) => {
247
- Ot.isRight(t.output) ? e.assign({
256
+ gt(({ event: t, enqueue: e }) => {
257
+ Bt.isRight(t.output) ? e.assign({
248
258
  configurationSession: t.output.right
249
259
  }) : e.assign({
250
260
  sessionCreateOrUpdateError: t.output.left
@@ -258,7 +268,7 @@ const de = Gt(({ input: t }) => T(
258
268
  always: [{
259
269
  target: "Idle",
260
270
  actions: [
261
- ft(({ enqueue: t, context: e }) => {
271
+ gt(({ enqueue: t, context: e }) => {
262
272
  nt.tryCatch(async () => {
263
273
  var n;
264
274
  return await ((n = e.configurationSession) == null ? void 0 : n.close());
@@ -274,7 +284,7 @@ const de = Gt(({ input: t }) => T(
274
284
  type: "final",
275
285
  id: "shutdown",
276
286
  entry: [
277
- ft(({ context: t, enqueue: e }) => {
287
+ gt(({ context: t, enqueue: e }) => {
278
288
  t.configurationSession && nt.tryCatch(async () => {
279
289
  var n;
280
290
  return await ((n = t.configurationSession) == null ? void 0 : n.close());
@@ -289,7 +299,7 @@ const de = Gt(({ input: t }) => T(
289
299
  }
290
300
  });
291
301
  function ge() {
292
- return Zt(fe);
302
+ return Yt(fe);
293
303
  }
294
304
  function Ae(t) {
295
305
  return f((e) => e(t.sessionManagementMachineAtom).context.configurationSession);
@@ -345,7 +355,7 @@ function xe(t, e) {
345
355
  }), F.attributes.changed.forEach((C) => {
346
356
  a(V(C.key), C);
347
357
  }), F.attributes.removed.forEach((C) => {
348
- a(V(St(C)), void 0);
358
+ a(V(yt(C)), void 0);
349
359
  }), Z == null && a(n, () => V);
350
360
  }), Y = c.addCanResetConfigurationChangedListener((R) => {
351
361
  x.debug("SessionSubscription:", "Received CanResetConfigurationChanged"), a(s, R);
@@ -418,7 +428,7 @@ function Re(t) {
418
428
  });
419
429
  }
420
430
  function Fe(t) {
421
- return T(
431
+ return j(
422
432
  t.values,
423
433
  H.values(kt.trivial),
424
434
  k.filter((e) => {
@@ -433,19 +443,19 @@ function Fe(t) {
433
443
  }))
434
444
  );
435
445
  }
436
- const p = Symbol.for("@ts-pattern/matcher"), Tt = Symbol.for("@ts-pattern/isVariadic"), it = "@ts-pattern/anonymous-select-key", ht = (t) => !!(t && typeof t == "object"), tt = (t) => t && !!t[p], A = (t, e, n) => {
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) => {
437
447
  if (tt(t)) {
438
448
  const i = t[p](), { matched: o, selections: s } = i.match(e);
439
449
  return o && s && Object.keys(s).forEach((r) => n(r, s[r])), o;
440
450
  }
441
- if (ht(t)) {
442
- if (!ht(e)) return !1;
451
+ if (pt(t)) {
452
+ if (!pt(e)) return !1;
443
453
  if (Array.isArray(t)) {
444
454
  if (!Array.isArray(e)) return !1;
445
455
  let i = [], o = [], s = [];
446
456
  for (const r of t.keys()) {
447
457
  const u = t[r];
448
- tt(u) && u[Tt] ? s.push(u) : s.length ? o.push(u) : i.push(u);
458
+ tt(u) && u[jt] ? s.push(u) : s.length ? o.push(u) : i.push(u);
449
459
  }
450
460
  if (s.length) {
451
461
  if (s.length > 1) throw new Error("Pattern error: Using `...P.array(...)` several times in a single pattern is not allowed.");
@@ -464,7 +474,7 @@ const p = Symbol.for("@ts-pattern/matcher"), Tt = Symbol.for("@ts-pattern/isVari
464
474
  return Object.is(e, t);
465
475
  }, S = (t) => {
466
476
  var e, n, i;
467
- return ht(t) ? tt(t) ? (e = (n = (i = t[p]()).getSelectionKeys) == null ? void 0 : n.call(i)) != null ? e : [] : Array.isArray(t) ? Q(t, S) : Q(Object.values(t), S) : [];
477
+ return pt(t) ? tt(t) ? (e = (n = (i = t[p]()).getSelectionKeys) == null ? void 0 : n.call(i)) != null ? e : [] : Array.isArray(t) ? Q(t, S) : Q(Object.values(t), S) : [];
468
478
  }, Q = (t, e) => t.reduce((n, i) => n.concat(e(i)), []);
469
479
  function Me(...t) {
470
480
  if (t.length === 1) {
@@ -480,19 +490,19 @@ function Me(...t) {
480
490
  throw new Error(`isMatching wasn't given the right number of arguments: expected 1 or 2, received ${t.length}.`);
481
491
  }
482
492
  function h(t) {
483
- return Object.assign(t, { optional: () => vt(t), and: (e) => d(t, e), or: (e) => jt(t, e), select: (e) => e === void 0 ? $(t) : $(e, t) });
493
+ return Object.assign(t, { optional: () => wt(t), and: (e) => d(t, e), or: (e) => Tt(t, e), select: (e) => e === void 0 ? $(t) : $(e, t) });
484
494
  }
485
- function pt(t) {
495
+ function bt(t) {
486
496
  return Object.assign(((e) => Object.assign(e, { [Symbol.iterator]() {
487
497
  let n = 0;
488
- const i = [{ value: Object.assign(e, { [Tt]: !0 }), done: !1 }, { done: !0, value: void 0 }];
498
+ const i = [{ value: Object.assign(e, { [jt]: !0 }), done: !1 }, { done: !0, value: void 0 }];
489
499
  return { next: () => {
490
500
  var o;
491
501
  return (o = i[n++]) != null ? o : i.at(-1);
492
502
  } };
493
- } }))(t), { optional: () => pt(vt(t)), select: (e) => pt(e === void 0 ? $(t) : $(e, t)) });
503
+ } }))(t), { optional: () => bt(wt(t)), select: (e) => bt(e === void 0 ? $(t) : $(e, t)) });
494
504
  }
495
- function vt(t) {
505
+ function wt(t) {
496
506
  return h({ [p]: () => ({ match: (e) => {
497
507
  let n = {};
498
508
  const i = (o, s) => {
@@ -517,7 +527,7 @@ function d(...t) {
517
527
  return { matched: t.every((o) => A(o, e, i)), selections: n };
518
528
  }, getSelectionKeys: () => Q(t, S), matcherType: "and" }) });
519
529
  }
520
- function jt(...t) {
530
+ function Tt(...t) {
521
531
  return h({ [p]: () => ({ match: (e) => {
522
532
  let n = {};
523
533
  const i = (o, s) => {
@@ -561,7 +571,7 @@ const Vt = h(l(function(t) {
561
571
  }, regex: (e) => {
562
572
  return P(d(t, (n = e, l((i) => M(i) && !!i.match(n)))));
563
573
  var n;
564
- } }), 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))) }), Te = 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))) }), je = U(l(z)), Ve = h(l(function(t) {
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) {
565
575
  return typeof t == "boolean";
566
576
  })), _e = h(l(function(t) {
567
577
  return typeof t == "symbol";
@@ -570,8 +580,8 @@ const Vt = h(l(function(t) {
570
580
  })), We = h(l(function(t) {
571
581
  return t != null;
572
582
  }));
573
- var Be = { __proto__: null, matcher: p, optional: vt, array: function(...t) {
574
- return pt({ [p]: () => ({ match: (e) => {
583
+ var Oe = { __proto__: null, matcher: p, optional: wt, array: function(...t) {
584
+ return bt({ [p]: () => ({ match: (e) => {
575
585
  if (!Array.isArray(e)) return { matched: !1 };
576
586
  if (t.length === 0) return { matched: !0 };
577
587
  const n = t[0];
@@ -612,17 +622,17 @@ var Be = { __proto__: null, matcher: p, optional: vt, array: function(...t) {
612
622
  return c && m;
613
623
  }), selections: n };
614
624
  }, getSelectionKeys: () => t.length === 0 ? [] : [...S(t[0]), ...S(t[1])] }) });
615
- }, intersection: d, union: jt, not: function(t) {
625
+ }, intersection: d, union: Tt, not: function(t) {
616
626
  return h({ [p]: () => ({ match: (e) => ({ matched: !A(t, e, () => {
617
627
  }) }), getSelectionKeys: () => [], matcherType: "not" }) });
618
- }, when: l, select: $, any: Vt, _: Ue, string: qe, number: Te, bigint: je, boolean: Ve, symbol: _e, nullish: Ne, nonNullable: We, instanceOf: function(t) {
628
+ }, when: l, select: $, any: Vt, _: Ue, string: qe, number: je, bigint: Te, boolean: Ve, symbol: _e, nullish: Ne, nonNullable: We, instanceOf: function(t) {
619
629
  return h(l(/* @__PURE__ */ function(e) {
620
630
  return (n) => n instanceof e;
621
631
  }(t)));
622
632
  }, shape: function(t) {
623
633
  return h(l(Me(t)));
624
634
  } };
625
- class Oe extends Error {
635
+ class Be extends Error {
626
636
  constructor(e) {
627
637
  let n;
628
638
  try {
@@ -633,9 +643,9 @@ class Oe extends Error {
633
643
  super(`Pattern matching error: no pattern matches value ${n}`), this.input = void 0, this.input = e;
634
644
  }
635
645
  }
636
- const bt = { matched: !1, value: void 0 };
646
+ const St = { matched: !1, value: void 0 };
637
647
  function ot(t) {
638
- return new st(t, bt);
648
+ return new st(t, St);
639
649
  }
640
650
  class st {
641
651
  constructor(e, n) {
@@ -649,20 +659,20 @@ class st {
649
659
  let s = !1, r = {};
650
660
  const u = (c, m) => {
651
661
  s = !0, r[c] = m;
652
- }, a = !i.some((c) => A(c, this.input, u)) || o && !o(this.input) ? bt : { matched: !0, value: n(s ? it in r ? r[it] : r : this.input, this.input) };
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) };
653
663
  return new st(this.input, a);
654
664
  }
655
665
  when(e, n) {
656
666
  if (this.state.matched) return this;
657
667
  const i = !!e(this.input);
658
- return new st(this.input, i ? { matched: !0, value: n(this.input, this.input) } : bt);
668
+ return new st(this.input, i ? { matched: !0, value: n(this.input, this.input) } : St);
659
669
  }
660
670
  otherwise(e) {
661
671
  return this.state.matched ? this.state.value : e(this.input);
662
672
  }
663
673
  exhaustive() {
664
674
  if (this.state.matched) return this.state.value;
665
- throw new Oe(this.input);
675
+ throw new Be(this.input);
666
676
  }
667
677
  run() {
668
678
  return this.exhaustive();
@@ -671,7 +681,7 @@ class st {
671
681
  return this;
672
682
  }
673
683
  }
674
- function j(t, e) {
684
+ function T(t, e) {
675
685
  var n = 0, i, o;
676
686
  e = e || {};
677
687
  function s() {
@@ -717,22 +727,22 @@ function Le(t, e, n) {
717
727
  choiceValueId: a,
718
728
  state: c
719
729
  }),
720
- clearDecisions: () => T(
730
+ clearDecisions: () => j(
721
731
  i,
722
732
  Fe,
723
733
  // Only execute if there are decisions to clear.
724
734
  K.fromPredicate(k.isNonEmpty),
725
735
  K.match(
726
736
  () => () => Promise.resolve(),
727
- (a) => T(() => u(a, { type: "KeepExistingDecisions" }), Lt.map(Kt))
737
+ (a) => j(() => u(a, { type: "KeepExistingDecisions" }), Lt.map(Kt))
728
738
  )
729
739
  )(),
730
- isMultiSelect: j(() => O.isChoiceAttributeMultiSelect(i)),
731
- getAllowedChoiceValues: j(() => O.getAllowedChoiceValues(i)),
732
- getIncludedChoiceValues: j(() => O.getIncludedChoiceValues(i)),
733
- getBlockedChoiceValues: j(() => O.getBlockedChoiceValues(i)),
734
- isChoiceValueAllowed: j((a) => wt.isAllowed(a)),
735
- isChoiceValueBlocked: j((a) => wt.isBlocked(a))
740
+ isMultiSelect: T(() => B.isChoiceAttributeMultiSelect(i)),
741
+ getAllowedChoiceValues: T(() => B.getAllowedChoiceValues(i)),
742
+ getIncludedChoiceValues: T(() => B.getIncludedChoiceValues(i)),
743
+ getBlockedChoiceValues: T(() => B.getBlockedChoiceValues(i)),
744
+ isChoiceValueAllowed: T((a) => Et.isAllowed(a)),
745
+ isChoiceValueBlocked: T((a) => Et.isBlocked(a))
736
746
  };
737
747
  }
738
748
  );
@@ -799,14 +809,14 @@ function dt(t, e, n, i, o) {
799
809
  const { explain: m, applySolution: Y } = u(e), R = o(c, r, u);
800
810
  return R === E ? E : {
801
811
  attribute: c,
802
- isMandatory: j(() => O.isMandatory(c)),
812
+ isMandatory: T(() => B.isMandatory(c)),
803
813
  explain: (F, Z) => {
804
814
  const V = ot(F.question).with(It.whyIsNotSatisfied, () => N.attribute).otherwise(() => i), C = {
805
815
  ...F,
806
816
  subject: V,
807
817
  attributeId: c.id
808
818
  };
809
- return ot(Z).with("decisions", (B) => m(C, B)).with("constraints", (B) => m(C, B)).with("full", (B) => m(C, B)).exhaustive();
819
+ return ot(Z).with("decisions", (O) => m(C, O)).with("constraints", (O) => m(C, O)).with("full", (O) => m(C, O)).exhaustive();
810
820
  },
811
821
  applySolution: Y,
812
822
  ...R
@@ -829,7 +839,7 @@ function He(t, e, n, i, o, s) {
829
839
  o,
830
840
  s
831
841
  ], u = f((a) => {
832
- const c = T(
842
+ const c = j(
833
843
  r,
834
844
  k.every((R) => a(R) !== E)
835
845
  ), m = a(t);
@@ -1014,15 +1024,15 @@ function ln() {
1014
1024
  const mn = "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.";
1015
1025
  function dn(t) {
1016
1026
  const { primitives: { sessionManagementMachineAtom: e } } = W(), n = Ft(e);
1017
- return gt(() => {
1027
+ return At(() => {
1018
1028
  n({ type: "SessionContextChanged", sessionContext: t.sessionContext }), t.sessionContext || console.warn(mn);
1019
- }, [t.sessionContext]), gt(() => () => {
1029
+ }, [t.sessionContext]), At(() => () => {
1020
1030
  n({ type: "Shutdown" });
1021
1031
  }, []), null;
1022
1032
  }
1023
- function qn(t) {
1033
+ function Un(t) {
1024
1034
  const e = X(() => ln(), []);
1025
- return /* @__PURE__ */ q(Pt, { children: /* @__PURE__ */ q(Ut.Provider, { value: e, children: /* @__PURE__ */ q(fn, { jotaiStore: t.jotaiStore, children: /* @__PURE__ */ Xt(gn, { children: [
1035
+ return /* @__PURE__ */ q(Pt, { children: /* @__PURE__ */ q(Ut.Provider, { value: e, children: /* @__PURE__ */ q(fn, { jotaiStore: t.jotaiStore, children: /* @__PURE__ */ Ht(gn, { children: [
1026
1036
  /* @__PURE__ */ q(dn, { sessionContext: t.sessionContext }),
1027
1037
  /* @__PURE__ */ q(se, {}),
1028
1038
  t.children
@@ -1035,25 +1045,25 @@ function gn(t) {
1035
1045
  const e = ct();
1036
1046
  return /* @__PURE__ */ q($t, { store: e, children: t.children });
1037
1047
  }
1038
- function Tn() {
1048
+ function qn() {
1039
1049
  const { selectors: { configurationInitializationAtom: t } } = W(), e = ct();
1040
- return yt(t, { store: e });
1050
+ return Ct(t, { store: e });
1041
1051
  }
1042
1052
  function jn() {
1043
1053
  const { selectors: { configurationUpdatingAtom: t } } = W(), e = ct();
1044
- return yt(t, { store: e });
1054
+ return Ct(t, { store: e });
1045
1055
  }
1046
- const Vn = y((t) => t.explainAtom, (t) => t.explainAtom), _n = y((t) => t.guardedConfigurationAtom, (t) => t.configurationAtom), Nn = y((t) => t.configurationSatisfactionAtom, (t) => t.configurationSatisfactionAtom), Wn = y((t) => t.configurationStoringAtom, (t) => t.configurationStoringAtom), Bn = y((t) => t.configurationResetAtom, (t) => t.configurationResetAtom), On = y((t) => t.sessionReinitializationAtom, (t) => t.sessionReinitializationAtom), Ln = y((t) => t.taskSchedulingAtom, (t) => t.taskSchedulingAtom), Kn = y((t) => t.guardedStoredConfigurationAtom, (t) => t.storedConfigurationAtom), Qn = y((t) => t.makeDecisionAtom, (t) => t.makeDecisionAtom), $n = y((t) => t.decisionQueriesAtom, (t) => t.decisionQueriesAtom), An = y((t) => t.guardedDecisionsAtom, (t) => t.decisionsAtom), hn = y((t) => t.guardedExplicitDecisionsAtom, (t) => t.explicitDecisionsAtom), pn = y((t) => t.guardedImplicitDecisionsAtom, (t) => t.implicitDecisionsAtom);
1047
- function Jn(t, e) {
1048
- const n = typeof t == "string" ? t : void 0, i = typeof t == "boolean" ? t : e, o = X(() => ot(n).returnType().with(Be.nullish, () => An).with(L.Explicit, () => hn).with(L.Implicit, () => pn).exhaustive(), [n]);
1056
+ const Tn = y((t) => t.explainAtom, (t) => t.explainAtom), Vn = y((t) => t.guardedConfigurationAtom, (t) => t.configurationAtom), _n = y((t) => t.configurationSatisfactionAtom, (t) => t.configurationSatisfactionAtom), Nn = y((t) => t.configurationStoringAtom, (t) => t.configurationStoringAtom), Wn = y((t) => t.configurationResetAtom, (t) => t.configurationResetAtom), On = y((t) => t.sessionReinitializationAtom, (t) => t.sessionReinitializationAtom), Bn = y((t) => t.taskSchedulingAtom, (t) => t.taskSchedulingAtom), Ln = y((t) => t.guardedStoredConfigurationAtom, (t) => t.storedConfigurationAtom), Kn = y((t) => t.makeDecisionAtom, (t) => t.makeDecisionAtom), Qn = y((t) => t.decisionQueriesAtom, (t) => t.decisionQueriesAtom), An = y((t) => t.guardedDecisionsAtom, (t) => t.decisionsAtom), hn = y((t) => t.guardedExplicitDecisionsAtom, (t) => t.explicitDecisionsAtom), pn = y((t) => t.guardedImplicitDecisionsAtom, (t) => t.implicitDecisionsAtom);
1057
+ function $n(t, e) {
1058
+ const n = typeof t == "string" ? t : void 0, i = typeof t == "boolean" ? t : e, o = X(() => ot(n).returnType().with(Oe.nullish, () => An).with(L.Explicit, () => hn).with(L.Implicit, () => pn).exhaustive(), [n]);
1049
1059
  return i === !1 ? o(!1) : o();
1050
1060
  }
1051
- function Hn() {
1061
+ function Jn() {
1052
1062
  const { selectors: t } = W();
1053
1063
  return X(() => ({
1054
1064
  getConfigurationInitializationAtom: t.configurationInitializationAtom,
1055
1065
  getConfigurationUpdatingAtom: t.configurationUpdatingAtom,
1056
- createAttributesAtom: At(t),
1066
+ createAttributesAtom: ht(t),
1057
1067
  getChoiceAttributeAtomFamily: t.choiceAttributeAtomFamily,
1058
1068
  getNumericAttributeAtomFamily: t.numericAttributeAtomFamily,
1059
1069
  getBooleanAttributeAtomFamily: t.booleanAttributeAtomFamily,
@@ -1074,26 +1084,26 @@ function Hn() {
1074
1084
  }), [t]);
1075
1085
  }
1076
1086
  export {
1077
- qn as Configuration,
1087
+ Un as Configuration,
1078
1088
  E as ConfigurationUninitialized,
1079
- Fn as useAttributes,
1080
- Pn as useBooleanAttribute,
1081
- Mn as useChoiceAttribute,
1082
- Un as useComponentAttribute,
1083
- _n as useConfiguration,
1084
- Tn as useConfigurationInitialization,
1085
- Bn as useConfigurationReset,
1086
- Nn as useConfigurationSatisfaction,
1087
- Wn as useConfigurationStoring,
1089
+ Rn as useAttributes,
1090
+ zn as useBooleanAttribute,
1091
+ Fn as useChoiceAttribute,
1092
+ Pn as useComponentAttribute,
1093
+ Vn as useConfiguration,
1094
+ qn as useConfigurationInitialization,
1095
+ Wn as useConfigurationReset,
1096
+ _n as useConfigurationSatisfaction,
1097
+ Nn as useConfigurationStoring,
1088
1098
  jn as useConfigurationUpdating,
1089
1099
  ct as useConfiguratorStore,
1090
- $n as useDecisionQueries,
1091
- Jn as useDecisions,
1092
- Vn as useExplain,
1093
- Hn as useJotaiAtoms,
1094
- Qn as useMakeDecision,
1095
- zn as useNumericAttribute,
1100
+ Qn as useDecisionQueries,
1101
+ $n as useDecisions,
1102
+ Tn as useExplain,
1103
+ Jn as useJotaiAtoms,
1104
+ Kn as useMakeDecision,
1105
+ Mn as useNumericAttribute,
1096
1106
  On as useSessionReinitialization,
1097
- Kn as useStoredConfiguration,
1098
- Ln as useTaskScheduling
1107
+ Ln as useStoredConfiguration,
1108
+ Bn as useTaskScheduling
1099
1109
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@viamedici-spc/configurator-react",
3
- "version": "2.1.0-fixWindowNotDefined-20241112132136",
3
+ "version": "2.1.0-sessionUpdateErrorIsNotRemovedOnRetry-20250106091418",
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": [
@@ -54,7 +54,7 @@
54
54
  "vitest": "^2.1.1"
55
55
  },
56
56
  "dependencies": {
57
- "@viamedici-spc/configurator-ts": "2.2.0-bundle-fp-ts-20241112131837",
57
+ "@viamedici-spc/configurator-ts": "2.2.0-setSessionContextFix-20241211151333",
58
58
  "@viamedici-spc/fp-ts-extensions": "^1.2.0",
59
59
  "dyna-guid": "^2.2.1",
60
60
  "fp-ts-react-stable-hooks": "^1.5.0",