UNPKG

@cosmicmind/domainjs

Version:

A domain-driven design framework for scalable systems.

2 lines (1 loc) 4.85 kB
"use strict";var e=Object.defineProperty,r=(r,t)=>e(r,"name",{value:t,configurable:!0}),t=(r,t,n)=>((r,t,n)=>t in r?e(r,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[t]=n)(r,"symbol"!=typeof t?t+"":t,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@cosmicmind/foundationjs"),i=require("@cosmicmind/patternjs"),o=class extends n.FoundationError{};r(o,"EntityError");let l=o;const a=r(((e={})=>r=>u(r,e)),"defineEntity");function s(e){return{set(r,t,n){var i,o,l,a;const s=null==(i=e.properties)?void 0:i[t];!1===(null==(o=null==s?void 0:s.validator)?void 0:o.call(s,n,r))&&c(`${JSON.stringify(r)} ${JSON.stringify(t)} is invalid`,e),null==(l=null==s?void 0:s.updated)||l.call(s,n,r[t],r);const u=Reflect.set(r,t,n);return null==(a=e.trace)||a.call(e,r),u}}}function c(e,r){var t;const n=new l(e);throw null==(t=r.error)||t.call(r,n),n}function u(e,r={}){var t,i,o,l;if(n.guard(e)){const a=r.properties;if(n.guard(a)){const u=new Proxy(e,s(r));for(const[o,l]of Object.entries(a))l.required?(o in e||c(`${JSON.stringify(e)} ${o} is required`,r),!1===(null==(t=l.validator)?void 0:t.call(l,e[o],u))&&c(`${JSON.stringify(e)} ${o} is invalid`,r)):o in e&&void 0!==e[o]&&n.guard(l,"validator")&&!1===(null==(i=l.validator)?void 0:i.call(l,e[o],u))&&c(`${JSON.stringify(e)} ${o} is invalid`,r);return null==(o=r.created)||o.call(r,u),null==(l=r.trace)||l.call(r,u),u}}c(`${JSON.stringify(e)} is invalid`,r)}r(s,"makeEntityHandler"),r(c,"throwError$2"),r(u,"makeEntity");const d=class extends i.Observable{};r(d,"Observable");let v=d;const f=class extends v{};r(f,"EventObservable");let g=f;const p=class extends n.FoundationError{};r(p,"EventError");let y=p;const E=r(((e={})=>r=>O(r,e)),"defineEvent");function $(e){return{set(){x("cannot modify event properties",e)}}}function x(e,r){var t;const n=new y(e);throw null==(t=r.error)||t.call(r,n),n}function O(e,r={}){var t,i,o;if(n.guard(e)){const l=r.properties;if(n.guard(l)){const a=new Proxy(e,$(r));for(const[o,s]of Object.entries(l))s.required?(o in e||x(`${JSON.stringify(e)} ${o} is required`,r),!1===(null==(t=s.validator)?void 0:t.call(s,e[o],a))&&x(`${JSON.stringify(e)} ${o} is invalid`,r)):o in e&&void 0!==e[o]&&n.guard(s,"validator")&&!1===(null==(i=s.validator)?void 0:i.call(s,e[o],a))&&x(`${JSON.stringify(e)} ${o} is invalid`,r);return null==(o=r.created)||o.call(r,a),a}}throw new y(`${String(e)} is invalid`)}r($,"makeEventHandler"),r(x,"throwError$1"),r(O,"makeEvent");const b=class extends g{constructor(e){super(),t(this,"root"),this.root="function"==typeof this.prepare?this.prepare(e):e}};r(b,"Aggregate");let w=b;function h(e,r={}){const t=a(r);return r=>new e(t(r))}r(h,"defineAggregate");const S=class extends v{};r(S,"MessageObservable");let m=S;const J=class extends n.FoundationError{};r(J,"MessageError");let N=J;const M=r(((e={})=>r=>j(r,e)),"defineMessage");function q(e){return{set(){V("cannot modify message properties",e)}}}function V(e,r){var t;const n=new N(e);throw null==(t=r.error)||t.call(r,n),n}function j(e,r={}){var t,i,o;if(n.guard(e)){const l=r.properties;if(n.guard(l)){const a=new Proxy(e,q(r));for(const[o,s]of Object.entries(l))s.required?(o in e||V(`${JSON.stringify(e)} ${o} is required`,r),!1===(null==(t=s.validator)?void 0:t.call(s,e[o],a))&&V(`${JSON.stringify(e)} ${o} is invalid`,r)):o in e&&void 0!==e[o]&&n.guard(s,"validator")&&!1===(null==(i=s.validator)?void 0:i.call(s,e[o],a))&&V(`${JSON.stringify(e)} ${o} is invalid`,r);return null==(o=r.created)||o.call(r,a),a}}throw new N(`${String(e)} is invalid`)}r(q,"makeMessageHandler"),r(V,"throwError"),r(j,"makeMessage");const k=class{constructor(e){t(this,"_value"),this._value="function"==typeof this.prepare?this.prepare(e):e}get value(){return this._value}};r(k,"Value");let P=k;const A=class extends n.FoundationError{};r(A,"ValueError");let F=A;const H=r(((e,r={})=>t=>T(new e(t),t,r)),"defineValue");function _(e){return{set(r,t,n){var i;if("value"===t&&!1===(null==(i=e.validator)?void 0:i.call(e,n,r)))throw new F(`${String(t)} is invalid`);return Reflect.set(r,t,n)}}}function R(e,r){var t;const n=new F(e);throw null==(t=r.error)||t.call(r,n),n}function T(e,r,t={}){var i,o,l;if(n.guard(e)){const n=new Proxy(e,_(t));if(!1===(null==(i=t.validator)?void 0:i.call(t,r,n))){R(`${e.constructor.name} is invalid: ${JSON.stringify(r)}`,t)}return null==(o=t.created)||o.call(t,n),null==(l=t.trace)||l.call(t,n),n}R(`${JSON.stringify(e)} is invalid`,t)}r(_,"createValueHandler"),r(R,"throwErrorAndTrace"),r(T,"createValue"),exports.Aggregate=w,exports.EntityError=l,exports.EventError=y,exports.EventObservable=g,exports.MessageError=N,exports.MessageObservable=m,exports.Observable=v,exports.Value=P,exports.ValueError=F,exports.defineAggregate=h,exports.defineEntity=a,exports.defineEvent=E,exports.defineMessage=M,exports.defineValue=H;