UNPKG

di-tory

Version:

Compose applications with dependency injection

1 lines 3 kB
"use strict";var DiToryLight=(()=>{var t=Object.defineProperty,e=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,n=Object.prototype.hasOwnProperty,o={};((e,r)=>{for(var n in r)t(e,n,{get:r[n],enumerable:!0})})(o,{Module:()=>l,default:()=>p,scope:()=>u});var s,i=class t extends Error{static messages={0:"Stack is empty",1:"Item already exists in stack"};static Empty=new t(0);static Exists=new t(1);constructor(e){super(t.messages[e])}},c=class{constructor(t=[],e=new Set){this.items=t,this.set=e}push(t){if(this.set.has(t))throw new i(1);this.items.push(t),this.set.add(t)}pop(){const t=this.items.pop();if(null==t)throw new i(0);return this.set.delete(t),t}peek(){return this.items.at(-1)}toStringArray(){return this.items.map(String)}get length(){return this.items.length}},a=class extends Error{constructor(t,e,r,n){super(`${t} in attempting to resolve <${r}>${e.length>0?` with stack ${e.map(t=>`<${t}>`).join(" <- ")}`:""}`,{cause:n}),this.code=t,this.resolutionStack=e,this.item=r}},u={module:"module",singleton:"singleton"},l=()=>{const t={},e={};let r=null,n=!1;const o=new Map,s={private(e,r){if(n)throw new Error("Cannot extend initialized module");for(const n of Object.keys(e)){const o=e[n];if("function"!=typeof o)throw new Error(`Expected ${String(n)} to be a function, but got ${typeof o}`);o.scope??=r,t[n]=o}return s},privateImpl(e){if(n)throw new Error("Cannot extend initialized module");for(const r of Object.keys(e)){const n=e[r],o=t=>(...e)=>n(t,...e);o.scope="module",t[r]=o}return s},public(t,r){if(n)throw new Error("Cannot extend initialized module");for(const n of Object.keys(t)){const o=t[n];if("function"!=typeof o)throw new Error(`Expected ${String(n)} to be a function, but got ${typeof o}`);o.scope??=r,e[n]=o}return s},publicImpl(t){if(n)throw new Error("Cannot extend initialized module");for(const r of Object.keys(t)){const n=t[r],o=t=>(...e)=>n(t,...e);o.scope="module",e[r]=o}return s},init:t=>(r=t,n=!0,s),create:(s={})=>(n=!0,((t,e,r,n,o)=>{const s={...e,...r},i=new c,u=new Map,l={},p={};for(const t of Object.keys(e))Object.defineProperty(l,t,{get:()=>f(t)}),Object.defineProperty(p,t,{get:()=>{throw new a("PrivateMemberAccessFailure",i.toStringArray(),String(t))}});for(const t of Object.keys(r))Object.defineProperty(l,t,{get:()=>f(t)}),Object.defineProperty(p,t,{get:()=>f(t)});const f=e=>{const r=s[e],c="singleton"===r.scope?t:u;if(c.has(e))return c.get(e);const p=i.toStringArray();try{i.push(e)}catch{throw new a("CircularDependencyFailure",i.toStringArray(),String(e))}let f;try{f=r(l,o)}catch(t){if(t instanceof a)throw t;throw new a("InstantiationFailure",p,String(e),t)}return i.pop(),c.set(e,f),0===i.length&&n[e]?.call(f,l,o),f};return p})(o,t,e,r??{},s))};return s},p=l;return s=o,((o,s,i,c)=>{if(s&&"object"==typeof s||"function"==typeof s)for(let a of r(s))n.call(o,a)||a===i||t(o,a,{get:()=>s[a],enumerable:!(c=e(s,a))||c.enumerable});return o})(t({},"__esModule",{value:!0}),s)})();//# sourceMappingURL=di-tory.light.min.js.map