assemblerjs 0.4.1 → 0.5.0
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/README.md +1 -1
- package/dist/index.d.ts +8 -0
- package/dist/index.js +1 -1
- package/dist/index.mjs +156 -152
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
A general purpose and zero-dependency [Dependency Injection](https://en.wikipedia.org/wiki/Dependency_injection) library for node and browser.
|
|
4
4
|
|
|
5
|
-
   
|
|
6
6
|
|
|
7
7
|
---
|
|
8
8
|
|
package/dist/index.d.ts
CHANGED
|
@@ -415,6 +415,14 @@ export declare class Assembler extends EventManager implements AbstractAssembler
|
|
|
415
415
|
*/
|
|
416
416
|
declare type InstanceInjection<T> = Tuple<[Identifier<T> | string | Symbol, T]>;
|
|
417
417
|
|
|
418
|
+
/**
|
|
419
|
+
* Check if a given class is an `Assemblage`.
|
|
420
|
+
*
|
|
421
|
+
* @param { Concrete<T> } target The class to test.
|
|
422
|
+
* @returns `true` if the class is an assemblage.
|
|
423
|
+
*/
|
|
424
|
+
export declare const isAssemblage: <T>(target: Concrete<T>) => boolean;
|
|
425
|
+
|
|
418
426
|
/**
|
|
419
427
|
* Describes a listener type as a function taking any number of arguments and returning `void`.
|
|
420
428
|
*/
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=function(e){return e.IsAssemblage="is_assemblage",e}({}),t=function(e){return e.AssemblageDefinition="assemblage:definition.value",e}({});const n=(...e)=>{},s=(...e)=>t=>{if(e.includes(typeof t))return typeof t},i=e=>!(e=>void 0===e)(e)&&!(e=>null===e)(e),r=e=>e&&"function"==typeof e&&void 0!==e.constructor,o=e=>"function"==typeof e&&"AsyncFunction"===e.constructor.name,c=(e,...t)=>{t.map(((e,n)=>{const s=/\S/.test(e);return s&&(t[n]=t[n].trim()),s?-1:n})).filter((e=>e>=0)).every((e=>{t[e]=" ",((e,t,n)=>{const s=e[t];e.splice(t,1),e.splice(n,0,s)})(t,e,t.length-1)})),t=(e=>Array.from(new Set(e)))(t);const n=new RegExp(`[^A-Za-zÀ-ÖØ-öø-ÿ0-9${t.join("")}]`,"gi");return e.replace(n,"")},a=(...e)=>t=>e.reduce(((e,t)=>t(e)),t),h=e=>t=>e.if(t)?e.then(t):e.else?e.else(t):void 0,l=e=>t=>{const s=Array.isArray(e)?e=>parseInt(e):n;for(const[n,i]of Object.entries(e))t(i,s(n))},u=(e,t)=>{const n=new Proxy(e,{get:function(n,s){return s===Symbol.iterator?n[Symbol.iterator].bind(n):((e,t)=>[...Object.getOwnPropertyNames(t.prototype),...Object.getOwnPropertyNames(Object.getPrototypeOf(e)),...Object.getOwnPropertyNames(e)])(e,t).includes(s)?n[s]:n.collection[s]},set:function(e,t,n){return Reflect.set(e,t,n)}});return n},f=(e,t)=>{const n=e;for(const s of((e,t)=>[...Object.getOwnPropertyNames(t.prototype),...Object.getOwnPropertyNames(Object.getPrototypeOf(e)),...Object.getOwnPropertyNames(e)])(e,t))delete n[s]},d=(e,t,n)=>{Reflect.defineMetadata(`__${e}__`,t,n)},p=(e,t)=>Reflect.getOwnMetadata(`__${e}__`,t),g=e=>Reflect.getMetadata("design:paramtypes",e)||[],b=t=>p(e.IsAssemblage,t)||!1,y={singleton:{test:e=>"boolean"==typeof e||void 0===e,throw:()=>{throw new Error("'singleton' property must be of type 'boolean' or 'undefined'.")},transform:e=>void 0===e},events:{test:e=>void 0===e||Array.isArray(e)&&e.every((e=>"string"==typeof e)),throw:()=>{throw new Error("'events' property must be an array of strings or 'undefined'.")},transform:e=>e},inject:{test:e=>void 0===e||Array.isArray(e)&&e.every((e=>Array.isArray(e)&&e.length>=1&&e.length<=3)),throw:()=>{throw new Error("'inject' property must be an array of tuples of length 1, 2 or 3.")},transform:e=>e},use:{test:e=>void 0===e||Array.isArray(e)&&e.every((e=>Array.isArray(e)&&2==e.length)),throw:()=>{throw new Error("'use' property must be an array of tuples of length 2.")},transform:e=>e},tags:{test:e=>void 0===e||"string"==typeof e||Array.isArray(e)&&e.every((e=>"string"==typeof e)),throw:()=>{throw new Error("'tags' property must be a string or an array of strings.")},transform:e=>"string"==typeof e?[e]:e},metadata:{test:e=>("object"==typeof e||void 0===e)&&!Array.isArray(e),throw:()=>{throw new Error("'metadata' property must be of type 'object' or 'undefined'.")},transform:e=>e}},m=e=>{const t={...e};for(const n in t){if(!Object.keys(y).includes(n))throw new Error(`Property '${n}' is not a valid assemblage definition property.`);const e=y[n].test,s=y[n].throw,i=y[n].transform;e(t[n])||s(),t[n]=i(t[n])}return t},v=e=>{if(!b(e))throw new Error(`Class '${e.name}' is not an assemblage.`);return p(t.AssemblageDefinition,e)},w=(e,t)=>v(t)[e],x=e=>{const t=()=>r(e[0])&&(e=>"object"==typeof e&&!Array.isArray(e)&&!r(e))(e[1]);return a(h({if:()=>r(e[0])&&r(e[1]),then:()=>({identifier:e[0],concrete:e[1],configuration:{}})}),h({if:()=>t(),then:()=>({identifier:e[0],concrete:e[0],configuration:e[1]}),else:e=>e}))()};var C=function(e){return e.UseIdentifier="assemblage:use.param.value",e}({}),j=function(e){return e.Context="assembler:context.param.index",e.Dispose="assembler:dispose.param.index",e.Definition="assemblage:definition.param.index",e.Configuration="assemblage:configuration.param.index",e.Use="assemblage:use.param.index",e}({});const A=e=>()=>(t,n,s)=>{const i=p(e,t)||[];i.push(s),d(e,i,t)},I=A(j.Context),O=A(j.Configuration),P=A(j.Definition),E=A(j.Dispose),D=e=>{const t=(e=>p(j.Context,e)||[])(e),n=(e=>p(j.Definition,e)||[])(e),s=(e=>p(j.Configuration,e)||[])(e),i=(e=>p(j.Dispose,e)||[])(e),r=(e=>p(j.Use,e)||[])(e);return{context:t,definition:n,configuration:s,dispose:i,use:r}};let $=Symbol.iterator;class S{dispose(){f(this,S)}add(...e){const t=e=>this.collection[e.channel].push(e.listener),n=h({if:()=>2===e.length,then:()=>({channel:e[0],listener:e[1]}),else:()=>{const t=e[0];return{channel:t[0],listener:t[1]}}}),s=h({if:e=>!i(this.collection[e.channel]),then:e=>{this.collection[e.channel]=[],t(e)},else:e=>{t(e)}});return a(n,s)(),this}remove(e,t){const n=t=>this.collection[e].splice(t,1),s=h({if:()=>this.collection[e]&&0===this.collection[e].length,then:()=>delete this.collection[e]}),r=h({if:()=>i(t),then:()=>n(this.collection[e].indexOf(t)),else:()=>delete this.collection[e]}),o=h({if:e=>this.has(e),then:e=>this.collection[e]});return a(o,r,s)(),this}has(...e){return s("string")(e[0])?Object.keys(this.collection).includes(e[0]):!!s("function")(e[0])&&Object.values(this.collection).flat().includes(e[0])}get(...e){return s("string")(e[0])?this.collection[e[0]]:s("function")(e[0])?Object.values(this.collection).flat().filter((t=>t===e[0])):[]}clear(){const e=(e=>t=>{const n=Array.isArray(e)?e=>parseInt(e):e=>e;for(const s in e)t(n(s))})(this.collection),t=e=>l(this.collection[e])((t=>this.remove(e,t)));return e((e=>t(e))),this}get listeners(){return Object.values(this.collection).flat()}get channels(){return Object.keys(this.collection)}get length(){return Object.values(this.collection).flat().length}[$](){let e=-1;const t=this.collection?Object.keys(this.collection):[];return{next:()=>({value:t[++e],done:!(e in t)})}}constructor(){!function(e,t,n){t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n}(this,"collection",{});return u(this,S)}}class R{}function U(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class _{dispose(){this.listeners.dispose(),this.channels.clear(),f(this,_)}addChannels(...e){return l(e)((e=>{const t=this.cleanChannel(e);if(this.channels.has(t))throw new Error(`Channel '${t}' already exists.`);this.channels.add(t)})),this}removeChannels(...e){return l(e)((e=>{const t=this.cleanChannel(e);"*"!==t&&this.channels.has(t)&&(this.channels.delete(t),this.listeners.remove(t),this.onceListeners.remove(t))})),this}on(e,t){const n=this.cleanChannel(e);if(!this.channels.has(n))throw new Error(`Channel '${n}' was not registered.`);return this.listeners.add(n,t),this}once(e,t){const n=this.cleanChannel(e);if(!this.channels.has(n))throw new Error(`Channel '${n}' was not registered.`);return this.onceListeners.add(n,t),this}off(e,t){const n=this.cleanChannel(e);return this.listeners.remove(n,t),this}emit(e,...t){const n=this.cleanChannel(e);if(this.channels.has(n)){const e=this.onceListeners.get("*")||[],s=this.listeners.get("*")||[],i=this.onceListeners.get(n)||[],r=this.listeners.get(n)||[],o=l(e),c=l(s),a=l(i),h=l(r);o((e=>{this.run(e,...t),this.onceListeners.remove("*",e)})),c((e=>{this.run(e,...t)})),a((e=>{this.run(e,...t),this.onceListeners.remove(n,e)})),h((e=>{this.run(e,...t)}))}return this}run(e,...t){if(o(e)){return e(...t).then((()=>Promise.resolve()))}e(...t)}cleanChannel(e){return c(e,"*")}constructor(...e){U(this,"listeners",new S),U(this,"onceListeners",new S),U(this,"channels",new Set(["*"])),this.addChannels(...e)}}function k(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class M{static of(e,t,n){return new M(e,t,n)}dispose(){this.singletonInstance&&(((e,t)=>{if(e.concrete.prototype instanceof _){const n=t;for(const t of e.events)n.off(t);n.removeChannels(...e.events),e.privateContext.removeChannels(...e.events)}})(this,this.singletonInstance),L(this.singletonInstance,"onDispose",this.publicContext),f(this.singletonInstance,this.concrete)),f(this,M)}build(){if(this.singletonInstance)return this.singletonInstance;const e=(e=>{const t=[],n=g(e.concrete),s=D(e.concrete);let i=0;for(const r of n)if(s.context.includes(i))t.push(e.publicContext),i++;else if(s.configuration.includes(i))t.push(e.configuration),i++;else if(s.definition.includes(i))t.push(e.definition),i++;else if(s.dispose.includes(i))t.push(e.privateContext.dispose),i++;else if(s.use.includes(i)){const n=p(C.UseIdentifier,e.concrete)[i];t.push(e.privateContext.require(n)),i++}else t.push(e.privateContext.require(r)),i++;return t})(this),t=new this.concrete(...e);return((e,t)=>{if(e.concrete.prototype instanceof _){const n=t,s=n.channels;for(const t of e.events)s.has(t)||n.addChannels(t),e.privateContext.events.has(t)||e.privateContext.addChannels(t);for(const i of e.events)t.on(i,((...t)=>{e.privateContext.emit(i,...t)}))}})(this,t),this.isSingleton?(this.singletonInstance=t,this.privateContext.prepareInitHook(t),this.singletonInstance):(L(t,"onInit",this.publicContext),t)}get dependencies(){return this.dependenciesIds}get definition(){return v(this.concrete)||{}}get isSingleton(){return w("singleton",this.concrete)||!0}get singleton(){return this.singletonInstance}get injections(){return w("inject",this.concrete)||[]}get objects(){return w("use",this.concrete)||[]}get tags(){return w("tags",this.concrete)||[]}get events(){return w("events",this.concrete)||[]}constructor(e,t,n){if(k(this,"privateContext",void 0),k(this,"publicContext",void 0),k(this,"identifier",void 0),k(this,"concrete",void 0),k(this,"configuration",void 0),k(this,"dependenciesIds",void 0),k(this,"singletonInstance",void 0),this.privateContext=t,this.publicContext=n,this.dependenciesIds=[],this.identifier=e.identifier,this.concrete=e.concrete,this.configuration=e.configuration,!b(this.concrete))throw new Error(`Class '${this.concrete.name}' is not an Assemblage.`);const s=l(this.injections),i=l(this.objects);s((e=>this.privateContext.register(e))),i((e=>{"string"==typeof e[0]||"symbol"==typeof e[0]?this.privateContext.use(e[0],e[1]):this.privateContext.register(e,!0)})),this.dependenciesIds=(e=>{const t=[],n=g(e),s=D(e);let i=0;for(const r of n)s.context.includes(i)||s.configuration.includes(i)||s.definition.includes(i)||s.dispose.includes(i)||s.use.includes(i)||t.push(r),i++;return t})(this.concrete),e.instance&&(this.singletonInstance=e.instance)}}const L=(e,t,n)=>new Promise((s=>{const i=e[t];if(i){if(o(i))return void i.bind(e)(n).then((()=>{s()}));s(i.bind(e)(n))}}));function q(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class N extends _{static build(e){const n=new N;((e,n,s)=>{const i=v(s);i[e]=n;const r=m(i);d(t.AssemblageDefinition,r,s)})("singleton",!0,e);const s=n.register([e]),i=n.require(s.identifier),r=n.initCache.indexOf(i);n.initCache.splice(r,1);for(const t of n.initCache)L(t,"onInit",n.publicContext);return L(i,"onInit",n.publicContext),n.initCache.length=0,i}dispose(){for(const[e,t]of this.injectables)t.dispose();f(this,N)}register(e,t=!1){const n=!0===t?(e=>({identifier:e[0],concrete:e[0],instance:e[1],configuration:{}}))(e):(e=>((e,t)=>(n,...s)=>e[n]?e[n](...s):t?t(n,...s):void 0)({1:()=>(e=>({identifier:e[0],concrete:e[0],configuration:{}}))(e),2:()=>x(e),3:()=>(e=>({identifier:e[0],concrete:e[1],configuration:e[2]}))(e)},(()=>{throw new Error("Injection tuple must be of length 1, 2 or 3.")}))(e.length))(e);if(this.has(n.identifier))throw new Error(`An assemblage is already registered with identifier '${n.identifier.name}'.`);const s=M.of(n,this.privateContext,this.publicContext);return this.injectables.set(s.identifier,s),L(s.concrete,"onRegister",this.publicContext),s}use(e,t){if(this.has(e))throw new Error(`A value is already registered with identifier '${String(e)}'.`);return this.objects.set(e,t),t}prepareInitHook(e){return this.initCache.push(e),this.initCache}has(e){return"string"==typeof e||"symbol"==typeof e?this.objects.has(e):this.injectables.has(e)}require(e){switch(typeof e){case"string":case"symbol":if(!this.objects.has(e))throw new Error(`Injected object with identifier '${String(e)}' has not been registered.`);return this.objects.get(e);default:if(!this.injectables.has(e))throw new Error(`Class with identifier '${e.name}' has not been registered or is a circular dependency.`);return this.injectables.get(e).build()}}tagged(...e){const t=[];for(const n of e)for(const[e,s]of this.injectables)s.tags.includes(n)&&t.push(s.build());return t}get size(){return this.injectables.size}constructor(){super(),q(this,"injectables",new Map),q(this,"objects",new Map),q(this,"initCache",[]),q(this,"privateContext",void 0),q(this,"publicContext",void 0),this.publicContext={has:this.has.bind(this),require:this.require.bind(this),tagged:this.tagged.bind(this),on:this.on.bind(this),once:this.once.bind(this),off:this.off.bind(this),events:this.channels},this.privateContext={...this.publicContext,register:this.register.bind(this),use:this.use.bind(this),prepareInitHook:this.prepareInitHook.bind(this),emit:this.emit.bind(this),addChannels:this.addChannels.bind(this),removeChannels:this.removeChannels.bind(this),dispose:this.dispose.bind(this)}}}exports.AbstractAssemblage=class{static onRegister(e){}},exports.AbstractAssembler=class extends R{},exports.AbstractEventManager=R,exports.Assemblage=n=>{const s=n?m(n):{};return n=>(d(e.IsAssemblage,!0,n),d(t.AssemblageDefinition,s,n),n)},exports.Assembler=N,exports.Await=(e,t=25)=>(n,s,i)=>{const r=i.value;i.value=async function(){return new Promise((n=>{if(this[e])r.apply(this),n();else{const s=setInterval((()=>{this[e]&&(clearInterval(s),r.apply(this),n())}),t)}}))}},exports.Configuration=O,exports.Context=I,exports.Definition=P,exports.Dispose=E,exports.EventManager=_,exports.ReflectParamIndex=j,exports.ReflectParamValue=C,exports.Use=e=>(t,n,s)=>{const i=p(j.Use,t)||[];i.push(s),d(j.Use,i,t);const r=p(C.UseIdentifier,t)||{};r[s]=e,d(C.UseIdentifier,r,t)},exports.getDecoratedParametersIndexes=D;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=function(e){return e.IsAssemblage="is_assemblage",e}({}),t=function(e){return e.AssemblageDefinition="assemblage:definition.value",e}({});const n=(...e)=>{},s=(...e)=>t=>{if(e.includes(typeof t))return typeof t},i=e=>!(e=>void 0===e)(e)&&!(e=>null===e)(e),r=e=>e&&"function"==typeof e&&void 0!==e.constructor,o=e=>"function"==typeof e&&"AsyncFunction"===e.constructor.name,c=(e,...t)=>{t.map(((e,n)=>{const s=/\S/.test(e);return s&&(t[n]=t[n].trim()),s?-1:n})).filter((e=>e>=0)).every((e=>{t[e]=" ",((e,t,n)=>{const s=e[t];e.splice(t,1),e.splice(n,0,s)})(t,e,t.length-1)})),t=(e=>Array.from(new Set(e)))(t);const n=new RegExp(`[^A-Za-zÀ-ÖØ-öø-ÿ0-9${t.join("")}]`,"gi");return e.replace(n,"")},a=(...e)=>t=>e.reduce(((e,t)=>t(e)),t),h=e=>t=>e.if(t)?e.then(t):e.else?e.else(t):void 0,l=e=>t=>{const s=Array.isArray(e)?e=>parseInt(e):n;for(const[n,i]of Object.entries(e))t(i,s(n))},u=(e,t)=>{const n=new Proxy(e,{get:function(n,s){return s===Symbol.iterator?n[Symbol.iterator].bind(n):((e,t)=>[...Object.getOwnPropertyNames(t.prototype),...Object.getOwnPropertyNames(Object.getPrototypeOf(e)),...Object.getOwnPropertyNames(e)])(e,t).includes(s)?n[s]:n.collection[s]},set:function(e,t,n){return Reflect.set(e,t,n)}});return n},f=(e,t)=>{const n=e;for(const s of((e,t)=>[...Object.getOwnPropertyNames(t.prototype),...Object.getOwnPropertyNames(Object.getPrototypeOf(e)),...Object.getOwnPropertyNames(e)])(e,t))delete n[s]},d=(e,t,n)=>{Reflect.defineMetadata(`__${e}__`,t,n)},p=(e,t)=>Reflect.getOwnMetadata(`__${e}__`,t),g=e=>Reflect.getMetadata("design:paramtypes",e)||[],b=t=>p(e.IsAssemblage,t)||!1,m={singleton:{test:e=>"boolean"==typeof e||void 0===e,throw:()=>{throw new Error("'singleton' property must be of type 'boolean' or 'undefined'.")},transform:e=>void 0===e||!!e},events:{test:e=>void 0===e||Array.isArray(e)&&e.every((e=>"string"==typeof e)),throw:()=>{throw new Error("'events' property must be an array of strings or 'undefined'.")},transform:e=>e},inject:{test:e=>void 0===e||Array.isArray(e)&&e.every((e=>Array.isArray(e)&&e.length>=1&&e.length<=3)),throw:()=>{throw new Error("'inject' property must be an array of tuples of length 1, 2 or 3.")},transform:e=>e},use:{test:e=>void 0===e||Array.isArray(e)&&e.every((e=>Array.isArray(e)&&2==e.length)),throw:()=>{throw new Error("'use' property must be an array of tuples of length 2.")},transform:e=>e},tags:{test:e=>void 0===e||"string"==typeof e||Array.isArray(e)&&e.every((e=>"string"==typeof e)),throw:()=>{throw new Error("'tags' property must be a string or an array of strings.")},transform:e=>"string"==typeof e?[e]:e},metadata:{test:e=>("object"==typeof e||void 0===e)&&!Array.isArray(e),throw:()=>{throw new Error("'metadata' property must be of type 'object' or 'undefined'.")},transform:e=>e}},y=e=>{const t={...e};for(const n in t)if(!Object.keys(m).includes(n))throw new Error(`Property '${n}' is not a valid assemblage definition property.`);for(const n in m){const e=m[n].test,s=m[n].throw,i=m[n].transform;e(t[n])||s(),t[n]=i(t[n])}return t},v=e=>{if(!b(e))throw new Error(`Class '${e.name}' is not an assemblage.`);return p(t.AssemblageDefinition,e)},w=(e,t)=>v(t)[e],x=e=>{const t=()=>r(e[0])&&(e=>"object"==typeof e&&!Array.isArray(e)&&!r(e))(e[1]);return a(h({if:()=>r(e[0])&&r(e[1]),then:()=>({identifier:e[0],concrete:e[1],configuration:{}})}),h({if:()=>t(),then:()=>({identifier:e[0],concrete:e[0],configuration:e[1]}),else:e=>e}))()};let C=Symbol.iterator;class j{dispose(){f(this,j)}add(...e){const t=e=>this.collection[e.channel].push(e.listener),n=h({if:()=>2===e.length,then:()=>({channel:e[0],listener:e[1]}),else:()=>{const t=e[0];return{channel:t[0],listener:t[1]}}}),s=h({if:e=>!i(this.collection[e.channel]),then:e=>{this.collection[e.channel]=[],t(e)},else:e=>{t(e)}});return a(n,s)(),this}remove(e,t){const n=t=>this.collection[e].splice(t,1),s=h({if:()=>this.collection[e]&&0===this.collection[e].length,then:()=>delete this.collection[e]}),r=h({if:()=>i(t),then:()=>n(this.collection[e].indexOf(t)),else:()=>delete this.collection[e]}),o=h({if:e=>this.has(e),then:e=>this.collection[e]});return a(o,r,s)(),this}has(...e){return s("string")(e[0])?Object.keys(this.collection).includes(e[0]):!!s("function")(e[0])&&Object.values(this.collection).flat().includes(e[0])}get(...e){return s("string")(e[0])?this.collection[e[0]]:s("function")(e[0])?Object.values(this.collection).flat().filter((t=>t===e[0])):[]}clear(){const e=(e=>t=>{const n=Array.isArray(e)?e=>parseInt(e):e=>e;for(const s in e)t(n(s))})(this.collection),t=e=>l(this.collection[e])((t=>this.remove(e,t)));return e((e=>t(e))),this}get listeners(){return Object.values(this.collection).flat()}get channels(){return Object.keys(this.collection)}get length(){return Object.values(this.collection).flat().length}[C](){let e=-1;const t=this.collection?Object.keys(this.collection):[];return{next:()=>({value:t[++e],done:!(e in t)})}}constructor(){!function(e,t,n){t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n}(this,"collection",{});return u(this,j)}}class A{}function I(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class O{dispose(){this.listeners.dispose(),this.channels.clear(),f(this,O)}addChannels(...e){return l(e)((e=>{const t=this.cleanChannel(e);if(this.channels.has(t))throw new Error(`Channel '${t}' already exists.`);this.channels.add(t)})),this}removeChannels(...e){return l(e)((e=>{const t=this.cleanChannel(e);"*"!==t&&this.channels.has(t)&&(this.channels.delete(t),this.listeners.remove(t),this.onceListeners.remove(t))})),this}on(e,t){const n=this.cleanChannel(e);if(!this.channels.has(n))throw new Error(`Channel '${n}' was not registered.`);return this.listeners.add(n,t),this}once(e,t){const n=this.cleanChannel(e);if(!this.channels.has(n))throw new Error(`Channel '${n}' was not registered.`);return this.onceListeners.add(n,t),this}off(e,t){const n=this.cleanChannel(e);return this.listeners.remove(n,t),this}emit(e,...t){const n=this.cleanChannel(e);if(this.channels.has(n)){const e=this.onceListeners.get("*")||[],s=this.listeners.get("*")||[],i=this.onceListeners.get(n)||[],r=this.listeners.get(n)||[],o=l(e),c=l(s),a=l(i),h=l(r);o((e=>{this.run(e,...t),this.onceListeners.remove("*",e)})),c((e=>{this.run(e,...t)})),a((e=>{this.run(e,...t),this.onceListeners.remove(n,e)})),h((e=>{this.run(e,...t)}))}return this}run(e,...t){if(o(e)){return e(...t).then((()=>Promise.resolve()))}e(...t)}cleanChannel(e){return c(e,"*")}constructor(...e){I(this,"listeners",new j),I(this,"onceListeners",new j),I(this,"channels",new Set(["*"])),this.addChannels(...e)}}var P=function(e){return e.UseIdentifier="assemblage:use.param.value",e}({}),E=function(e){return e.Context="assembler:context.param.index",e.Dispose="assembler:dispose.param.index",e.Definition="assemblage:definition.param.index",e.Configuration="assemblage:configuration.param.index",e.Use="assemblage:use.param.index",e}({});const D=e=>()=>(t,n,s)=>{const i=p(e,t)||[];i.push(s),d(e,i,t)},$=D(E.Context),S=D(E.Configuration),R=D(E.Definition),U=D(E.Dispose),_=e=>{const t=(e=>p(E.Context,e)||[])(e),n=(e=>p(E.Definition,e)||[])(e),s=(e=>p(E.Configuration,e)||[])(e),i=(e=>p(E.Dispose,e)||[])(e),r=(e=>p(E.Use,e)||[])(e);return{context:t,definition:n,configuration:s,dispose:i,use:r}};function k(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class M{static of(e,t,n){return new M(e,t,n)}dispose(){this.singletonInstance&&(((e,t)=>{if(e.concrete.prototype instanceof O){const n=t;for(const t of e.events)n.off(t);n.removeChannels(...e.events),e.privateContext.removeChannels(...e.events)}})(this,this.singletonInstance),L(this.singletonInstance,"onDispose",this.publicContext),f(this.singletonInstance,this.concrete)),f(this,M)}build(){if(this.singletonInstance)return this.singletonInstance;const e=(e=>{const t=[],n=g(e.concrete),s=_(e.concrete);let i=0;for(const r of n)if(s.context.includes(i))t.push(e.publicContext),i++;else if(s.configuration.includes(i))t.push(e.configuration),i++;else if(s.definition.includes(i))t.push(e.definition),i++;else if(s.dispose.includes(i))t.push(e.privateContext.dispose),i++;else if(s.use.includes(i)){const n=p(P.UseIdentifier,e.concrete)[i];t.push(e.privateContext.require(n)),i++}else t.push(e.privateContext.require(r)),i++;return t})(this),t=new this.concrete(...e);return((e,t)=>{if(e.concrete.prototype instanceof O){const n=t,s=n.channels;for(const t of e.events)s.has(t)||n.addChannels(t),e.privateContext.events.has(t)||e.privateContext.addChannels(t);for(const i of e.events)t.on(i,((...t)=>{e.privateContext.emit(i,...t)}))}})(this,t),this.isSingleton?(this.singletonInstance=t,this.privateContext.prepareInitHook(t),this.singletonInstance):(L(t,"onInit",this.publicContext),t)}get dependencies(){return this.dependenciesIds}get definition(){return v(this.concrete)||{}}get isSingleton(){return w("singleton",this.concrete)}get singleton(){return this.singletonInstance}get injections(){return w("inject",this.concrete)||[]}get objects(){return w("use",this.concrete)||[]}get tags(){return w("tags",this.concrete)||[]}get events(){return w("events",this.concrete)||[]}constructor(e,t,n){if(k(this,"privateContext",void 0),k(this,"publicContext",void 0),k(this,"identifier",void 0),k(this,"concrete",void 0),k(this,"configuration",void 0),k(this,"dependenciesIds",void 0),k(this,"singletonInstance",void 0),this.privateContext=t,this.publicContext=n,this.dependenciesIds=[],this.identifier=e.identifier,this.concrete=e.concrete,this.configuration=e.configuration,!b(this.concrete))throw new Error(`Class '${this.concrete.name}' is not an Assemblage.`);const s=l(this.injections),i=l(this.objects);s((e=>this.privateContext.register(e))),i((e=>{"string"==typeof e[0]||"symbol"==typeof e[0]?this.privateContext.use(e[0],e[1]):this.privateContext.register(e,!0)})),this.dependenciesIds=(e=>{const t=[],n=g(e),s=_(e);let i=0;for(const r of n)s.context.includes(i)||s.configuration.includes(i)||s.definition.includes(i)||s.dispose.includes(i)||s.use.includes(i)||t.push(r),i++;return t})(this.concrete),e.instance&&(this.singletonInstance=e.instance)}}const L=(e,t,n)=>new Promise((s=>{const i=e[t];if(i){if(o(i))return void i.bind(e)(n).then((()=>{s()}));s(i.bind(e)(n))}}));function q(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}class N extends O{static build(e){const n=new N;((e,n,s)=>{const i=v(s);i[e]=n;const r=y(i);d(t.AssemblageDefinition,r,s)})("singleton",!0,e);const s=n.register([e]),i=n.require(s.identifier),r=n.initCache.indexOf(i);n.initCache.splice(r,1);for(const t of n.initCache)L(t,"onInit",n.publicContext);return L(i,"onInit",n.publicContext),n.initCache.length=0,i}dispose(){for(const[e,t]of this.injectables)t.dispose();f(this,N)}register(e,t=!1){const n=!0===t?(e=>({identifier:e[0],concrete:e[0],instance:e[1],configuration:{}}))(e):(e=>((e,t)=>(n,...s)=>e[n]?e[n](...s):t?t(n,...s):void 0)({1:()=>(e=>({identifier:e[0],concrete:e[0],configuration:{}}))(e),2:()=>x(e),3:()=>(e=>({identifier:e[0],concrete:e[1],configuration:e[2]}))(e)},(()=>{throw new Error("Injection tuple must be of length 1, 2 or 3.")}))(e.length))(e);if(this.has(n.identifier))throw new Error(`An assemblage is already registered with identifier '${n.identifier.name}'.`);const s=M.of(n,this.privateContext,this.publicContext);return this.injectables.set(s.identifier,s),L(s.concrete,"onRegister",this.publicContext),s}use(e,t){if(this.has(e))throw new Error(`A value is already registered with identifier '${String(e)}'.`);return this.objects.set(e,t),t}prepareInitHook(e){return this.initCache.push(e),this.initCache}has(e){return"string"==typeof e||"symbol"==typeof e?this.objects.has(e):this.injectables.has(e)}require(e){switch(typeof e){case"string":case"symbol":if(!this.objects.has(e))throw new Error(`Injected object with identifier '${String(e)}' has not been registered.`);return this.objects.get(e);default:if(!this.injectables.has(e))throw new Error(`Class with identifier '${e.name}' has not been registered or is a circular dependency.`);return this.injectables.get(e).build()}}tagged(...e){const t=[];for(const n of e)for(const[e,s]of this.injectables)s.tags.includes(n)&&t.push(s.build());return t}get size(){return this.injectables.size}constructor(){super(),q(this,"injectables",new Map),q(this,"objects",new Map),q(this,"initCache",[]),q(this,"privateContext",void 0),q(this,"publicContext",void 0),this.publicContext={has:this.has.bind(this),require:this.require.bind(this),tagged:this.tagged.bind(this),on:this.on.bind(this),once:this.once.bind(this),off:this.off.bind(this),events:this.channels},this.privateContext={...this.publicContext,register:this.register.bind(this),use:this.use.bind(this),prepareInitHook:this.prepareInitHook.bind(this),emit:this.emit.bind(this),addChannels:this.addChannels.bind(this),removeChannels:this.removeChannels.bind(this),dispose:this.dispose.bind(this)}}}exports.AbstractAssemblage=class{static onRegister(e){}},exports.AbstractAssembler=class extends A{},exports.AbstractEventManager=A,exports.Assemblage=n=>{const s=y(n||{});return n=>(d(e.IsAssemblage,!0,n),d(t.AssemblageDefinition,s,n),n)},exports.Assembler=N,exports.Await=(e,t=25)=>(n,s,i)=>{const r=i.value;i.value=async function(){return new Promise((n=>{if(this[e])r.apply(this),n();else{const s=setInterval((()=>{this[e]&&(clearInterval(s),r.apply(this),n())}),t)}}))}},exports.Configuration=S,exports.Context=$,exports.Definition=R,exports.Dispose=U,exports.EventManager=O,exports.ReflectParamIndex=E,exports.ReflectParamValue=P,exports.Use=e=>(t,n,s)=>{const i=p(E.Use,t)||[];i.push(s),d(E.Use,i,t);const r=p(P.UseIdentifier,t)||{};r[s]=e,d(P.UseIdentifier,r,t)},exports.getDecoratedParametersIndexes=_,exports.isAssemblage=b;
|
package/dist/index.mjs
CHANGED
|
@@ -121,7 +121,9 @@ const n = {
|
|
|
121
121
|
throw: ()=>{
|
|
122
122
|
throw new Error(`'singleton' property must be of type 'boolean' or 'undefined'.`);
|
|
123
123
|
},
|
|
124
|
-
transform: (r)=>
|
|
124
|
+
transform: (r)=>{
|
|
125
|
+
return typeof r === 'undefined' ? true : r ? true : false;
|
|
126
|
+
}
|
|
125
127
|
},
|
|
126
128
|
events: {
|
|
127
129
|
test: (r)=>typeof r === 'undefined' || Array.isArray(r) && r.every((r)=>typeof r === 'string'),
|
|
@@ -169,6 +171,8 @@ const validateDefinition = (r)=>{
|
|
|
169
171
|
if (!Object.keys(n).includes(r)) {
|
|
170
172
|
throw new Error(`Property '${r}' is not a valid assemblage definition property.`);
|
|
171
173
|
}
|
|
174
|
+
}
|
|
175
|
+
for(const r in n){
|
|
172
176
|
const e = n[r].test;
|
|
173
177
|
const o = n[r].throw;
|
|
174
178
|
const s = n[r].transform;
|
|
@@ -254,7 +258,7 @@ const resolveInstanceInjectionTuple = (e)=>{
|
|
|
254
258
|
};
|
|
255
259
|
|
|
256
260
|
const Assemblage = (m)=>{
|
|
257
|
-
const n = m ? validateDefinition(m) : {};
|
|
261
|
+
const n = m ? validateDefinition(m) : validateDefinition({});
|
|
258
262
|
return (t)=>{
|
|
259
263
|
defineCustomMetadata(ReflectFlags.IsAssemblage, true, t);
|
|
260
264
|
defineCustomMetadata(ReflectValue.AssemblageDefinition, n, t);
|
|
@@ -262,149 +266,7 @@ const Assemblage = (m)=>{
|
|
|
262
266
|
};
|
|
263
267
|
};
|
|
264
268
|
|
|
265
|
-
|
|
266
|
-
return (n, s, a)=>{
|
|
267
|
-
const i = a.value;
|
|
268
|
-
a.value = async function() {
|
|
269
|
-
return new Promise((n)=>{
|
|
270
|
-
if (this[t]) {
|
|
271
|
-
i.apply(this);
|
|
272
|
-
n();
|
|
273
|
-
} else {
|
|
274
|
-
const s = setInterval(()=>{
|
|
275
|
-
if (this[t]) {
|
|
276
|
-
clearInterval(s);
|
|
277
|
-
i.apply(this);
|
|
278
|
-
n();
|
|
279
|
-
}
|
|
280
|
-
}, e);
|
|
281
|
-
}
|
|
282
|
-
});
|
|
283
|
-
};
|
|
284
|
-
};
|
|
285
|
-
};
|
|
286
|
-
|
|
287
|
-
var ReflectParamValue = /*#__PURE__*/ function(e) {
|
|
288
|
-
e["UseIdentifier"] = "assemblage:use.param.value";
|
|
289
|
-
return e;
|
|
290
|
-
}({});
|
|
291
|
-
var ReflectParamIndex = /*#__PURE__*/ function(e) {
|
|
292
|
-
e["Context"] = "assembler:context.param.index";
|
|
293
|
-
e["Dispose"] = "assembler:dispose.param.index";
|
|
294
|
-
e["Definition"] = "assemblage:definition.param.index";
|
|
295
|
-
e["Configuration"] = "assemblage:configuration.param.index";
|
|
296
|
-
e["Use"] = "assemblage:use.param.index";
|
|
297
|
-
return e;
|
|
298
|
-
}({});
|
|
299
|
-
|
|
300
|
-
const i = (t)=>()=>{
|
|
301
|
-
return (i, s, r)=>{
|
|
302
|
-
const c = getOwnCustomMetadata(t, i) || [];
|
|
303
|
-
c.push(r);
|
|
304
|
-
defineCustomMetadata(t, c, i);
|
|
305
|
-
};
|
|
306
|
-
};
|
|
307
|
-
const s$1 = i(ReflectParamIndex.Context);
|
|
308
|
-
const r$1 = i(ReflectParamIndex.Configuration);
|
|
309
|
-
const c$1 = i(ReflectParamIndex.Definition);
|
|
310
|
-
const e$4 = i(ReflectParamIndex.Dispose);
|
|
311
|
-
|
|
312
|
-
const Use = (n)=>{
|
|
313
|
-
return (r, i, m)=>{
|
|
314
|
-
const c = getOwnCustomMetadata(ReflectParamIndex.Use, r) || [];
|
|
315
|
-
c.push(m);
|
|
316
|
-
defineCustomMetadata(ReflectParamIndex.Use, c, r);
|
|
317
|
-
const U = getOwnCustomMetadata(ReflectParamValue.UseIdentifier, r) || {};
|
|
318
|
-
U[m] = n;
|
|
319
|
-
defineCustomMetadata(ReflectParamValue.UseIdentifier, U, r);
|
|
320
|
-
};
|
|
321
|
-
};
|
|
322
|
-
|
|
323
|
-
const o = (o)=>{
|
|
324
|
-
return getOwnCustomMetadata(ReflectParamIndex.Context, o) || [];
|
|
325
|
-
};
|
|
326
|
-
const r = (o)=>{
|
|
327
|
-
return getOwnCustomMetadata(ReflectParamIndex.Configuration, o) || [];
|
|
328
|
-
};
|
|
329
|
-
const e$3 = (o)=>{
|
|
330
|
-
return getOwnCustomMetadata(ReflectParamIndex.Definition, o) || [];
|
|
331
|
-
};
|
|
332
|
-
const s = (o)=>{
|
|
333
|
-
return getOwnCustomMetadata(ReflectParamIndex.Dispose, o) || [];
|
|
334
|
-
};
|
|
335
|
-
const c = (o)=>{
|
|
336
|
-
return getOwnCustomMetadata(ReflectParamIndex.Use, o) || [];
|
|
337
|
-
};
|
|
338
|
-
const getDecoratedParametersIndexes = (t)=>{
|
|
339
|
-
const n = o(t);
|
|
340
|
-
const i = e$3(t);
|
|
341
|
-
const a = r(t);
|
|
342
|
-
const u = s(t);
|
|
343
|
-
const m = c(t);
|
|
344
|
-
return {
|
|
345
|
-
context: n,
|
|
346
|
-
definition: i,
|
|
347
|
-
configuration: a,
|
|
348
|
-
dispose: u,
|
|
349
|
-
use: m
|
|
350
|
-
};
|
|
351
|
-
};
|
|
352
|
-
|
|
353
|
-
const resolveParameters = (i)=>{
|
|
354
|
-
const c = [];
|
|
355
|
-
const s = getParamTypes(i.concrete);
|
|
356
|
-
const u = getDecoratedParametersIndexes(i.concrete);
|
|
357
|
-
let r = 0;
|
|
358
|
-
for (const n of s){
|
|
359
|
-
if (u.context.includes(r)) {
|
|
360
|
-
c.push(i.publicContext);
|
|
361
|
-
r++;
|
|
362
|
-
continue;
|
|
363
|
-
}
|
|
364
|
-
if (u.configuration.includes(r)) {
|
|
365
|
-
c.push(i.configuration);
|
|
366
|
-
r++;
|
|
367
|
-
continue;
|
|
368
|
-
}
|
|
369
|
-
if (u.definition.includes(r)) {
|
|
370
|
-
c.push(i.definition);
|
|
371
|
-
r++;
|
|
372
|
-
continue;
|
|
373
|
-
}
|
|
374
|
-
if (u.dispose.includes(r)) {
|
|
375
|
-
c.push(i.privateContext.dispose);
|
|
376
|
-
r++;
|
|
377
|
-
continue;
|
|
378
|
-
}
|
|
379
|
-
if (u.use.includes(r)) {
|
|
380
|
-
const n = getOwnCustomMetadata(ReflectParamValue.UseIdentifier, i.concrete);
|
|
381
|
-
const t = n[r];
|
|
382
|
-
c.push(i.privateContext.require(t));
|
|
383
|
-
r++;
|
|
384
|
-
continue;
|
|
385
|
-
}
|
|
386
|
-
c.push(i.privateContext.require(n));
|
|
387
|
-
r++;
|
|
388
|
-
}
|
|
389
|
-
return c;
|
|
390
|
-
};
|
|
391
|
-
const resolveDependencies = (e)=>{
|
|
392
|
-
const o = [];
|
|
393
|
-
const i = getParamTypes(e);
|
|
394
|
-
const c = getDecoratedParametersIndexes(e);
|
|
395
|
-
let s = 0;
|
|
396
|
-
for (const e of i){
|
|
397
|
-
if (c.context.includes(s) || c.configuration.includes(s) || c.definition.includes(s) || c.dispose.includes(s) || c.use.includes(s)) {
|
|
398
|
-
s++;
|
|
399
|
-
continue;
|
|
400
|
-
}
|
|
401
|
-
o.push(e);
|
|
402
|
-
s++;
|
|
403
|
-
}
|
|
404
|
-
return o;
|
|
405
|
-
};
|
|
406
|
-
|
|
407
|
-
function e$2(e, t, n) {
|
|
269
|
+
function e$4(e, t, n) {
|
|
408
270
|
if (t in e) {
|
|
409
271
|
Object.defineProperty(e, t, {
|
|
410
272
|
value: n,
|
|
@@ -513,7 +375,7 @@ class ListenerCollection {
|
|
|
513
375
|
};
|
|
514
376
|
}
|
|
515
377
|
constructor(){
|
|
516
|
-
e$
|
|
378
|
+
e$4(this, "collection", {});
|
|
517
379
|
const t = proxifyIterable(this, ListenerCollection);
|
|
518
380
|
return t;
|
|
519
381
|
}
|
|
@@ -522,7 +384,7 @@ class ListenerCollection {
|
|
|
522
384
|
class AbstractEventManager {
|
|
523
385
|
}
|
|
524
386
|
|
|
525
|
-
function e$
|
|
387
|
+
function e$3(e, n, s) {
|
|
526
388
|
if (n in e) {
|
|
527
389
|
Object.defineProperty(e, n, {
|
|
528
390
|
value: s,
|
|
@@ -624,9 +486,9 @@ class EventManager {
|
|
|
624
486
|
return onlyAlphanumeric(e, '*');
|
|
625
487
|
}
|
|
626
488
|
constructor(...n){
|
|
627
|
-
e$
|
|
628
|
-
e$
|
|
629
|
-
e$
|
|
489
|
+
e$3(this, "listeners", new ListenerCollection());
|
|
490
|
+
e$3(this, "onceListeners", new ListenerCollection());
|
|
491
|
+
e$3(this, "channels", new Set([
|
|
630
492
|
'*'
|
|
631
493
|
]));
|
|
632
494
|
this.addChannels(...n);
|
|
@@ -661,6 +523,148 @@ const unregisterEvents = (t, n)=>{
|
|
|
661
523
|
}
|
|
662
524
|
};
|
|
663
525
|
|
|
526
|
+
const Await = (t, e = 25)=>{
|
|
527
|
+
return (n, s, a)=>{
|
|
528
|
+
const i = a.value;
|
|
529
|
+
a.value = async function() {
|
|
530
|
+
return new Promise((n)=>{
|
|
531
|
+
if (this[t]) {
|
|
532
|
+
i.apply(this);
|
|
533
|
+
n();
|
|
534
|
+
} else {
|
|
535
|
+
const s = setInterval(()=>{
|
|
536
|
+
if (this[t]) {
|
|
537
|
+
clearInterval(s);
|
|
538
|
+
i.apply(this);
|
|
539
|
+
n();
|
|
540
|
+
}
|
|
541
|
+
}, e);
|
|
542
|
+
}
|
|
543
|
+
});
|
|
544
|
+
};
|
|
545
|
+
};
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
var ReflectParamValue = /*#__PURE__*/ function(e) {
|
|
549
|
+
e["UseIdentifier"] = "assemblage:use.param.value";
|
|
550
|
+
return e;
|
|
551
|
+
}({});
|
|
552
|
+
var ReflectParamIndex = /*#__PURE__*/ function(e) {
|
|
553
|
+
e["Context"] = "assembler:context.param.index";
|
|
554
|
+
e["Dispose"] = "assembler:dispose.param.index";
|
|
555
|
+
e["Definition"] = "assemblage:definition.param.index";
|
|
556
|
+
e["Configuration"] = "assemblage:configuration.param.index";
|
|
557
|
+
e["Use"] = "assemblage:use.param.index";
|
|
558
|
+
return e;
|
|
559
|
+
}({});
|
|
560
|
+
|
|
561
|
+
const i = (t)=>()=>{
|
|
562
|
+
return (i, s, r)=>{
|
|
563
|
+
const c = getOwnCustomMetadata(t, i) || [];
|
|
564
|
+
c.push(r);
|
|
565
|
+
defineCustomMetadata(t, c, i);
|
|
566
|
+
};
|
|
567
|
+
};
|
|
568
|
+
const s$1 = i(ReflectParamIndex.Context);
|
|
569
|
+
const r$1 = i(ReflectParamIndex.Configuration);
|
|
570
|
+
const c$1 = i(ReflectParamIndex.Definition);
|
|
571
|
+
const e$2 = i(ReflectParamIndex.Dispose);
|
|
572
|
+
|
|
573
|
+
const Use = (n)=>{
|
|
574
|
+
return (r, i, m)=>{
|
|
575
|
+
const c = getOwnCustomMetadata(ReflectParamIndex.Use, r) || [];
|
|
576
|
+
c.push(m);
|
|
577
|
+
defineCustomMetadata(ReflectParamIndex.Use, c, r);
|
|
578
|
+
const U = getOwnCustomMetadata(ReflectParamValue.UseIdentifier, r) || {};
|
|
579
|
+
U[m] = n;
|
|
580
|
+
defineCustomMetadata(ReflectParamValue.UseIdentifier, U, r);
|
|
581
|
+
};
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
const o = (o)=>{
|
|
585
|
+
return getOwnCustomMetadata(ReflectParamIndex.Context, o) || [];
|
|
586
|
+
};
|
|
587
|
+
const r = (o)=>{
|
|
588
|
+
return getOwnCustomMetadata(ReflectParamIndex.Configuration, o) || [];
|
|
589
|
+
};
|
|
590
|
+
const e$1 = (o)=>{
|
|
591
|
+
return getOwnCustomMetadata(ReflectParamIndex.Definition, o) || [];
|
|
592
|
+
};
|
|
593
|
+
const s = (o)=>{
|
|
594
|
+
return getOwnCustomMetadata(ReflectParamIndex.Dispose, o) || [];
|
|
595
|
+
};
|
|
596
|
+
const c = (o)=>{
|
|
597
|
+
return getOwnCustomMetadata(ReflectParamIndex.Use, o) || [];
|
|
598
|
+
};
|
|
599
|
+
const getDecoratedParametersIndexes = (t)=>{
|
|
600
|
+
const n = o(t);
|
|
601
|
+
const i = e$1(t);
|
|
602
|
+
const m = r(t);
|
|
603
|
+
const u = s(t);
|
|
604
|
+
const a = c(t);
|
|
605
|
+
return {
|
|
606
|
+
context: n,
|
|
607
|
+
definition: i,
|
|
608
|
+
configuration: m,
|
|
609
|
+
dispose: u,
|
|
610
|
+
use: a
|
|
611
|
+
};
|
|
612
|
+
};
|
|
613
|
+
|
|
614
|
+
const resolveParameters = (i)=>{
|
|
615
|
+
const c = [];
|
|
616
|
+
const s = getParamTypes(i.concrete);
|
|
617
|
+
const u = getDecoratedParametersIndexes(i.concrete);
|
|
618
|
+
let r = 0;
|
|
619
|
+
for (const n of s){
|
|
620
|
+
if (u.context.includes(r)) {
|
|
621
|
+
c.push(i.publicContext);
|
|
622
|
+
r++;
|
|
623
|
+
continue;
|
|
624
|
+
}
|
|
625
|
+
if (u.configuration.includes(r)) {
|
|
626
|
+
c.push(i.configuration);
|
|
627
|
+
r++;
|
|
628
|
+
continue;
|
|
629
|
+
}
|
|
630
|
+
if (u.definition.includes(r)) {
|
|
631
|
+
c.push(i.definition);
|
|
632
|
+
r++;
|
|
633
|
+
continue;
|
|
634
|
+
}
|
|
635
|
+
if (u.dispose.includes(r)) {
|
|
636
|
+
c.push(i.privateContext.dispose);
|
|
637
|
+
r++;
|
|
638
|
+
continue;
|
|
639
|
+
}
|
|
640
|
+
if (u.use.includes(r)) {
|
|
641
|
+
const n = getOwnCustomMetadata(ReflectParamValue.UseIdentifier, i.concrete);
|
|
642
|
+
const t = n[r];
|
|
643
|
+
c.push(i.privateContext.require(t));
|
|
644
|
+
r++;
|
|
645
|
+
continue;
|
|
646
|
+
}
|
|
647
|
+
c.push(i.privateContext.require(n));
|
|
648
|
+
r++;
|
|
649
|
+
}
|
|
650
|
+
return c;
|
|
651
|
+
};
|
|
652
|
+
const resolveDependencies = (e)=>{
|
|
653
|
+
const o = [];
|
|
654
|
+
const i = getParamTypes(e);
|
|
655
|
+
const c = getDecoratedParametersIndexes(e);
|
|
656
|
+
let s = 0;
|
|
657
|
+
for (const e of i){
|
|
658
|
+
if (c.context.includes(s) || c.configuration.includes(s) || c.definition.includes(s) || c.dispose.includes(s) || c.use.includes(s)) {
|
|
659
|
+
s++;
|
|
660
|
+
continue;
|
|
661
|
+
}
|
|
662
|
+
o.push(e);
|
|
663
|
+
s++;
|
|
664
|
+
}
|
|
665
|
+
return o;
|
|
666
|
+
};
|
|
667
|
+
|
|
664
668
|
function t(t, e, n) {
|
|
665
669
|
if (e in t) {
|
|
666
670
|
Object.defineProperty(t, e, {
|
|
@@ -706,7 +710,7 @@ class Injectable {
|
|
|
706
710
|
return getDefinition(this.concrete) || {};
|
|
707
711
|
}
|
|
708
712
|
get isSingleton() {
|
|
709
|
-
return getDefinitionValue('singleton', this.concrete)
|
|
713
|
+
return getDefinitionValue('singleton', this.concrete);
|
|
710
714
|
}
|
|
711
715
|
get singleton() {
|
|
712
716
|
return this.singletonInstance;
|
|
@@ -894,4 +898,4 @@ class Assembler extends EventManager {
|
|
|
894
898
|
class AbstractAssembler extends AbstractEventManager {
|
|
895
899
|
}
|
|
896
900
|
|
|
897
|
-
export { AbstractAssemblage, AbstractAssembler, AbstractEventManager, Assemblage, Assembler, Await, r$1 as Configuration, s$1 as Context, c$1 as Definition, e$
|
|
901
|
+
export { AbstractAssemblage, AbstractAssembler, AbstractEventManager, Assemblage, Assembler, Await, r$1 as Configuration, s$1 as Context, c$1 as Definition, e$2 as Dispose, EventManager, ReflectParamIndex, ReflectParamValue, Use, getDecoratedParametersIndexes, isAssemblage };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "assemblerjs",
|
|
3
3
|
"description": "A general purpose and zero-dependency Dependency Injection library for node and browser.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.5.0",
|
|
5
5
|
"author": "Benoît LAHOZ <info@benoitlahoz.io>",
|
|
6
6
|
"bugs": "https://github.com/benoitlahoz/assemblerjs/issues",
|
|
7
7
|
"devDependencies": {
|