@viamedici-spc/configurator-react 0.1.0-alpha0024 → 0.1.0-alpha0026
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 +1 -1
- package/dist/index.d.ts +35 -5
- package/dist/index.js +298 -276
- package/package.json +4 -3
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("@viamedici-spc/configurator-ts"),s=require("@viamedici-spc/fp-ts-extensions"),a=require("react"),m=require("react/jsx-runtime"),r=require("xstate"),g=require("xstate/lib/actions"),M=require("@viamedici-spc/fp-ts-extensions/Eq"),z=require("fast-equals"),_=require("@xstate/react"),D=a.createContext(null),I=a.createContext(null),O=a.createContext(null),T=a.createContext(null),P=()=>a.useContext(D),S=()=>a.useContext(T),w="The configuration is not initialized. Consider using the ConfigurationSuspender or unload components manually that make use of any unsafe hook while the configuration is initializing. Check the hooks documentation to see if it is safe to use while the configuration is initializing.";function q(e){if(!e)throw new Error(w)}function y(e){if(!e)throw new Error(w)}function h(){const e=P();return q(e),a.useMemo(()=>({makeDecision:n=>e.makeDecision(n),setManyDecision:(n,i)=>e.setMany(n,i)}),[e])}globalThis&&globalThis.__spreadArray;var j=function(e){return e._tag==="Some"},E=function(e){return function(n){return j(e(n))}};const F=E(e=>e.type===u.AttributeType.Choice?s.some(e):s.none),B=E(e=>e.type===u.AttributeType.Numeric?s.some(e):s.none),H=E(e=>e.type===u.AttributeType.Boolean?s.some(e):s.none),K=E(e=>e.type===u.AttributeType.Component?s.some(e):s.none);function A(e){return e.decision!=null&&e.decision.kind===u.DecisionKind.Explicit}function N(e){return s.pipe(e.values,s.RA.filter(A),s.RA.map(n=>({type:u.AttributeType.Choice,attributeId:e.id,choiceValueId:n.id,state:null})))}function V(e){return s.pipe(e,s.O.fromPredicate(A),s.O.map(()=>({type:u.AttributeType.Numeric,attributeId:e.id,state:null})))}function $(e){return s.pipe(e,s.O.fromPredicate(A),s.O.map(()=>({type:u.AttributeType.Boolean,attributeId:e.id,state:null})))}function G(e){return s.pipe(e,s.O.fromPredicate(A),s.O.map(()=>({type:u.AttributeType.Component,attributeId:e.id,state:null})))}function J(e,n){return s.pipe(u.ConfigurationInterpreter.filterAttributesOfComponent(n,e,!0),i=>[s.pipe(i,s.RA.filter(F),s.RA.chain(N)),s.pipe(i,s.RA.filter(B),s.RA.map(V),s.RA.compact),s.pipe(i,s.RA.filter(H),s.RA.map($),s.RA.compact),s.pipe(i,s.RA.filter(K),s.RA.map(G),s.RA.compact)],s.RA.flatten)}function L(e,n=!1){const i=S();return y(i),a.useMemo(()=>s.pipe(s.O.fromNullable(e),s.O.map(s.flow(s.RA.map(t=>u.ConfigurationInterpreter.getAttribute(i,t)),n?s.RA.filterMap(s.O.fromNullable):s.identity)),s.O.getOrElse(()=>i.attributes)),[e,i,n])}function Q(e){const n=S(),{makeDecision:i,setManyDecision:t}=h();y(n);const o=u.ConfigurationInterpreter.getChoiceAttribute(n,e),l=a.useMemo(()=>({makeDecision:(p,c)=>i({type:u.AttributeType.Choice,attributeId:e,choiceValueId:p,state:c}),clearDecisions:s.pipe(o,s.O.fromNullable,s.O.map(N),s.O.filter(s.RA.isNonEmpty),s.O.map(p=>()=>t(p,{type:"Default"})),s.O.getOrElse(()=>()=>Promise.resolve()))}),[e,o,i,t]),d=a.useMemo(()=>({...l,attribute:o}),[o,l]);if(o)return d}function W(e){const n=S(),{makeDecision:i}=h();y(n);const t=u.ConfigurationInterpreter.getNumericAttribute(n,e),o=a.useMemo(()=>({makeDecision:d=>i({type:u.AttributeType.Numeric,attributeId:e,state:d})}),[e,i]),l=a.useMemo(()=>({...o,attribute:t}),[t,o]);if(t)return l}function X(e){const n=S(),{makeDecision:i}=h();y(n);const t=u.ConfigurationInterpreter.getBooleanAttribute(n,e),o=a.useMemo(()=>({makeDecision:d=>i({type:u.AttributeType.Boolean,attributeId:e,state:d})}),[e,i]),l=a.useMemo(()=>({...o,attribute:t}),[t,o]);if(t)return l}function Y(e){const n=S(),{makeDecision:i,setManyDecision:t}=h();y(n);const o=n.attributes,l=u.ConfigurationInterpreter.getComponentAttribute(n,e),d=a.useMemo(()=>({makeDecision:c=>i({type:u.AttributeType.Component,attributeId:e,state:c}),clearSubtree:s.pipe(J(e,o),s.O.fromPredicate(s.RA.isNonEmpty),s.O.map(c=>()=>t(c,{type:"Default"})),s.O.getOrElse(()=>()=>Promise.resolve()))}),[e,i,o,t]),p=a.useMemo(()=>({...d,attribute:l}),[l,d]);if(l)return p}const Z=s.Eq.fromEquals((e,n)=>s.RR.getEq(s.Str.Eq).equals(e??{},n??{})),ee=s.Eq.struct({attributeId:s.Eq.fromEquals(u.globalAttributeIdEquals),decisions:s.RA.getEq(s.Eq.fromEquals(u.globalAttributeIdEquals))}),ne=s.Eq.fromEquals((e,n)=>s.RA.getEq(ee).equals(e??[],n??[])),b=s.Eq.struct({configurationModelSource:s.Eq.fromEquals((e,n)=>z.deepEqual(e,n)),attributeRelations:ne,usageRuleParameters:Z}),se=s.Eq.eqStrict,R=M.eqNullable(se),ie=()=>r.createMachine({predictableActionArguments:!0,preserveActionOrder:!0,schema:{context:{},events:{}},context:{desiredClient:null,desiredSessionContext:null,actualClient:null,session:null,sessionCreationError:null,sessionUpdateError:null,hasEverSuccessfullyCreatedSession:!1},initial:"ProcessChanges",on:{ChangeConfigurationClient:{actions:["saveDesiredClient"]},ChangeSessionContext:{actions:["saveDesiredSessionContext"]}},exit:[g.log("Shutting down","SessionManagement:"),"disposeOldSession"],states:{ProcessChanges:{entry:[g.log("Entering ProcessChanges","SessionManagement:"),f(2)],always:[{target:"DisposeSession",cond:"shallDisposeSession"},{target:"CreateSession",cond:"shallCreateSession"},{target:"UpdateSession",cond:"shallUpdateSession"}]},DisposeSession:{entry:[g.log("Entering DisposeSession","SessionManagement:"),f(2)],always:{actions:["disposeOldSession"],target:"ProcessChanges"}},CreateSession:{entry:[g.log("Entering CreateSession","SessionManagement:"),f(0)],invoke:{id:"getNewSession",src:"createSession",onDone:{actions:["setSessionCreationResult","setHasEverSuccessfullyCreatedSession"],target:"ProcessChanges"},onError:{actions:"setSessionCreationError",target:"SessionCreationFailed"}}},SessionCreationFailed:{entry:[g.log("Entering SessionCreationFailed","SessionManagement:"),f(2)],always:{target:"ProcessChanges",cond:"shallImmediatelyProcessChangesAfterSessionCreationError"},exit:[g.log("Exiting SessionCreationFailed","SessionManagement:"),"clearSessionCreationError"],on:{RetrySessionCreation:{target:"ProcessChanges",actions:g.log("Retrying session creation","SessionManagement:")}}},UpdateSession:{entry:[g.log("Entering UpdateSession","SessionManagement:"),f(1)],invoke:{id:"updateExistingSession",src:"updateSession",onDone:{target:"ProcessChanges"},onError:{actions:"setSessionUpdateError",target:"SessionUpdateFailed"}}},SessionUpdateFailed:{entry:[g.log("Entering SessionUpdateFailed","SessionManagement:"),f(2)],always:{target:"ProcessChanges",cond:"shallImmediatelyProcessChangesAfterSessionUpdateError"},exit:[g.log("Exiting SessionUpdateFailed","SessionManagement:"),"clearSessionUpdateError"],on:{RetrySessionUpdate:{target:"ProcessChanges",actions:g.log("Retrying session update","SessionManagement:")}}}}},{actions:{saveDesiredClient:r.assign({desiredClient:(e,n)=>n.client}),saveDesiredSessionContext:r.assign({desiredSessionContext:(e,n)=>n.sessionContext}),disposeOldSession:r.assign((e,n)=>(e.session&&e.session.close().then(s.constVoid).catch(i=>{}),{session:null,actualClient:null})),setSessionCreationResult:r.assign((e,n)=>({session:n.data.session,actualClient:n.data.client})),setSessionCreationError:r.assign((e,n)=>({sessionCreationError:n.data})),clearSessionCreationError:r.assign({sessionCreationError:()=>null}),setSessionUpdateError:r.assign((e,n)=>({sessionUpdateError:n.data})),clearSessionUpdateError:r.assign({sessionUpdateError:()=>null}),setHasEverSuccessfullyCreatedSession:r.assign({hasEverSuccessfullyCreatedSession:()=>!0})},services:{createSession:e=>e.desiredClient.createSession(e.desiredSessionContext).then(n=>({session:n,client:e.desiredClient})).catch(n=>Promise.reject({type:n.type,client:e.desiredClient,sessionContext:e.desiredSessionContext})),updateSession:e=>e.session.setSessionContext(e.desiredSessionContext).catch(n=>Promise.reject({type:n.type,sessionContext:e.desiredSessionContext}))},guards:{shallDisposeSession:e=>e.session!=null&&(e.desiredSessionContext==null||e.desiredClient==null||!R.equals(e.actualClient,e.desiredClient)),shallCreateSession:e=>e.session==null&&e.desiredClient!=null&&e.desiredSessionContext!=null,shallUpdateSession:e=>e.session!=null&&!b.equals(e.session.getSessionContext(),e.desiredSessionContext),shallImmediatelyProcessChangesAfterSessionCreationError:e=>!R.equals(e.desiredClient,e.sessionCreationError.client)||!M.eqNullable(b).equals(e.desiredSessionContext,e.sessionCreationError.sessionContext),shallImmediatelyProcessChangesAfterSessionUpdateError:e=>!R.equals(e.desiredClient,e.actualClient)||!M.eqNullable(b).equals(e.desiredSessionContext,e.sessionUpdateError.sessionContext)}});function f(e){const n=e===0,i=e===1;return g.pure((t,o)=>{const l={isInitializing:(!t.hasEverSuccessfullyCreatedSession||n)&&t.sessionCreationError==null,errorType:t.sessionCreationError&&t.sessionCreationError.type},d={isUpdating:i&&t.sessionUpdateError==null,errorType:t.sessionUpdateError&&t.sessionUpdateError.type};return r.sendParent({type:"SessionManagementStateChanged",sessionInitialization:l,sessionUpdating:d,session:t.session})})}const te=e=>n=>(n({type:"ConfigurationChanged",session:e,configuration:e.getConfiguration()}),e.setOnConfigurationChangedHandler(i=>{n({type:"ConfigurationChanged",session:e,configuration:i})}),()=>{e.setOnConfigurationChangedHandler(null)}),oe=()=>r.createMachine({predictableActionArguments:!0,preserveActionOrder:!0,schema:{context:{},events:{}},context:{session:null},on:{ConfigurationChanged:{actions:[r.sendParent((e,n)=>n)]}},initial:"ProcessChanges",states:{ProcessChanges:{entry:[g.log("Entering ProcessChanges","ConfigurationSubscriptionManagement:")],on:{ChangeSession:{actions:["saveSession"]}},always:[{target:"Subscribe",cond:(e,n)=>e.session!=null}]},Subscribe:{entry:[g.log("Entering Subscribe","ConfigurationSubscriptionManagement:")],on:{ChangeSession:{target:"ProcessChanges",cond:(e,n)=>n.session==null||e.session!==n.session,actions:["saveSession"]}},invoke:{id:"configurationSubscriptionActor",src:(e,n)=>te(e.session)}}}},{actions:{saveSession:r.assign((e,n)=>({session:n.session}))}}),re=()=>{let e,n;return{promise:new Promise((t,o)=>{e=t,n=o}),resolve:e,reject:n}},U=()=>{const e=re();return{capsule:{promise:e.promise},resolve:e.resolve,reject:e.reject}},ae=()=>r.createMachine({predictableActionArguments:!0,preserveActionOrder:!0,schema:{context:{},events:{}},context:{sessionManagementActor:null,configurationSubscriptionManagementActor:null,sessionInitialization:null,sessionUpdating:null,session:null,configuration:null,isReadyPromise:U()},entry:[r.assign({sessionManagementActor:()=>r.spawn(ie()),configurationSubscriptionManagementActor:()=>r.spawn(oe())})],exit:[g.stop(e=>e.sessionManagementActor),g.stop(e=>e.configurationSubscriptionManagementActor)],on:{ChangeConfigurationClient:{actions:[r.forwardTo(e=>e.sessionManagementActor)]},ChangeSessionContext:{actions:[r.forwardTo(e=>e.sessionManagementActor)]},RetrySessionCreation:{actions:[r.forwardTo(e=>e.sessionManagementActor)]},RetrySessionUpdate:{actions:[r.forwardTo(e=>e.sessionManagementActor)]},SessionManagementStateChanged:{actions:[r.assign((e,n)=>({session:n.session,sessionInitialization:n.sessionInitialization,sessionUpdating:n.sessionUpdating})),r.send(e=>({type:"ChangeSession",session:e.session}),{to:e=>e.configurationSubscriptionManagementActor}),"calculateReadyState"]},ConfigurationChanged:{actions:[r.assign((e,n)=>({configuration:{session:n.session,configuration:n.configuration}})),"calculateReadyState"]}},initial:"Idle",states:{Idle:{}}},{actions:{calculateReadyState:r.assign((e,n)=>{var o;const i=!((o=e.sessionInitialization)!=null&&o.isInitializing)&&e.session!=null&&e.configuration!=null&&e.configuration.session===e.session;return e.isReadyPromise&&i&&(e.isReadyPromise.resolve(),e.isReadyPromise.capsule.promise=null),{isReadyPromise:(()=>i?null:e.isReadyPromise!=null?e.isReadyPromise:U())()}})}});function ue(e){var d,p;const[n,i]=_.useMachine(ae,{logger:(...c)=>console.log("ConfigurationManagement:",...c)});a.useEffect(()=>{i({type:"ChangeConfigurationClient",client:e.configuratorClient}),e.configuratorClient||console.warn("The configurator client is null or undefined. This will dispose the session that may exist. If this was not intended, make sure you pass a valid client.")},[e.configuratorClient]),a.useEffect(()=>{const c=s.pipe(s.O.fromNullable(e.sessionContext),s.O.chainFirst(C=>s.O.fromNullable(C.configurationModelSource)),s.O.toNullable);i({type:"ChangeSessionContext",sessionContext:c}),c||console.warn("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.")},[e.sessionContext]);const t=a.useMemo(()=>{var c,C,x,v;return{isInitializing:((C=(c=n.context.isReadyPromise)==null?void 0:c.capsule)==null?void 0:C.promise)!=null,isInitializingPromise:(x=n.context.isReadyPromise)==null?void 0:x.capsule,error:((v=n.context.sessionInitialization)==null?void 0:v.errorType)&&{type:n.context.sessionInitialization.errorType,retry:()=>i({type:"RetrySessionCreation"})}}},[n.context.sessionInitialization,n.context.isReadyPromise]),o=a.useMemo(()=>{var c,C;return{isUpdating:(c=n.context.sessionUpdating)==null?void 0:c.isUpdating,error:((C=n.context.sessionUpdating)==null?void 0:C.errorType)&&{type:n.context.sessionUpdating.errorType,retry:()=>i({type:"RetrySessionUpdate"})}}},[n.context.sessionUpdating]),l=((d=n.context.configuration)==null?void 0:d.session)===n.context.session?(p=n.context.configuration)==null?void 0:p.configuration:null;return{configurationInitialization:t,configurationUpdating:o,session:n.context.session,configuration:l}}function le(e){const{configurationInitialization:n,configurationUpdating:i,session:t,configuration:o}=ue({configuratorClient:e.configuratorClient,sessionContext:e});return m.jsx(I.Provider,{value:n,children:m.jsx(O.Provider,{value:i,children:m.jsx(D.Provider,{value:t,children:m.jsx(T.Provider,{value:o,children:e.children})})})})}function k(){return a.useContext(I)}function ce(){return a.useContext(O)}function ge(e){const{children:n}=e,{isInitializingPromise:i}=k();if(i!=null&&i.promise)throw i.promise;return m.jsx(m.Fragment,{children:n})}function de(){const e=P();return q(e),a.useMemo(()=>({}),[e])}function pe(){const e=P(),n=S();return q(e),y(n),a.useMemo(()=>({configuration:n,restoreConfiguration:i=>e.restoreConfiguration(i)}),[n,e])}exports.Configuration=le;exports.ConfigurationSuspender=ge;exports.useAttributes=L;exports.useBooleanAttribute=X;exports.useChoiceAttribute=Q;exports.useComponentAttribute=Y;exports.useConfiguration=pe;exports.useConfigurationInitialization=k;exports.useConfigurationUpdating=ce;exports.useDecision=h;exports.useExplain=de;exports.useNumericAttribute=W;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=require("@viamedici-spc/configurator-ts"),s=require("@viamedici-spc/fp-ts-extensions"),u=require("react"),A=require("ts-pattern"),m=require("react/jsx-runtime"),l=require("xstate"),p=require("xstate/lib/actions"),Q=require("fast-equals"),H=require("@xstate/react"),D=u.createContext(null),O=u.createContext(null),N=u.createContext(null),k=u.createContext(null),M=()=>u.useContext(D),S=()=>u.useContext(k),z="The configuration is not initialized. Consider using the ConfigurationSuspender or unload components manually that make use of any unsafe hook while the configuration is initializing. Check the hooks documentation to see if it is safe to use while the configuration is initializing.";function w(e){if(!e)throw new Error(z)}function y(e){if(!e)throw new Error(z)}function E(){const e=M();return w(e),u.useMemo(()=>({makeDecision:n=>e.makeDecision(n),setManyDecision:(n,t)=>e.setMany(n,t)}),[e])}globalThis&&globalThis.__spreadArray;var V=function(e){return e._tag==="Some"},x=function(e){return function(n){return V(e(n))}};const K=x(e=>e.type===o.AttributeType.Choice?s.some(e):s.none),$=x(e=>e.type===o.AttributeType.Numeric?s.some(e):s.none),G=x(e=>e.type===o.AttributeType.Boolean?s.some(e):s.none),J=x(e=>e.type===o.AttributeType.Component?s.some(e):s.none);function R(e){return e.decision!=null&&e.decision.kind===o.DecisionKind.Explicit}function j(e){return s.pipe(e.values,s.RA.filter(R),s.RA.map(n=>({type:o.AttributeType.Choice,attributeId:e.id,choiceValueId:n.id,state:null})))}function L(e){return s.pipe(e,s.O.fromPredicate(R),s.O.map(()=>({type:o.AttributeType.Numeric,attributeId:e.id,state:null})))}function W(e){return s.pipe(e,s.O.fromPredicate(R),s.O.map(()=>({type:o.AttributeType.Boolean,attributeId:e.id,state:null})))}function X(e){return s.pipe(e,s.O.fromPredicate(R),s.O.map(()=>({type:o.AttributeType.Component,attributeId:e.id,state:null})))}function Y(e,n){return s.pipe(o.ConfigurationInterpreter.filterAttributesOfComponent(n,e,!0),t=>[s.pipe(t,s.RA.filter(K),s.RA.chain(j)),s.pipe(t,s.RA.filter($),s.RA.map(L),s.RA.compact),s.pipe(t,s.RA.filter(G),s.RA.map(W),s.RA.compact),s.pipe(t,s.RA.filter(J),s.RA.map(X),s.RA.compact)],s.RA.flatten)}function _(){const e=M();return w(e),u.useMemo(()=>({explain:(n,t)=>A.match(t).with("decisions",i=>e.explain(n,i)).with("constraints",i=>e.explain(n,i)).with("full",i=>e.explain(n,i)).exhaustive(),applySolution:n=>e.applySolution(n)}),[e])}function Z(e,n=!1){const t=S();return y(t),u.useMemo(()=>s.pipe(s.O.fromNullable(e),s.O.map(s.flow(s.RA.map(i=>o.ConfigurationInterpreter.getAttribute(t,i)),n?s.RA.filterMap(s.O.fromNullable):s.identity)),s.O.getOrElse(()=>t.attributes)),[e,t,n])}function ee(e){const n=S(),{makeDecision:t,setManyDecision:i}=E(),r=b(e,o.ExplainQuestionSubject.choiceValue);y(n);const a=o.ConfigurationInterpreter.getChoiceAttribute(n,e),g=u.useMemo(()=>({makeDecision:(c,f)=>t({type:o.AttributeType.Choice,attributeId:e,choiceValueId:c,state:f}),clearDecisions:s.pipe(a,s.O.fromNullable,s.O.map(j),s.O.filter(s.RA.isNonEmpty),s.O.map(c=>()=>i(c,{type:"Default"})),s.O.getOrElse(()=>()=>Promise.resolve())),...r}),[e,a,t,i,r]),d=u.useMemo(()=>({...g,attribute:a}),[a,g]);if(a)return d}function ne(e){const n=S(),{makeDecision:t}=E(),i=b(e,o.ExplainQuestionSubject.numeric);y(n);const r=o.ConfigurationInterpreter.getNumericAttribute(n,e),a=u.useMemo(()=>({makeDecision:d=>t({type:o.AttributeType.Numeric,attributeId:e,state:d}),...i}),[e,t,i]),g=u.useMemo(()=>({...a,attribute:r}),[r,a]);if(r)return g}function se(e){const n=S(),{makeDecision:t}=E(),i=b(e,o.ExplainQuestionSubject.boolean);y(n);const r=o.ConfigurationInterpreter.getBooleanAttribute(n,e),a=u.useMemo(()=>({makeDecision:d=>t({type:o.AttributeType.Boolean,attributeId:e,state:d}),...i}),[e,t,i]),g=u.useMemo(()=>({...a,attribute:r}),[r,a]);if(r)return g}function te(e){const n=S(),{makeDecision:t,setManyDecision:i}=E(),r=b(e,o.ExplainQuestionSubject.component);y(n);const a=n.attributes,g=o.ConfigurationInterpreter.getComponentAttribute(n,e),d=u.useMemo(()=>({makeDecision:f=>t({type:o.AttributeType.Component,attributeId:e,state:f}),clearSubtree:s.pipe(Y(e,a),s.O.fromPredicate(s.RA.isNonEmpty),s.O.map(f=>()=>i(f,{type:"Default"})),s.O.getOrElse(()=>()=>Promise.resolve())),...r}),[e,t,a,i,r]),c=u.useMemo(()=>({...d,attribute:g}),[g,d]);if(g)return c}function b(e,n){const{explain:t,applySolution:i}=_();return u.useMemo(()=>({explain:(r,a)=>{const g=A.match(r.question).with(o.ExplainQuestionType.whyIsNotSatisfied,()=>o.ExplainQuestionSubject.attribute).otherwise(()=>n),d={...r,subject:g,attributeId:e};return A.match(a).with("decisions",c=>t(d,c)).with("constraints",c=>t(d,c)).with("full",c=>t(d,c)).exhaustive()},applySolution:i}),[e,n,t,i])}const I=s.Eq.fromEquals(o.globalAttributeIdEquals),ie=s.Eq.fromEquals(o.globalConstraintIdEquals),oe=s.Eq.fromEquals((e,n)=>s.RR.getEq(s.Str.Eq).equals(e??{},n??{})),re=s.Eq.struct({attributeId:I,decisions:s.RA.getEq(I)}),ae=s.Eq.fromEquals((e,n)=>s.RA.getEq(re).equals(e??[],n??[])),le=s.Eq.struct({type:s.Str.Eq}),ue=s.Eq.struct({type:s.Str.Eq}),ce=s.Eq.struct({type:s.Str.Eq,rules:s.RA.getEq(ie)}),ge=s.Eq.fromEquals((e,n)=>A.match({x:e,y:n}).returnType().with({x:{type:o.AllowedRulesInExplainType.all},y:{type:o.AllowedRulesInExplainType.all}},({x:t,y:i})=>le.equals(t,i)).with({x:{type:o.AllowedRulesInExplainType.none},y:{type:o.AllowedRulesInExplainType.none}},({x:t,y:i})=>ue.equals(t,i)).with({x:{type:o.AllowedRulesInExplainType.specific},y:{type:o.AllowedRulesInExplainType.specific}},({x:t,y:i})=>ce.equals(t,i)).otherwise(()=>!1)),pe=s.Eq.struct({rules:s.Eq.eqNullable(ge)}),F=s.Eq.struct({configurationModelSource:s.Eq.fromEquals((e,n)=>Q.deepEqual(e,n)),attributeRelations:ae,usageRuleParameters:oe,allowedInExplain:s.Eq.eqNullable(pe)}),q=s.Eq.eqNullable(F),de=s.Eq.eqStrict,h=s.Eq.eqNullable(de),fe=()=>l.createMachine({predictableActionArguments:!0,preserveActionOrder:!0,schema:{context:{},events:{}},context:{desiredClient:null,desiredSessionContext:null,actualClient:null,session:null,sessionCreationError:null,sessionUpdateError:null,hasEverSuccessfullyCreatedSession:!1},initial:"ProcessChanges",on:{ChangeConfigurationClient:{actions:["saveDesiredClient"]},ChangeSessionContext:{actions:["saveDesiredSessionContext"]}},exit:[p.log("Shutting down","SessionManagement:"),"disposeOldSession"],states:{ProcessChanges:{entry:[p.log("Entering ProcessChanges","SessionManagement:"),C(2)],always:[{target:"DisposeSession",cond:"shallDisposeSession"},{target:"CreateSession",cond:"shallCreateSession"},{target:"UpdateSession",cond:"shallUpdateSession"}]},DisposeSession:{entry:[p.log("Entering DisposeSession","SessionManagement:"),C(2)],always:{actions:["disposeOldSession"],target:"ProcessChanges"}},CreateSession:{entry:[p.log("Entering CreateSession","SessionManagement:"),C(0)],invoke:{id:"getNewSession",src:"createSession",onDone:{actions:["setSessionCreationResult","setHasEverSuccessfullyCreatedSession"],target:"ProcessChanges"},onError:{actions:"setSessionCreationError",target:"SessionCreationFailed"}}},SessionCreationFailed:{entry:[p.log("Entering SessionCreationFailed","SessionManagement:"),C(2)],always:{target:"ProcessChanges",cond:"shallImmediatelyProcessChangesAfterSessionCreationError"},exit:[p.log("Exiting SessionCreationFailed","SessionManagement:"),"clearSessionCreationError"],on:{RetrySessionCreation:{target:"ProcessChanges",actions:p.log("Retrying session creation","SessionManagement:")}}},UpdateSession:{entry:[p.log("Entering UpdateSession","SessionManagement:"),C(1)],invoke:{id:"updateExistingSession",src:"updateSession",onDone:{target:"ProcessChanges"},onError:{actions:"setSessionUpdateError",target:"SessionUpdateFailed"}}},SessionUpdateFailed:{entry:[p.log("Entering SessionUpdateFailed","SessionManagement:"),C(2)],always:{target:"ProcessChanges",cond:"shallImmediatelyProcessChangesAfterSessionUpdateError"},exit:[p.log("Exiting SessionUpdateFailed","SessionManagement:"),"clearSessionUpdateError"],on:{RetrySessionUpdate:{target:"ProcessChanges",actions:p.log("Retrying session update","SessionManagement:")}}}}},{actions:{saveDesiredClient:l.assign({desiredClient:(e,n)=>n.client}),saveDesiredSessionContext:l.assign({desiredSessionContext:(e,n)=>n.sessionContext}),disposeOldSession:l.assign((e,n)=>(e.session&&e.session.close().then(s.constVoid).catch(t=>{}),{session:null,actualClient:null})),setSessionCreationResult:l.assign((e,n)=>({session:n.data.session,actualClient:n.data.client})),setSessionCreationError:l.assign((e,n)=>({sessionCreationError:n.data})),clearSessionCreationError:l.assign({sessionCreationError:()=>null}),setSessionUpdateError:l.assign((e,n)=>({sessionUpdateError:n.data})),clearSessionUpdateError:l.assign({sessionUpdateError:()=>null}),setHasEverSuccessfullyCreatedSession:l.assign({hasEverSuccessfullyCreatedSession:()=>!0})},services:{createSession:e=>e.desiredClient.createSession(e.desiredSessionContext).then(n=>({session:n,client:e.desiredClient})).catch(n=>Promise.reject({type:n.type,client:e.desiredClient,sessionContext:e.desiredSessionContext})),updateSession:e=>e.session.setSessionContext(e.desiredSessionContext).catch(n=>Promise.reject({type:n.type,sessionContext:e.desiredSessionContext}))},guards:{shallDisposeSession:e=>e.session!=null&&(e.desiredSessionContext==null||e.desiredClient==null||!h.equals(e.actualClient,e.desiredClient)),shallCreateSession:e=>e.session==null&&e.desiredClient!=null&&e.desiredSessionContext!=null,shallUpdateSession:e=>e.session!=null&&!F.equals(e.session.getSessionContext(),e.desiredSessionContext),shallImmediatelyProcessChangesAfterSessionCreationError:e=>!h.equals(e.desiredClient,e.sessionCreationError.client)||!q.equals(e.desiredSessionContext,e.sessionCreationError.sessionContext),shallImmediatelyProcessChangesAfterSessionUpdateError:e=>!h.equals(e.desiredClient,e.actualClient)||!q.equals(e.desiredSessionContext,e.sessionUpdateError.sessionContext)}});function C(e){const n=e===0,t=e===1;return p.pure((i,r)=>{const a={isInitializing:(!i.hasEverSuccessfullyCreatedSession||n)&&i.sessionCreationError==null,errorType:i.sessionCreationError&&i.sessionCreationError.type},g={isUpdating:t&&i.sessionUpdateError==null,errorType:i.sessionUpdateError&&i.sessionUpdateError.type};return l.sendParent({type:"SessionManagementStateChanged",sessionInitialization:a,sessionUpdating:g,session:i.session})})}const Ce=e=>n=>(n({type:"ConfigurationChanged",session:e,configuration:e.getConfiguration()}),e.setOnConfigurationChangedHandler(t=>{n({type:"ConfigurationChanged",session:e,configuration:t})}),()=>{e.setOnConfigurationChangedHandler(null)}),me=()=>l.createMachine({predictableActionArguments:!0,preserveActionOrder:!0,schema:{context:{},events:{}},context:{session:null},on:{ConfigurationChanged:{actions:[l.sendParent((e,n)=>n)]}},initial:"ProcessChanges",states:{ProcessChanges:{entry:[p.log("Entering ProcessChanges","ConfigurationSubscriptionManagement:")],on:{ChangeSession:{actions:["saveSession"]}},always:[{target:"Subscribe",cond:(e,n)=>e.session!=null}]},Subscribe:{entry:[p.log("Entering Subscribe","ConfigurationSubscriptionManagement:")],on:{ChangeSession:{target:"ProcessChanges",cond:(e,n)=>n.session==null||e.session!==n.session,actions:["saveSession"]}},invoke:{id:"configurationSubscriptionActor",src:(e,n)=>Ce(e.session)}}}},{actions:{saveSession:l.assign((e,n)=>({session:n.session}))}}),Se=()=>{let e,n;return{promise:new Promise((i,r)=>{e=i,n=r}),resolve:e,reject:n}},T=()=>{const e=Se();return{capsule:{promise:e.promise},resolve:e.resolve,reject:e.reject}};var ye=function(e,n,t){var i=u.useRef(),r=u.useRef(0);return i.current==null&&(i.current=e),n.equals(e,i.current)||(t&&t.debug&&process.env.NODE_ENV!=="production"&&console.info("Stable hook update triggered:",{prev:i.current,value:e}),i.current=e,r.current+=1),[r.current]},U=function(e,n,t,i){return u.useEffect(e,ye(n,t,i))};const Ee=()=>l.createMachine({predictableActionArguments:!0,preserveActionOrder:!0,schema:{context:{},events:{}},context:{sessionManagementActor:null,configurationSubscriptionManagementActor:null,sessionInitialization:null,sessionUpdating:null,session:null,configuration:null,isReadyPromise:T()},entry:[l.assign({sessionManagementActor:()=>l.spawn(fe()),configurationSubscriptionManagementActor:()=>l.spawn(me())})],exit:[p.stop(e=>e.sessionManagementActor),p.stop(e=>e.configurationSubscriptionManagementActor)],on:{ChangeConfigurationClient:{actions:[l.forwardTo(e=>e.sessionManagementActor)]},ChangeSessionContext:{actions:[l.forwardTo(e=>e.sessionManagementActor)]},RetrySessionCreation:{actions:[l.forwardTo(e=>e.sessionManagementActor)]},RetrySessionUpdate:{actions:[l.forwardTo(e=>e.sessionManagementActor)]},SessionManagementStateChanged:{actions:[l.assign((e,n)=>({session:n.session,sessionInitialization:n.sessionInitialization,sessionUpdating:n.sessionUpdating})),l.send(e=>({type:"ChangeSession",session:e.session}),{to:e=>e.configurationSubscriptionManagementActor}),"calculateReadyState"]},ConfigurationChanged:{actions:[l.assign((e,n)=>({configuration:{session:n.session,configuration:n.configuration}})),"calculateReadyState"]}},initial:"Idle",states:{Idle:{}}},{actions:{calculateReadyState:l.assign((e,n)=>{var r;const t=!((r=e.sessionInitialization)!=null&&r.isInitializing)&&e.session!=null&&e.configuration!=null&&e.configuration.session===e.session;return e.isReadyPromise&&t&&(e.isReadyPromise.resolve(),e.isReadyPromise.capsule.promise=null),{isReadyPromise:(()=>t?null:e.isReadyPromise!=null?e.isReadyPromise:T())()}})}});function he(e){var g,d;const[n,t]=H.useMachine(Ee,{logger:(...c)=>console.log("ConfigurationManagement:",...c)});U(()=>{t({type:"ChangeConfigurationClient",client:e.configuratorClient}),e.configuratorClient||console.warn("The configurator client is null or undefined. This will dispose the session that may exist. If this was not intended, make sure you pass a valid client.")},[e.configuratorClient],s.Eq.tuple(h)),U(()=>{const c=s.pipe(s.O.fromNullable(e.sessionContext),s.O.chainFirst(f=>s.O.fromNullable(f.configurationModelSource)),s.O.toNullable);t({type:"ChangeSessionContext",sessionContext:c}),c||console.warn("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.")},[e.sessionContext],s.Eq.tuple(q));const i=u.useMemo(()=>{var c,f,P,v;return{isInitializing:((f=(c=n.context.isReadyPromise)==null?void 0:c.capsule)==null?void 0:f.promise)!=null,isInitializingPromise:(P=n.context.isReadyPromise)==null?void 0:P.capsule,error:((v=n.context.sessionInitialization)==null?void 0:v.errorType)&&{type:n.context.sessionInitialization.errorType,retry:()=>t({type:"RetrySessionCreation"})}}},[n.context.sessionInitialization,n.context.isReadyPromise]),r=u.useMemo(()=>{var c,f;return{isUpdating:(c=n.context.sessionUpdating)==null?void 0:c.isUpdating,error:((f=n.context.sessionUpdating)==null?void 0:f.errorType)&&{type:n.context.sessionUpdating.errorType,retry:()=>t({type:"RetrySessionUpdate"})}}},[n.context.sessionUpdating]),a=((g=n.context.configuration)==null?void 0:g.session)===n.context.session?(d=n.context.configuration)==null?void 0:d.configuration:null;return{configurationInitialization:i,configurationUpdating:r,session:n.context.session,configuration:a}}function Ae(e){const{configuratorClient:n,...t}=e,{configurationInitialization:i,configurationUpdating:r,session:a,configuration:g}=he({configuratorClient:n,sessionContext:t});return m.jsx(O.Provider,{value:i,children:m.jsx(N.Provider,{value:r,children:m.jsx(D.Provider,{value:a,children:m.jsx(k.Provider,{value:g,children:e.children})})})})}function B(){return u.useContext(O)}function xe(){return u.useContext(N)}function Re(e){const{children:n}=e,{isInitializingPromise:t}=B();if(t!=null&&t.promise)throw t.promise;return m.jsx(m.Fragment,{children:n})}function be(){const e=M(),n=S();return w(e),y(n),u.useMemo(()=>({configuration:n,restoreConfiguration:t=>e.restoreConfiguration(t)}),[n,e])}exports.Configuration=Ae;exports.ConfigurationSuspender=Re;exports.useAttributes=Z;exports.useBooleanAttribute=se;exports.useChoiceAttribute=ee;exports.useComponentAttribute=te;exports.useConfiguration=be;exports.useConfigurationInitialization=B;exports.useConfigurationUpdating=xe;exports.useDecision=E;exports.useExplain=_;exports.useNumericAttribute=ne;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { AllowedInExplain } from '@viamedici-spc/configurator-ts';
|
|
1
2
|
import { Attribute } from '@viamedici-spc/configurator-ts';
|
|
2
3
|
import { AttributeRelations } from '@viamedici-spc/configurator-ts';
|
|
3
4
|
import { BooleanAttribute } from '@viamedici-spc/configurator-ts';
|
|
@@ -8,13 +9,25 @@ import { ComponentAttribute } from '@viamedici-spc/configurator-ts';
|
|
|
8
9
|
import { ComponentDecisionState } from '@viamedici-spc/configurator-ts';
|
|
9
10
|
import { Configuration as Configuration_2 } from '@viamedici-spc/configurator-ts';
|
|
10
11
|
import { ConfigurationModelSource } from '@viamedici-spc/configurator-ts';
|
|
12
|
+
import { ConstraintsExplainAnswer } from '@viamedici-spc/configurator-ts';
|
|
13
|
+
import { DecisionsExplainAnswer } from '@viamedici-spc/configurator-ts';
|
|
14
|
+
import { ExplainQuestion } from '@viamedici-spc/configurator-ts';
|
|
15
|
+
import { ExplainQuestionParam as ExplainQuestionParam_2 } from '@viamedici-spc/configurator-ts';
|
|
16
|
+
import { ExplainSolution } from '@viamedici-spc/configurator-ts';
|
|
11
17
|
import { ExplicitDecision } from '@viamedici-spc/configurator-ts';
|
|
12
18
|
import { FailureType } from '@viamedici-spc/configurator-ts';
|
|
19
|
+
import { FullExplainAnswer } from '@viamedici-spc/configurator-ts';
|
|
13
20
|
import { GlobalAttributeId } from '@viamedici-spc/configurator-ts';
|
|
14
21
|
import { IConfiguratorClient } from '@viamedici-spc/configurator-ts';
|
|
15
22
|
import { NumericAttribute } from '@viamedici-spc/configurator-ts';
|
|
16
23
|
import { PropsWithChildren } from 'react';
|
|
17
24
|
import { SetManyMode } from '@viamedici-spc/configurator-ts';
|
|
25
|
+
import { WhyIsAttributeNotSatisfied } from '@viamedici-spc/configurator-ts';
|
|
26
|
+
import { WhyIsBooleanStateNotPossible } from '@viamedici-spc/configurator-ts';
|
|
27
|
+
import { WhyIsChoiceValueStateNotPossible } from '@viamedici-spc/configurator-ts';
|
|
28
|
+
import { WhyIsComponentStateNotPossible } from '@viamedici-spc/configurator-ts';
|
|
29
|
+
import { WhyIsNumericStateNotPossible } from '@viamedici-spc/configurator-ts';
|
|
30
|
+
import { WhyIsStateNotPossible } from '@viamedici-spc/configurator-ts';
|
|
18
31
|
|
|
19
32
|
export declare function Configuration(props: PropsWithChildren<ConfigurationProps>): JSX.Element;
|
|
20
33
|
|
|
@@ -52,6 +65,7 @@ export declare type ConfigurationProps = {
|
|
|
52
65
|
configurationModelSource: ConfigurationModelSource;
|
|
53
66
|
attributeRelations?: AttributeRelations | null;
|
|
54
67
|
usageRuleParameters?: Record<string, string> | null;
|
|
68
|
+
allowedInExplain?: AllowedInExplain | null;
|
|
55
69
|
};
|
|
56
70
|
|
|
57
71
|
/**
|
|
@@ -71,6 +85,17 @@ declare type EncapsulatedPromise = {
|
|
|
71
85
|
promise: Promise<void> | null;
|
|
72
86
|
};
|
|
73
87
|
|
|
88
|
+
declare type ExplainQuestionParam<T extends WhyIsStateNotPossible> = SimplifiedExplainQuestion<WhyIsAttributeNotSatisfied> | SimplifiedExplainQuestion<T>;
|
|
89
|
+
|
|
90
|
+
declare type SimplifiedExplainQuestion<T extends ExplainQuestion> = Omit<T, "attributeId" | "subject">;
|
|
91
|
+
|
|
92
|
+
declare type UseAttributeExplainResult<T extends WhyIsStateNotPossible> = {
|
|
93
|
+
explain(question: ExplainQuestionParam<T>, answerType: "decisions"): Promise<DecisionsExplainAnswer>;
|
|
94
|
+
explain(question: ExplainQuestionParam<T>, answerType: "constraints"): Promise<ConstraintsExplainAnswer>;
|
|
95
|
+
explain(question: ExplainQuestionParam<T>, answerType: "full"): Promise<FullExplainAnswer>;
|
|
96
|
+
applySolution(solution: ExplainSolution): Promise<void>;
|
|
97
|
+
};
|
|
98
|
+
|
|
74
99
|
/**
|
|
75
100
|
* Retrieves the requested attributes. Will return all existing attributes if requested attributes is null or undefined.
|
|
76
101
|
* @param attributes The attributes to return or null/undefined if all attributes shall be returned.
|
|
@@ -88,7 +113,7 @@ export declare function useAttributes(attributes?: GlobalAttributeId[], ignoreMi
|
|
|
88
113
|
*/
|
|
89
114
|
export declare function useBooleanAttribute(attributeId: GlobalAttributeId): UseBooleanAttributeResult | undefined;
|
|
90
115
|
|
|
91
|
-
export declare type UseBooleanAttributeResult = {
|
|
116
|
+
export declare type UseBooleanAttributeResult = UseAttributeExplainResult<WhyIsBooleanStateNotPossible> & {
|
|
92
117
|
attribute: BooleanAttribute;
|
|
93
118
|
makeDecision: (state: boolean | null | undefined) => Promise<void>;
|
|
94
119
|
};
|
|
@@ -101,7 +126,7 @@ export declare type UseBooleanAttributeResult = {
|
|
|
101
126
|
*/
|
|
102
127
|
export declare function useChoiceAttribute(attributeId: GlobalAttributeId): UseChoiceAttributeResult | undefined;
|
|
103
128
|
|
|
104
|
-
export declare type UseChoiceAttributeResult = {
|
|
129
|
+
export declare type UseChoiceAttributeResult = UseAttributeExplainResult<WhyIsChoiceValueStateNotPossible> & {
|
|
105
130
|
attribute: ChoiceAttribute;
|
|
106
131
|
makeDecision: (choiceValueId: ChoiceValueId, state: ChoiceValueDecisionState | null | undefined) => Promise<void>;
|
|
107
132
|
clearDecisions: () => Promise<void>;
|
|
@@ -109,7 +134,7 @@ export declare type UseChoiceAttributeResult = {
|
|
|
109
134
|
|
|
110
135
|
export declare function useComponentAttribute(attributeId: GlobalAttributeId): UseComponentAttributeResult | undefined;
|
|
111
136
|
|
|
112
|
-
export declare type UseComponentAttributeResult = {
|
|
137
|
+
export declare type UseComponentAttributeResult = UseAttributeExplainResult<WhyIsComponentStateNotPossible> & {
|
|
113
138
|
attribute: ComponentAttribute;
|
|
114
139
|
makeDecision: (state: ComponentDecisionState | null | undefined) => Promise<void>;
|
|
115
140
|
clearSubtree: () => Promise<void>;
|
|
@@ -155,7 +180,12 @@ export declare type UseDecisionResult = {
|
|
|
155
180
|
*/
|
|
156
181
|
export declare function useExplain(): UseExplainResult;
|
|
157
182
|
|
|
158
|
-
export declare type UseExplainResult = {
|
|
183
|
+
export declare type UseExplainResult = {
|
|
184
|
+
explain(question: ExplainQuestionParam_2, answerType: "decisions"): Promise<DecisionsExplainAnswer>;
|
|
185
|
+
explain(question: ExplainQuestionParam_2, answerType: "constraints"): Promise<ConstraintsExplainAnswer>;
|
|
186
|
+
explain(question: ExplainQuestionParam_2, answerType: "full"): Promise<FullExplainAnswer>;
|
|
187
|
+
applySolution(solution: ExplainSolution): Promise<void>;
|
|
188
|
+
};
|
|
159
189
|
|
|
160
190
|
/**
|
|
161
191
|
* Gets the requested numeric attribute with the command to make decisions.
|
|
@@ -165,7 +195,7 @@ export declare type UseExplainResult = {};
|
|
|
165
195
|
*/
|
|
166
196
|
export declare function useNumericAttribute(attributeId: GlobalAttributeId): UseNumericAttributeResult | undefined;
|
|
167
197
|
|
|
168
|
-
export declare type UseNumericAttributeResult = {
|
|
198
|
+
export declare type UseNumericAttributeResult = UseAttributeExplainResult<WhyIsNumericStateNotPossible> & {
|
|
169
199
|
attribute: NumericAttribute;
|
|
170
200
|
makeDecision: (state: number | null | undefined) => Promise<void>;
|
|
171
201
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,222 +1,254 @@
|
|
|
1
|
-
import { AttributeType as
|
|
2
|
-
import { pipe as
|
|
3
|
-
import { createContext as
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import { deepEqual as
|
|
9
|
-
import { useMachine as
|
|
10
|
-
const
|
|
11
|
-
function
|
|
1
|
+
import { AttributeType as S, ConfigurationInterpreter as E, DecisionKind as ie, ExplainQuestionSubject as A, ExplainQuestionType as te, globalAttributeIdEquals as oe, globalConstraintIdEquals as re, AllowedRulesInExplainType as h } from "@viamedici-spc/configurator-ts";
|
|
2
|
+
import { pipe as m, RA as l, O as a, some as w, none as M, flow as ae, identity as le, Eq as u, RR as ce, Str as U, constVoid as ue } from "@viamedici-spc/fp-ts-extensions";
|
|
3
|
+
import { createContext as D, useContext as I, useMemo as g, useRef as V, useEffect as de } from "react";
|
|
4
|
+
import { match as v } from "ts-pattern";
|
|
5
|
+
import { jsx as R, Fragment as ge } from "react/jsx-runtime";
|
|
6
|
+
import { createMachine as O, assign as p, sendParent as W, spawn as Q, forwardTo as P, send as pe } from "xstate";
|
|
7
|
+
import { log as C, pure as fe, stop as K } from "xstate/lib/actions";
|
|
8
|
+
import { deepEqual as Ce } from "fast-equals";
|
|
9
|
+
import { useMachine as me } from "@xstate/react";
|
|
10
|
+
const X = D(null), Y = D(null), Z = D(null), $ = D(null), F = () => I(X), x = () => I($), ee = "The configuration is not initialized. Consider using the ConfigurationSuspender or unload components manually that make use of any unsafe hook while the configuration is initializing. Check the hooks documentation to see if it is safe to use while the configuration is initializing.";
|
|
11
|
+
function j(e) {
|
|
12
12
|
if (!e)
|
|
13
|
-
throw new Error(
|
|
13
|
+
throw new Error(ee);
|
|
14
14
|
}
|
|
15
|
-
function
|
|
15
|
+
function b(e) {
|
|
16
16
|
if (!e)
|
|
17
|
-
throw new Error(
|
|
17
|
+
throw new Error(ee);
|
|
18
18
|
}
|
|
19
|
-
function
|
|
20
|
-
const e =
|
|
21
|
-
return
|
|
19
|
+
function N() {
|
|
20
|
+
const e = F();
|
|
21
|
+
return j(e), g(() => ({
|
|
22
22
|
makeDecision: (n) => e.makeDecision(n),
|
|
23
23
|
setManyDecision: (n, s) => e.setMany(n, s)
|
|
24
24
|
}), [e]);
|
|
25
25
|
}
|
|
26
26
|
globalThis && globalThis.__spreadArray;
|
|
27
|
-
var
|
|
27
|
+
var Se = function(e) {
|
|
28
28
|
return e._tag === "Some";
|
|
29
|
-
},
|
|
29
|
+
}, k = function(e) {
|
|
30
30
|
return function(n) {
|
|
31
|
-
return
|
|
31
|
+
return Se(e(n));
|
|
32
32
|
};
|
|
33
33
|
};
|
|
34
|
-
const
|
|
35
|
-
function
|
|
36
|
-
return e.decision != null && e.decision.kind ===
|
|
34
|
+
const he = k((e) => e.type === S.Choice ? w(e) : M), ye = k((e) => e.type === S.Numeric ? w(e) : M), Ee = k((e) => e.type === S.Boolean ? w(e) : M), xe = k((e) => e.type === S.Component ? w(e) : M);
|
|
35
|
+
function T(e) {
|
|
36
|
+
return e.decision != null && e.decision.kind === ie.Explicit;
|
|
37
37
|
}
|
|
38
|
-
function
|
|
39
|
-
return
|
|
38
|
+
function ne(e) {
|
|
39
|
+
return m(
|
|
40
40
|
e.values,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
type:
|
|
41
|
+
l.filter(T),
|
|
42
|
+
l.map((n) => ({
|
|
43
|
+
type: S.Choice,
|
|
44
44
|
attributeId: e.id,
|
|
45
45
|
choiceValueId: n.id,
|
|
46
46
|
state: null
|
|
47
47
|
}))
|
|
48
48
|
);
|
|
49
49
|
}
|
|
50
|
-
function
|
|
51
|
-
return
|
|
50
|
+
function be(e) {
|
|
51
|
+
return m(
|
|
52
52
|
e,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
type:
|
|
53
|
+
a.fromPredicate(T),
|
|
54
|
+
a.map(() => ({
|
|
55
|
+
type: S.Numeric,
|
|
56
56
|
attributeId: e.id,
|
|
57
57
|
state: null
|
|
58
58
|
}))
|
|
59
59
|
);
|
|
60
60
|
}
|
|
61
|
-
function
|
|
62
|
-
return
|
|
61
|
+
function Re(e) {
|
|
62
|
+
return m(
|
|
63
63
|
e,
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
type:
|
|
64
|
+
a.fromPredicate(T),
|
|
65
|
+
a.map(() => ({
|
|
66
|
+
type: S.Boolean,
|
|
67
67
|
attributeId: e.id,
|
|
68
68
|
state: null
|
|
69
69
|
}))
|
|
70
70
|
);
|
|
71
71
|
}
|
|
72
|
-
function
|
|
73
|
-
return
|
|
72
|
+
function Ae(e) {
|
|
73
|
+
return m(
|
|
74
74
|
e,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
type:
|
|
75
|
+
a.fromPredicate(T),
|
|
76
|
+
a.map(() => ({
|
|
77
|
+
type: S.Component,
|
|
78
78
|
attributeId: e.id,
|
|
79
79
|
state: null
|
|
80
80
|
}))
|
|
81
81
|
);
|
|
82
82
|
}
|
|
83
|
-
function
|
|
84
|
-
return
|
|
85
|
-
|
|
83
|
+
function Pe(e, n) {
|
|
84
|
+
return m(
|
|
85
|
+
E.filterAttributesOfComponent(n, e, !0),
|
|
86
86
|
(s) => [
|
|
87
|
-
|
|
87
|
+
m(
|
|
88
88
|
s,
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
l.filter(he),
|
|
90
|
+
l.chain(ne)
|
|
91
91
|
),
|
|
92
|
-
|
|
92
|
+
m(
|
|
93
93
|
s,
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
94
|
+
l.filter(ye),
|
|
95
|
+
l.map(be),
|
|
96
|
+
l.compact
|
|
97
97
|
),
|
|
98
|
-
|
|
98
|
+
m(
|
|
99
99
|
s,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
100
|
+
l.filter(Ee),
|
|
101
|
+
l.map(Re),
|
|
102
|
+
l.compact
|
|
103
103
|
),
|
|
104
|
-
|
|
104
|
+
m(
|
|
105
105
|
s,
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
106
|
+
l.filter(xe),
|
|
107
|
+
l.map(Ae),
|
|
108
|
+
l.compact
|
|
109
109
|
)
|
|
110
110
|
],
|
|
111
|
-
|
|
111
|
+
l.flatten
|
|
112
112
|
);
|
|
113
113
|
}
|
|
114
|
-
function
|
|
115
|
-
const
|
|
116
|
-
return
|
|
117
|
-
() =>
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
114
|
+
function qe() {
|
|
115
|
+
const e = F();
|
|
116
|
+
return j(e), g(() => ({
|
|
117
|
+
explain: (n, s) => v(s).with("decisions", (i) => e.explain(n, i)).with("constraints", (i) => e.explain(n, i)).with("full", (i) => e.explain(n, i)).exhaustive(),
|
|
118
|
+
applySolution: (n) => e.applySolution(n)
|
|
119
|
+
}), [e]);
|
|
120
|
+
}
|
|
121
|
+
function en(e, n = !1) {
|
|
122
|
+
const s = x();
|
|
123
|
+
return b(s), g(
|
|
124
|
+
() => m(
|
|
125
|
+
a.fromNullable(e),
|
|
126
|
+
a.map(ae(
|
|
127
|
+
l.map((i) => E.getAttribute(s, i)),
|
|
128
|
+
n ? l.filterMap(a.fromNullable) : le
|
|
122
129
|
)),
|
|
123
|
-
|
|
130
|
+
a.getOrElse(() => s.attributes)
|
|
124
131
|
),
|
|
125
132
|
[e, s, n]
|
|
126
133
|
);
|
|
127
134
|
}
|
|
128
|
-
function
|
|
129
|
-
const n =
|
|
130
|
-
|
|
131
|
-
const
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
makeDecision: (m, l) => s({
|
|
135
|
-
type: C.Choice,
|
|
135
|
+
function nn(e) {
|
|
136
|
+
const n = x(), { makeDecision: s, setManyDecision: i } = N(), t = z(e, A.choiceValue);
|
|
137
|
+
b(n);
|
|
138
|
+
const o = E.getChoiceAttribute(n, e), c = g(() => ({
|
|
139
|
+
makeDecision: (r, f) => s({
|
|
140
|
+
type: S.Choice,
|
|
136
141
|
attributeId: e,
|
|
137
|
-
choiceValueId:
|
|
138
|
-
state:
|
|
142
|
+
choiceValueId: r,
|
|
143
|
+
state: f
|
|
139
144
|
}),
|
|
140
|
-
clearDecisions:
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
145
|
+
clearDecisions: m(
|
|
146
|
+
o,
|
|
147
|
+
a.fromNullable,
|
|
148
|
+
a.map(ne),
|
|
144
149
|
// Only setMany if there are decisions to clear.
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
)
|
|
149
|
-
|
|
150
|
-
}), [e,
|
|
151
|
-
...
|
|
152
|
-
attribute:
|
|
153
|
-
}), [
|
|
154
|
-
if (
|
|
150
|
+
a.filter(l.isNonEmpty),
|
|
151
|
+
a.map((r) => () => i(r, { type: "Default" })),
|
|
152
|
+
a.getOrElse(() => () => Promise.resolve())
|
|
153
|
+
),
|
|
154
|
+
...t
|
|
155
|
+
}), [e, o, s, i, t]), d = g(() => ({
|
|
156
|
+
...c,
|
|
157
|
+
attribute: o
|
|
158
|
+
}), [o, c]);
|
|
159
|
+
if (o)
|
|
155
160
|
return d;
|
|
156
161
|
}
|
|
157
|
-
function
|
|
158
|
-
const n =
|
|
159
|
-
|
|
160
|
-
const
|
|
162
|
+
function sn(e) {
|
|
163
|
+
const n = x(), { makeDecision: s } = N(), i = z(e, A.numeric);
|
|
164
|
+
b(n);
|
|
165
|
+
const t = E.getNumericAttribute(n, e), o = g(() => ({
|
|
161
166
|
makeDecision: (d) => s({
|
|
162
|
-
type:
|
|
167
|
+
type: S.Numeric,
|
|
163
168
|
attributeId: e,
|
|
164
169
|
state: d
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
170
|
+
}),
|
|
171
|
+
...i
|
|
172
|
+
}), [e, s, i]), c = g(() => ({
|
|
173
|
+
...o,
|
|
174
|
+
attribute: t
|
|
175
|
+
}), [t, o]);
|
|
176
|
+
if (t)
|
|
177
|
+
return c;
|
|
172
178
|
}
|
|
173
|
-
function
|
|
174
|
-
const n =
|
|
175
|
-
|
|
176
|
-
const
|
|
179
|
+
function tn(e) {
|
|
180
|
+
const n = x(), { makeDecision: s } = N(), i = z(e, A.boolean);
|
|
181
|
+
b(n);
|
|
182
|
+
const t = E.getBooleanAttribute(n, e), o = g(() => ({
|
|
177
183
|
makeDecision: (d) => s({
|
|
178
|
-
type:
|
|
184
|
+
type: S.Boolean,
|
|
179
185
|
attributeId: e,
|
|
180
186
|
state: d
|
|
181
|
-
})
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
187
|
+
}),
|
|
188
|
+
...i
|
|
189
|
+
}), [e, s, i]), c = g(() => ({
|
|
190
|
+
...o,
|
|
191
|
+
attribute: t
|
|
192
|
+
}), [t, o]);
|
|
193
|
+
if (t)
|
|
194
|
+
return c;
|
|
188
195
|
}
|
|
189
|
-
function
|
|
190
|
-
const n =
|
|
191
|
-
|
|
192
|
-
const
|
|
193
|
-
makeDecision: (
|
|
194
|
-
type:
|
|
196
|
+
function on(e) {
|
|
197
|
+
const n = x(), { makeDecision: s, setManyDecision: i } = N(), t = z(e, A.component);
|
|
198
|
+
b(n);
|
|
199
|
+
const o = n.attributes, c = E.getComponentAttribute(n, e), d = g(() => ({
|
|
200
|
+
makeDecision: (f) => s({
|
|
201
|
+
type: S.Component,
|
|
195
202
|
attributeId: e,
|
|
196
|
-
state:
|
|
203
|
+
state: f
|
|
197
204
|
}),
|
|
198
|
-
clearSubtree:
|
|
199
|
-
|
|
205
|
+
clearSubtree: m(
|
|
206
|
+
Pe(e, o),
|
|
200
207
|
// Only setMany if there are decisions to clear.
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
)
|
|
205
|
-
|
|
208
|
+
a.fromPredicate(l.isNonEmpty),
|
|
209
|
+
a.map((f) => () => i(f, { type: "Default" })),
|
|
210
|
+
a.getOrElse(() => () => Promise.resolve())
|
|
211
|
+
),
|
|
212
|
+
...t
|
|
213
|
+
}), [e, s, o, i, t]), r = g(() => ({
|
|
206
214
|
...d,
|
|
207
|
-
attribute:
|
|
208
|
-
}), [
|
|
209
|
-
if (
|
|
210
|
-
return
|
|
215
|
+
attribute: c
|
|
216
|
+
}), [c, d]);
|
|
217
|
+
if (c)
|
|
218
|
+
return r;
|
|
211
219
|
}
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
+
function z(e, n) {
|
|
221
|
+
const { explain: s, applySolution: i } = qe();
|
|
222
|
+
return g(() => ({
|
|
223
|
+
explain: (t, o) => {
|
|
224
|
+
const c = v(t.question).with(te.whyIsNotSatisfied, () => A.attribute).otherwise(() => n), d = {
|
|
225
|
+
...t,
|
|
226
|
+
subject: c,
|
|
227
|
+
attributeId: e
|
|
228
|
+
};
|
|
229
|
+
return v(o).with("decisions", (r) => s(d, r)).with("constraints", (r) => s(d, r)).with("full", (r) => s(d, r)).exhaustive();
|
|
230
|
+
},
|
|
231
|
+
applySolution: i
|
|
232
|
+
}), [e, n, s, i]);
|
|
233
|
+
}
|
|
234
|
+
const G = u.fromEquals(oe), ve = u.fromEquals(re), we = u.fromEquals((e, n) => ce.getEq(U.Eq).equals(e ?? {}, n ?? {})), Me = u.struct({
|
|
235
|
+
attributeId: G,
|
|
236
|
+
decisions: l.getEq(G)
|
|
237
|
+
}), Ue = u.fromEquals((e, n) => l.getEq(Me).equals(e ?? [], n ?? [])), De = u.struct({
|
|
238
|
+
type: U.Eq
|
|
239
|
+
}), Ie = u.struct({
|
|
240
|
+
type: U.Eq
|
|
241
|
+
}), Ne = u.struct({
|
|
242
|
+
type: U.Eq,
|
|
243
|
+
rules: l.getEq(ve)
|
|
244
|
+
}), ke = u.fromEquals((e, n) => v({ x: e, y: n }).returnType().with({ x: { type: h.all }, y: { type: h.all } }, ({ x: s, y: i }) => De.equals(s, i)).with({ x: { type: h.none }, y: { type: h.none } }, ({ x: s, y: i }) => Ie.equals(s, i)).with({ x: { type: h.specific }, y: { type: h.specific } }, ({ x: s, y: i }) => Ne.equals(s, i)).otherwise(() => !1)), Te = u.struct({
|
|
245
|
+
rules: u.eqNullable(ke)
|
|
246
|
+
}), se = u.struct({
|
|
247
|
+
configurationModelSource: u.fromEquals((e, n) => Ce(e, n)),
|
|
248
|
+
attributeRelations: Ue,
|
|
249
|
+
usageRuleParameters: we,
|
|
250
|
+
allowedInExplain: u.eqNullable(Te)
|
|
251
|
+
}), _ = u.eqNullable(se), ze = u.eqStrict, q = u.eqNullable(ze), _e = () => O({
|
|
220
252
|
predictableActionArguments: !0,
|
|
221
253
|
preserveActionOrder: !0,
|
|
222
254
|
schema: {
|
|
@@ -242,14 +274,14 @@ const Se = p.fromEquals((e, n) => ee.getEq(ne.Eq).equals(e ?? {}, n ?? {})), he
|
|
|
242
274
|
}
|
|
243
275
|
},
|
|
244
276
|
exit: [
|
|
245
|
-
|
|
277
|
+
C("Shutting down", "SessionManagement:"),
|
|
246
278
|
"disposeOldSession"
|
|
247
279
|
],
|
|
248
280
|
states: {
|
|
249
281
|
ProcessChanges: {
|
|
250
282
|
entry: [
|
|
251
|
-
|
|
252
|
-
|
|
283
|
+
C("Entering ProcessChanges", "SessionManagement:"),
|
|
284
|
+
y(
|
|
253
285
|
2
|
|
254
286
|
/* Other */
|
|
255
287
|
)
|
|
@@ -262,8 +294,8 @@ const Se = p.fromEquals((e, n) => ee.getEq(ne.Eq).equals(e ?? {}, n ?? {})), he
|
|
|
262
294
|
},
|
|
263
295
|
DisposeSession: {
|
|
264
296
|
entry: [
|
|
265
|
-
|
|
266
|
-
|
|
297
|
+
C("Entering DisposeSession", "SessionManagement:"),
|
|
298
|
+
y(
|
|
267
299
|
2
|
|
268
300
|
/* Other */
|
|
269
301
|
)
|
|
@@ -275,8 +307,8 @@ const Se = p.fromEquals((e, n) => ee.getEq(ne.Eq).equals(e ?? {}, n ?? {})), he
|
|
|
275
307
|
},
|
|
276
308
|
CreateSession: {
|
|
277
309
|
entry: [
|
|
278
|
-
|
|
279
|
-
|
|
310
|
+
C("Entering CreateSession", "SessionManagement:"),
|
|
311
|
+
y(
|
|
280
312
|
0
|
|
281
313
|
/* CreateSession */
|
|
282
314
|
)
|
|
@@ -296,8 +328,8 @@ const Se = p.fromEquals((e, n) => ee.getEq(ne.Eq).equals(e ?? {}, n ?? {})), he
|
|
|
296
328
|
},
|
|
297
329
|
SessionCreationFailed: {
|
|
298
330
|
entry: [
|
|
299
|
-
|
|
300
|
-
|
|
331
|
+
C("Entering SessionCreationFailed", "SessionManagement:"),
|
|
332
|
+
y(
|
|
301
333
|
2
|
|
302
334
|
/* Other */
|
|
303
335
|
)
|
|
@@ -309,20 +341,20 @@ const Se = p.fromEquals((e, n) => ee.getEq(ne.Eq).equals(e ?? {}, n ?? {})), he
|
|
|
309
341
|
cond: "shallImmediatelyProcessChangesAfterSessionCreationError"
|
|
310
342
|
},
|
|
311
343
|
exit: [
|
|
312
|
-
|
|
344
|
+
C("Exiting SessionCreationFailed", "SessionManagement:"),
|
|
313
345
|
"clearSessionCreationError"
|
|
314
346
|
],
|
|
315
347
|
on: {
|
|
316
348
|
RetrySessionCreation: {
|
|
317
349
|
target: "ProcessChanges",
|
|
318
|
-
actions:
|
|
350
|
+
actions: C("Retrying session creation", "SessionManagement:")
|
|
319
351
|
}
|
|
320
352
|
}
|
|
321
353
|
},
|
|
322
354
|
UpdateSession: {
|
|
323
355
|
entry: [
|
|
324
|
-
|
|
325
|
-
|
|
356
|
+
C("Entering UpdateSession", "SessionManagement:"),
|
|
357
|
+
y(
|
|
326
358
|
1
|
|
327
359
|
/* UpdateSession */
|
|
328
360
|
)
|
|
@@ -341,8 +373,8 @@ const Se = p.fromEquals((e, n) => ee.getEq(ne.Eq).equals(e ?? {}, n ?? {})), he
|
|
|
341
373
|
},
|
|
342
374
|
SessionUpdateFailed: {
|
|
343
375
|
entry: [
|
|
344
|
-
|
|
345
|
-
|
|
376
|
+
C("Entering SessionUpdateFailed", "SessionManagement:"),
|
|
377
|
+
y(
|
|
346
378
|
2
|
|
347
379
|
/* Other */
|
|
348
380
|
)
|
|
@@ -354,43 +386,43 @@ const Se = p.fromEquals((e, n) => ee.getEq(ne.Eq).equals(e ?? {}, n ?? {})), he
|
|
|
354
386
|
cond: "shallImmediatelyProcessChangesAfterSessionUpdateError"
|
|
355
387
|
},
|
|
356
388
|
exit: [
|
|
357
|
-
|
|
389
|
+
C("Exiting SessionUpdateFailed", "SessionManagement:"),
|
|
358
390
|
"clearSessionUpdateError"
|
|
359
391
|
],
|
|
360
392
|
on: {
|
|
361
393
|
RetrySessionUpdate: {
|
|
362
394
|
target: "ProcessChanges",
|
|
363
|
-
actions:
|
|
395
|
+
actions: C("Retrying session update", "SessionManagement:")
|
|
364
396
|
}
|
|
365
397
|
}
|
|
366
398
|
}
|
|
367
399
|
}
|
|
368
400
|
}, {
|
|
369
401
|
actions: {
|
|
370
|
-
saveDesiredClient:
|
|
402
|
+
saveDesiredClient: p({
|
|
371
403
|
desiredClient: (e, n) => n.client
|
|
372
404
|
}),
|
|
373
|
-
saveDesiredSessionContext:
|
|
405
|
+
saveDesiredSessionContext: p({
|
|
374
406
|
desiredSessionContext: (e, n) => n.sessionContext
|
|
375
407
|
}),
|
|
376
|
-
disposeOldSession:
|
|
408
|
+
disposeOldSession: p((e, n) => (e.session && e.session.close().then(ue).catch((s) => {
|
|
377
409
|
}), {
|
|
378
410
|
session: null,
|
|
379
411
|
actualClient: null
|
|
380
412
|
})),
|
|
381
|
-
setSessionCreationResult:
|
|
413
|
+
setSessionCreationResult: p((e, n) => ({
|
|
382
414
|
session: n.data.session,
|
|
383
415
|
actualClient: n.data.client
|
|
384
416
|
})),
|
|
385
|
-
setSessionCreationError:
|
|
417
|
+
setSessionCreationError: p((e, n) => ({
|
|
386
418
|
sessionCreationError: n.data
|
|
387
419
|
})),
|
|
388
|
-
clearSessionCreationError:
|
|
389
|
-
setSessionUpdateError:
|
|
420
|
+
clearSessionCreationError: p({ sessionCreationError: () => null }),
|
|
421
|
+
setSessionUpdateError: p((e, n) => ({
|
|
390
422
|
sessionUpdateError: n.data
|
|
391
423
|
})),
|
|
392
|
-
clearSessionUpdateError:
|
|
393
|
-
setHasEverSuccessfullyCreatedSession:
|
|
424
|
+
clearSessionUpdateError: p({ sessionUpdateError: () => null }),
|
|
425
|
+
setHasEverSuccessfullyCreatedSession: p({
|
|
394
426
|
hasEverSuccessfullyCreatedSession: () => !0
|
|
395
427
|
})
|
|
396
428
|
},
|
|
@@ -409,38 +441,38 @@ const Se = p.fromEquals((e, n) => ee.getEq(ne.Eq).equals(e ?? {}, n ?? {})), he
|
|
|
409
441
|
}))
|
|
410
442
|
},
|
|
411
443
|
guards: {
|
|
412
|
-
shallDisposeSession: (e) => e.session != null && (e.desiredSessionContext == null || e.desiredClient == null || !
|
|
444
|
+
shallDisposeSession: (e) => e.session != null && (e.desiredSessionContext == null || e.desiredClient == null || !q.equals(e.actualClient, e.desiredClient)),
|
|
413
445
|
shallCreateSession: (e) => e.session == null && e.desiredClient != null && e.desiredSessionContext != null,
|
|
414
|
-
shallUpdateSession: (e) => e.session != null && !
|
|
446
|
+
shallUpdateSession: (e) => e.session != null && !se.equals(e.session.getSessionContext(), e.desiredSessionContext),
|
|
415
447
|
shallImmediatelyProcessChangesAfterSessionCreationError: (e) => (
|
|
416
448
|
// The desired client and the desired session context is not the same that resulted in the error.
|
|
417
|
-
!
|
|
449
|
+
!q.equals(e.desiredClient, e.sessionCreationError.client) || !_.equals(e.desiredSessionContext, e.sessionCreationError.sessionContext)
|
|
418
450
|
),
|
|
419
451
|
shallImmediatelyProcessChangesAfterSessionUpdateError: (e) => (
|
|
420
452
|
// The desired client was changed
|
|
421
|
-
!
|
|
453
|
+
!q.equals(e.desiredClient, e.actualClient) || !_.equals(e.desiredSessionContext, e.sessionUpdateError.sessionContext)
|
|
422
454
|
)
|
|
423
455
|
}
|
|
424
456
|
});
|
|
425
|
-
function
|
|
457
|
+
function y(e) {
|
|
426
458
|
const n = e === 0, s = e === 1;
|
|
427
|
-
return
|
|
428
|
-
const
|
|
459
|
+
return fe((i, t) => {
|
|
460
|
+
const o = {
|
|
429
461
|
isInitializing: (!i.hasEverSuccessfullyCreatedSession || n) && i.sessionCreationError == null,
|
|
430
462
|
errorType: i.sessionCreationError && i.sessionCreationError.type
|
|
431
|
-
},
|
|
463
|
+
}, c = {
|
|
432
464
|
isUpdating: s && i.sessionUpdateError == null,
|
|
433
465
|
errorType: i.sessionUpdateError && i.sessionUpdateError.type
|
|
434
466
|
};
|
|
435
|
-
return
|
|
467
|
+
return W({
|
|
436
468
|
type: "SessionManagementStateChanged",
|
|
437
|
-
sessionInitialization:
|
|
438
|
-
sessionUpdating:
|
|
469
|
+
sessionInitialization: o,
|
|
470
|
+
sessionUpdating: c,
|
|
439
471
|
session: i.session
|
|
440
472
|
});
|
|
441
473
|
});
|
|
442
474
|
}
|
|
443
|
-
const
|
|
475
|
+
const Oe = (e) => (n) => (n({
|
|
444
476
|
type: "ConfigurationChanged",
|
|
445
477
|
session: e,
|
|
446
478
|
configuration: e.getConfiguration()
|
|
@@ -452,7 +484,7 @@ const Ae = (e) => (n) => (n({
|
|
|
452
484
|
});
|
|
453
485
|
}), () => {
|
|
454
486
|
e.setOnConfigurationChangedHandler(null);
|
|
455
|
-
}),
|
|
487
|
+
}), Fe = () => O({
|
|
456
488
|
predictableActionArguments: !0,
|
|
457
489
|
preserveActionOrder: !0,
|
|
458
490
|
schema: {
|
|
@@ -466,7 +498,7 @@ const Ae = (e) => (n) => (n({
|
|
|
466
498
|
// Forward the configuration data to the parent.
|
|
467
499
|
ConfigurationChanged: {
|
|
468
500
|
actions: [
|
|
469
|
-
|
|
501
|
+
W((e, n) => n)
|
|
470
502
|
]
|
|
471
503
|
}
|
|
472
504
|
},
|
|
@@ -474,7 +506,7 @@ const Ae = (e) => (n) => (n({
|
|
|
474
506
|
states: {
|
|
475
507
|
ProcessChanges: {
|
|
476
508
|
entry: [
|
|
477
|
-
|
|
509
|
+
C("Entering ProcessChanges", "ConfigurationSubscriptionManagement:")
|
|
478
510
|
],
|
|
479
511
|
on: {
|
|
480
512
|
ChangeSession: {
|
|
@@ -492,7 +524,7 @@ const Ae = (e) => (n) => (n({
|
|
|
492
524
|
},
|
|
493
525
|
Subscribe: {
|
|
494
526
|
entry: [
|
|
495
|
-
|
|
527
|
+
C("Entering Subscribe", "ConfigurationSubscriptionManagement:")
|
|
496
528
|
],
|
|
497
529
|
on: {
|
|
498
530
|
ChangeSession: {
|
|
@@ -505,17 +537,17 @@ const Ae = (e) => (n) => (n({
|
|
|
505
537
|
},
|
|
506
538
|
invoke: {
|
|
507
539
|
id: "configurationSubscriptionActor",
|
|
508
|
-
src: (e, n) =>
|
|
540
|
+
src: (e, n) => Oe(e.session)
|
|
509
541
|
}
|
|
510
542
|
}
|
|
511
543
|
}
|
|
512
544
|
}, {
|
|
513
545
|
actions: {
|
|
514
|
-
saveSession:
|
|
546
|
+
saveSession: p((e, n) => ({
|
|
515
547
|
session: n.session
|
|
516
548
|
}))
|
|
517
549
|
}
|
|
518
|
-
}),
|
|
550
|
+
}), je = () => {
|
|
519
551
|
let e, n;
|
|
520
552
|
return {
|
|
521
553
|
promise: new Promise((i, t) => {
|
|
@@ -524,14 +556,21 @@ const Ae = (e) => (n) => (n({
|
|
|
524
556
|
resolve: e,
|
|
525
557
|
reject: n
|
|
526
558
|
};
|
|
527
|
-
},
|
|
528
|
-
const e =
|
|
559
|
+
}, J = () => {
|
|
560
|
+
const e = je();
|
|
529
561
|
return {
|
|
530
562
|
capsule: { promise: e.promise },
|
|
531
563
|
resolve: e.resolve,
|
|
532
564
|
reject: e.reject
|
|
533
565
|
};
|
|
534
|
-
}
|
|
566
|
+
};
|
|
567
|
+
var Be = function(e, n, s) {
|
|
568
|
+
var i = V(), t = V(0);
|
|
569
|
+
return i.current == null && (i.current = e), n.equals(e, i.current) || (s && s.debug && process.env.NODE_ENV !== "production" && console.info("Stable hook update triggered:", { prev: i.current, value: e }), i.current = e, t.current += 1), [t.current];
|
|
570
|
+
}, L = function(e, n, s, i) {
|
|
571
|
+
return de(e, Be(n, s, i));
|
|
572
|
+
};
|
|
573
|
+
const He = () => O({
|
|
535
574
|
predictableActionArguments: !0,
|
|
536
575
|
preserveActionOrder: !0,
|
|
537
576
|
schema: {
|
|
@@ -545,50 +584,50 @@ const Ae = (e) => (n) => (n({
|
|
|
545
584
|
sessionUpdating: null,
|
|
546
585
|
session: null,
|
|
547
586
|
configuration: null,
|
|
548
|
-
isReadyPromise:
|
|
587
|
+
isReadyPromise: J()
|
|
549
588
|
},
|
|
550
589
|
entry: [
|
|
551
|
-
|
|
552
|
-
sessionManagementActor: () =>
|
|
553
|
-
configurationSubscriptionManagementActor: () =>
|
|
590
|
+
p({
|
|
591
|
+
sessionManagementActor: () => Q(_e()),
|
|
592
|
+
configurationSubscriptionManagementActor: () => Q(Fe())
|
|
554
593
|
})
|
|
555
594
|
],
|
|
556
595
|
exit: [
|
|
557
|
-
|
|
558
|
-
|
|
596
|
+
K((e) => e.sessionManagementActor),
|
|
597
|
+
K((e) => e.configurationSubscriptionManagementActor)
|
|
559
598
|
],
|
|
560
599
|
on: {
|
|
561
600
|
// Forward events for sessionManagement
|
|
562
601
|
ChangeConfigurationClient: {
|
|
563
602
|
actions: [
|
|
564
|
-
|
|
603
|
+
P((e) => e.sessionManagementActor)
|
|
565
604
|
]
|
|
566
605
|
},
|
|
567
606
|
ChangeSessionContext: {
|
|
568
607
|
actions: [
|
|
569
|
-
|
|
608
|
+
P((e) => e.sessionManagementActor)
|
|
570
609
|
]
|
|
571
610
|
},
|
|
572
611
|
RetrySessionCreation: {
|
|
573
612
|
actions: [
|
|
574
|
-
|
|
613
|
+
P((e) => e.sessionManagementActor)
|
|
575
614
|
]
|
|
576
615
|
},
|
|
577
616
|
RetrySessionUpdate: {
|
|
578
617
|
actions: [
|
|
579
|
-
|
|
618
|
+
P((e) => e.sessionManagementActor)
|
|
580
619
|
]
|
|
581
620
|
},
|
|
582
621
|
SessionManagementStateChanged: {
|
|
583
622
|
actions: [
|
|
584
623
|
// Assign the received data
|
|
585
|
-
|
|
624
|
+
p((e, n) => ({
|
|
586
625
|
session: n.session,
|
|
587
626
|
sessionInitialization: n.sessionInitialization,
|
|
588
627
|
sessionUpdating: n.sessionUpdating
|
|
589
628
|
})),
|
|
590
629
|
// Forward the session to the configuration subscription
|
|
591
|
-
|
|
630
|
+
pe((e) => ({
|
|
592
631
|
type: "ChangeSession",
|
|
593
632
|
session: e.session
|
|
594
633
|
}), { to: (e) => e.configurationSubscriptionManagementActor }),
|
|
@@ -597,7 +636,7 @@ const Ae = (e) => (n) => (n({
|
|
|
597
636
|
},
|
|
598
637
|
ConfigurationChanged: {
|
|
599
638
|
actions: [
|
|
600
|
-
|
|
639
|
+
p((e, n) => ({
|
|
601
640
|
configuration: {
|
|
602
641
|
session: n.session,
|
|
603
642
|
configuration: n.configuration
|
|
@@ -613,123 +652,106 @@ const Ae = (e) => (n) => (n({
|
|
|
613
652
|
}
|
|
614
653
|
}, {
|
|
615
654
|
actions: {
|
|
616
|
-
calculateReadyState:
|
|
655
|
+
calculateReadyState: p((e, n) => {
|
|
617
656
|
var t;
|
|
618
657
|
const s = !((t = e.sessionInitialization) != null && t.isInitializing) && e.session != null && e.configuration != null && e.configuration.session === e.session;
|
|
619
658
|
return e.isReadyPromise && s && (e.isReadyPromise.resolve(), e.isReadyPromise.capsule.promise = null), {
|
|
620
|
-
isReadyPromise: (() => s ? null : e.isReadyPromise != null ? e.isReadyPromise :
|
|
659
|
+
isReadyPromise: (() => s ? null : e.isReadyPromise != null ? e.isReadyPromise : J())()
|
|
621
660
|
};
|
|
622
661
|
})
|
|
623
662
|
}
|
|
624
663
|
});
|
|
625
|
-
function
|
|
626
|
-
var
|
|
627
|
-
const [n, s] =
|
|
628
|
-
logger: (...
|
|
664
|
+
function Ve(e) {
|
|
665
|
+
var c, d;
|
|
666
|
+
const [n, s] = me(He, {
|
|
667
|
+
logger: (...r) => console.log("ConfigurationManagement:", ...r)
|
|
629
668
|
});
|
|
630
|
-
|
|
669
|
+
L(() => {
|
|
631
670
|
s({
|
|
632
671
|
type: "ChangeConfigurationClient",
|
|
633
672
|
client: e.configuratorClient
|
|
634
673
|
}), e.configuratorClient || console.warn("The configurator client is null or undefined. This will dispose the session that may exist. If this was not intended, make sure you pass a valid client.");
|
|
635
|
-
}, [e.configuratorClient]),
|
|
636
|
-
const
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
674
|
+
}, [e.configuratorClient], u.tuple(q)), L(() => {
|
|
675
|
+
const r = m(
|
|
676
|
+
a.fromNullable(e.sessionContext),
|
|
677
|
+
a.chainFirst((f) => a.fromNullable(f.configurationModelSource)),
|
|
678
|
+
a.toNullable
|
|
640
679
|
);
|
|
641
680
|
s({
|
|
642
681
|
type: "ChangeSessionContext",
|
|
643
|
-
sessionContext:
|
|
644
|
-
}),
|
|
645
|
-
}, [e.sessionContext]);
|
|
646
|
-
const i =
|
|
682
|
+
sessionContext: r
|
|
683
|
+
}), r || console.warn("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.");
|
|
684
|
+
}, [e.sessionContext], u.tuple(_));
|
|
685
|
+
const i = g(
|
|
647
686
|
() => {
|
|
648
|
-
var
|
|
687
|
+
var r, f, B, H;
|
|
649
688
|
return {
|
|
650
|
-
isInitializing: ((
|
|
651
|
-
isInitializingPromise: (
|
|
652
|
-
error: ((
|
|
689
|
+
isInitializing: ((f = (r = n.context.isReadyPromise) == null ? void 0 : r.capsule) == null ? void 0 : f.promise) != null,
|
|
690
|
+
isInitializingPromise: (B = n.context.isReadyPromise) == null ? void 0 : B.capsule,
|
|
691
|
+
error: ((H = n.context.sessionInitialization) == null ? void 0 : H.errorType) && {
|
|
653
692
|
type: n.context.sessionInitialization.errorType,
|
|
654
693
|
retry: () => s({ type: "RetrySessionCreation" })
|
|
655
694
|
}
|
|
656
695
|
};
|
|
657
696
|
},
|
|
658
697
|
[n.context.sessionInitialization, n.context.isReadyPromise]
|
|
659
|
-
), t =
|
|
698
|
+
), t = g(
|
|
660
699
|
() => {
|
|
661
|
-
var
|
|
700
|
+
var r, f;
|
|
662
701
|
return {
|
|
663
|
-
isUpdating: (
|
|
664
|
-
error: ((
|
|
702
|
+
isUpdating: (r = n.context.sessionUpdating) == null ? void 0 : r.isUpdating,
|
|
703
|
+
error: ((f = n.context.sessionUpdating) == null ? void 0 : f.errorType) && {
|
|
665
704
|
type: n.context.sessionUpdating.errorType,
|
|
666
705
|
retry: () => s({ type: "RetrySessionUpdate" })
|
|
667
706
|
}
|
|
668
707
|
};
|
|
669
708
|
},
|
|
670
709
|
[n.context.sessionUpdating]
|
|
671
|
-
),
|
|
710
|
+
), o = ((c = n.context.configuration) == null ? void 0 : c.session) === n.context.session ? (d = n.context.configuration) == null ? void 0 : d.configuration : null;
|
|
672
711
|
return {
|
|
673
712
|
configurationInitialization: i,
|
|
674
713
|
configurationUpdating: t,
|
|
675
714
|
session: n.context.session,
|
|
676
|
-
configuration:
|
|
715
|
+
configuration: o
|
|
677
716
|
};
|
|
678
717
|
}
|
|
679
|
-
function
|
|
680
|
-
const {
|
|
681
|
-
configuratorClient:
|
|
682
|
-
sessionContext:
|
|
718
|
+
function rn(e) {
|
|
719
|
+
const { configuratorClient: n, ...s } = e, { configurationInitialization: i, configurationUpdating: t, session: o, configuration: c } = Ve({
|
|
720
|
+
configuratorClient: n,
|
|
721
|
+
sessionContext: s
|
|
683
722
|
});
|
|
684
|
-
return /* @__PURE__ */
|
|
723
|
+
return /* @__PURE__ */ R(Y.Provider, { value: i, children: /* @__PURE__ */ R(Z.Provider, { value: t, children: /* @__PURE__ */ R(X.Provider, { value: o, children: /* @__PURE__ */ R($.Provider, { value: c, children: e.children }) }) }) });
|
|
685
724
|
}
|
|
686
|
-
function
|
|
687
|
-
return
|
|
725
|
+
function Qe() {
|
|
726
|
+
return I(Y);
|
|
688
727
|
}
|
|
689
|
-
function
|
|
690
|
-
return
|
|
728
|
+
function an() {
|
|
729
|
+
return I(Z);
|
|
691
730
|
}
|
|
692
|
-
function
|
|
693
|
-
const { children: n } = e, { isInitializingPromise: s } =
|
|
731
|
+
function ln(e) {
|
|
732
|
+
const { children: n } = e, { isInitializingPromise: s } = Qe();
|
|
694
733
|
if (s != null && s.promise)
|
|
695
734
|
throw s.promise;
|
|
696
|
-
return /* @__PURE__ */
|
|
697
|
-
}
|
|
698
|
-
function Ge() {
|
|
699
|
-
const e = N();
|
|
700
|
-
return T(e), u(() => ({
|
|
701
|
-
// explainChoiceAttributeConsequence: (a, v, m) => configurationSession.explain({
|
|
702
|
-
// type: ExplainType.ChoiceValue,
|
|
703
|
-
// attributeId: a,
|
|
704
|
-
// choiceValueId: v,
|
|
705
|
-
// question: m
|
|
706
|
-
// } as ExplainChoiceValue),
|
|
707
|
-
// explainChoiceAttributeConsequences: (a, m) => configurationSession.explain({
|
|
708
|
-
// type: ExplainType.Choice,
|
|
709
|
-
// attributeId: a,
|
|
710
|
-
// question: m
|
|
711
|
-
// } as ExplainChoice),
|
|
712
|
-
// applySolution: (s) => configurationSession.applySolution(s)
|
|
713
|
-
}), [e]);
|
|
735
|
+
return /* @__PURE__ */ R(ge, { children: n });
|
|
714
736
|
}
|
|
715
|
-
function
|
|
716
|
-
const e =
|
|
717
|
-
return
|
|
737
|
+
function cn() {
|
|
738
|
+
const e = F(), n = x();
|
|
739
|
+
return j(e), b(n), g(() => ({
|
|
718
740
|
configuration: n,
|
|
719
741
|
restoreConfiguration: (s) => e.restoreConfiguration(s)
|
|
720
742
|
}), [n, e]);
|
|
721
743
|
}
|
|
722
744
|
export {
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
745
|
+
rn as Configuration,
|
|
746
|
+
ln as ConfigurationSuspender,
|
|
747
|
+
en as useAttributes,
|
|
748
|
+
tn as useBooleanAttribute,
|
|
749
|
+
nn as useChoiceAttribute,
|
|
750
|
+
on as useComponentAttribute,
|
|
751
|
+
cn as useConfiguration,
|
|
752
|
+
Qe as useConfigurationInitialization,
|
|
753
|
+
an as useConfigurationUpdating,
|
|
754
|
+
N as useDecision,
|
|
755
|
+
qe as useExplain,
|
|
756
|
+
sn as useNumericAttribute
|
|
735
757
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viamedici-spc/configurator-react",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-alpha0026",
|
|
4
4
|
"description": "React TypeScript library to build configurator web applications based on the Viamedici Headless Configuration API (HCA).",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"files": [
|
|
@@ -54,11 +54,12 @@
|
|
|
54
54
|
"vitest": "^0.34.1"
|
|
55
55
|
},
|
|
56
56
|
"dependencies": {
|
|
57
|
-
"@viamedici-spc/configurator-ts": "1.1.0-
|
|
57
|
+
"@viamedici-spc/configurator-ts": "1.1.0-alpha0006",
|
|
58
58
|
"@viamedici-spc/fp-ts-extensions": "1.0.0",
|
|
59
59
|
"@xstate/react": "^3.2.2",
|
|
60
60
|
"fast-equals": "^4.0.3",
|
|
61
|
-
"ts-
|
|
61
|
+
"fp-ts-react-stable-hooks": "^1.5.0",
|
|
62
|
+
"ts-pattern": "^5.0.6",
|
|
62
63
|
"url-join": "^5.0.0",
|
|
63
64
|
"xstate": "^4.38.2"
|
|
64
65
|
},
|