@teqfw/di 0.32.0 → 0.33.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/RELEASE.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @teqfw/di releases
2
2
 
3
+ ## 0.33.0 – Cleanup and Enhancements
4
+
5
+ - Removed deprecated documentation.
6
+ - Updated ESLint rules for consistency with current platform practices.
7
+ - Introduced `#` as a separator (in addition to `.`) between namespace and export names.
8
+
3
9
  ## 0.32.0 - added support for the `node:` prefix
4
10
 
5
11
  - **Added ability** to manually register objects in the container (`register`).
@@ -78,6 +84,6 @@
78
84
  ## 0.8.0
79
85
 
80
86
  * docs for plugin's teq-descriptor (see in `main` branch);
81
- * use object notation instead of array notation in namespace replacement statements of teq-descriptor (
82
- `@teqfw/di.replace` node format is changed in `./teqfw.json`);
87
+ * use object notation instead of array notation in namespace replacement statements of
88
+ teq-descriptor (`@teqfw/di.replace` node format is changed in `./teqfw.json`);
83
89
  * array is used as a container for upline dependencies in the 'SpecProxy' (object was);
@@ -9,5 +9,6 @@ rm -fr "${DIR_ROOT}/doc/"
9
9
  rm -fr "${DIR_ROOT}/docs/"
10
10
  rm -fr "${DIR_ROOT}/example/"
11
11
  rm -fr "${DIR_ROOT}/node_modules/"
12
+ rm -fr "${DIR_ROOT}/package-lock.json"
12
13
  rm -fr "${DIR_ROOT}/test/"
13
14
  rm -fr "${DIR_ROOT}/tmp/"
package/dist/esm.js CHANGED
@@ -1 +1 @@
1
- var e={COMP_A:"A",COMP_F:"F",ID:"container",ID_FQN:"TeqFw_Di_Container$",LIFE_I:"I",LIFE_S:"S",isClass(e){const t=Object.getOwnPropertyDescriptor(e,"prototype");return t&&!t.writable}};const t=/(function)*\s*\w*\s*\(\s*\{([^\}]*)\}/s,o=/constructor\s*\(\s*\{([^\}]*)\}/s;function s(e){const t=[];try{const o=new Function(`{${e}}`,"return");o(new Proxy({},{get:(e,o)=>t.push(o)}))}catch(t){throw new Error(`Cannot analyze the deps specification:${e}\n\nPlease, be sure that spec does not contain extra ')' in a comments.\n\nError: ${t}`)}return t}function n(n){return"function"==typeof n?e.isClass(n)?function(e){const t=[],n=e.toString(),r=o.exec(n);return r&&t.push(...s(r[1])),t}(n):function(e){const o=[],n=e.toString(),r=t.exec(n);return r&&o.push(...s(r[2])),o}(n):[]}class r{constructor(){let t=!1;this.create=async function(o,s,r,i){if(r.includes(o.value))throw new Error(`Circular dependency for '${o.value}'. Parents are: ${JSON.stringify(r)}`);if(o.exportName){const a=[...r,o.value],{[o.exportName]:u}=s;if(o.composition===e.COMP_F){if("function"==typeof u){const s=n(u);s.length&&(c=`Deps for object '${o.value}' are: ${JSON.stringify(s)}`,t&&console.log(c));const r={};for(const e of s)r[e]=await i.compose(e,a);const l=e.isClass(u)?new u(r):u(r);return l instanceof Promise?await l:l}return Object.assign({},u)}return u}return s;var c},this.setDebug=function(e){t=e}}}class i{exportName;composition;life;moduleName;value;wrappers=[]}const c=/^((([A-Z])[A-Za-z0-9_]*)((\.)?([A-Za-z0-9_]*)((\$)?(\$)?)?)?(\(([A-Za-z0-9_,]*)\))?)$/;class a{canParse(e){return!0}parse(t){const o=new i;o.value=t;const s=c.exec(t);if(s&&(o.moduleName=s[2],"."===s[5]?"$"===s[7]||"$$"===s[7]?(o.composition=e.COMP_F,o.exportName=s[6],o.life="$"===s[7]?e.LIFE_S:e.LIFE_I):(o.composition=e.COMP_A,o.life=e.LIFE_S,o.exportName=""!==s[6]?s[6]:"default"):"$"===s[7]||"$$"===s[7]?(o.composition=e.COMP_F,o.exportName="default",o.life="$"===s[7]?e.LIFE_S:e.LIFE_I):(o.composition=void 0,o.exportName=void 0,o.life=void 0),s[11]&&(o.wrappers=s[11].split(","))),o.composition===e.COMP_A&&o.life===e.LIFE_I)throw new Error(`Export is not a function and should be used as a singleton only: '${o.value}'.`);return o}}class u{constructor(){let e=new a;const t=[];this.addChunk=function(e){t.push(e)},this.parse=function(o){let s;for(const e of t)if(e.canParse(o)){s=e.parse(o);break}return s||(s=e?.parse(o)),s},this.setDefaultChunk=function(t){e=t}}}class l{constructor(){const e=[];this.addChunk=function(t){e.push(t)},this.modify=function(t,o){let s=t;for(const n of e)s=n.modify(s,t,o);return s}}}class f{constructor(){const e=[];this.addChunk=function(t){e.push(t)},this.modify=async function(t,o,s){let n=t;for(const t of e)n=t.modify(n,o,s),n instanceof Promise&&(n=await n);return n}}}const p="root";class m{constructor(){const e={};let t=!1,o=[],s="/";this.addNamespaceRoot=function(s,n,r){const i=(t?n.replace(/^\\/,""):n).replace(/\\/g,"/"),c=t?`file://${i}`:i;e[s]={ext:r??"js",ns:s,[p]:c},o=Object.keys(e).sort(((e,t)=>t.localeCompare(e)))},this.resolve=function(t){let n,r,i;for(i of o)if(t.startsWith(i)){n=e[i][p],r=e[i].ext;break}if(n&&r){let e=t.replace(i,"");0===e.indexOf("_")&&(e=e.replace("_",""));const o=e.replaceAll("_",s);return`${n}${s}${o}.${r}`}return t},this.setWindowsEnv=function(e=!0){t=e,s=e?"\\":"/"}}}function d(e){return`${e.moduleName}#${e.exportName}`}class h{constructor(){let t=new r,o=!1,s=new u,n=new l,i=new f;const c={},a={};let p=new m;function h(){o&&console.log(...arguments)}this.get=async function(e,t=[]){return this.compose(e,t)},this.compose=async function(o,r=[]){if(h(`Object '${o}' is requested.`),o===e.ID||o===e.ID_FQN)return h("Container itself is returned."),a[e.ID];const u=s.parse(o),l=n.modify(u,r);if(l.life===e.LIFE_S){const e=d(l);if(a[e])return h(`Existing singleton '${e}' is returned.`),a[e]}let f;c[l.moduleName]||(h(`ES6 module '${l.moduleName}' is not resolved yet`),c[l.moduleName]=p.resolve(l.moduleName));const m=c[l.moduleName];try{f=await import(m),h(`ES6 module '${l.moduleName}' is loaded from '${m}'.`)}catch(e){throw console.error(e?.message,`Object key: "${o}".`,`Path: "${m}".`,`Stack: ${JSON.stringify(r)}`),e}let $=await t.create(l,f,r,this);if($=await i.modify($,l,r),h(`Object '${o}' is created.`),l.life===e.LIFE_S){const e=d(l);a[e]=$,h(`Object '${o}' is saved as singleton.`)}return $},this.getParser=()=>s,this.getPreProcessor=()=>n,this.getPostProcessor=()=>i,this.getResolver=()=>p,this.setDebug=function(e){o=e,t.setDebug(e)},this.setParser=e=>s=e,this.setPreProcessor=e=>n=e,this.setPostProcessor=e=>i=e,this.setResolver=e=>p=e,a[e.ID]=this}}export{h as default};
1
+ var e={CA:"A",CF:"F",ID:"container",ID_FQN:"TeqFw_Di_Container$",LI:"I",LS:"S",isClass(e){const t=Object.getOwnPropertyDescriptor(e,"prototype");return t&&!t.writable}};const t=/(function)*\s*\w*\s*\(\s*\{([^}]*)}/s,o=/constructor\s*\(\s*\{([^}]*)}/s;function n(e){const t=[];try{const o=new Function(`{${e}}`,"return");o(new Proxy({},{get:(e,o)=>t.push(o)}))}catch(t){throw new Error(`Cannot analyze the deps specification:${e}\n\nPlease, be sure that spec does not contain extra ')' in a comments.\n\nError: ${t}`)}return t}function s(s){return"function"==typeof s?e.isClass(s)?function(e){const t=[],s=e.toString(),r=o.exec(s);return r&&t.push(...n(r[1])),t}(s):function(e){const o=[],s=e.toString(),r=t.exec(s);return r&&o.push(...n(r[2])),o}(s):[]}class r{constructor(){let t=!1;this.create=async function(o,n,r,i){if(r.includes(o.origin))throw new Error(`Circular dependency for '${o.origin}'. Parents are: ${JSON.stringify(r)}`);if(o.exportName){const a=[...r,o.origin],{[o.exportName]:u}=n;if(o.composition===e.CF){if("function"==typeof u){const n=s(u);n.length&&(c=`Deps for object '${o.origin}' are: ${JSON.stringify(n)}`,t&&console.log(c));const r={};for(const e of n)r[e]=await i.compose(e,a);const l=e.isClass(u)?new u(r):u(r);return l instanceof Promise?await l:l}return Object.assign({},u)}return u}return n;var c},this.setDebug=function(e){t=e}}}class i{exportName;composition;life;moduleName;origin;wrappers=[]}const c=/^(node:)?(@?[A-Za-z0-9_-]+\/?[A-Za-z0-9_-]*)(([.#])?([A-Za-z0-9_]*)((\$)?(\$)?)?)?(\(([A-Za-z0-9_,]*)\))?$/;class a{canParse(){return!0}parse(t){const o=new i;o.origin=t;const n=c.exec(t);if(n&&(o.isNodeModule=Boolean(n[1]),o.moduleName=n[2].replace(/^node:/,""),"."===n[4]||"#"===n[4]?"$"===n[6]||"$$"===n[6]?(o.composition=e.CF,o.exportName=n[5],o.life="$"===n[6]?e.LS:e.LI):(o.composition=e.CA,o.life=e.LS,o.exportName=""!==n[5]?n[5]:"default"):"$"===n[6]||"$$"===n[6]?(o.composition=e.CF,o.exportName="default",o.life="$"===n[6]?e.LS:e.LI):(o.composition=void 0,o.exportName=void 0,o.life=void 0),n[10]&&(o.wrappers=n[10].split(","))),o.composition===e.CA&&o.life===e.LI)throw new Error(`Export is not a function and should be used as a singleton only: '${o.origin}'.`);return o}}class u{constructor(){let e=new a;const t=[];this.addChunk=function(e){t.push(e)},this.parse=function(o){let n;for(const e of t)if(e.canParse(o)){n=e.parse(o);break}return n||(n=e?.parse(o)),n},this.setDefaultChunk=function(t){e=t}}}class l{constructor(){const e=[];this.addChunk=function(t){e.push(t)},this.modify=function(t,o){let n=t;for(const s of e)n=s.modify(n,t,o);return n}}}class f{constructor(){const e=[];this.addChunk=function(t){e.push(t)},this.modify=async function(t,o,n){let s=t;for(const t of e)s=t.modify(s,o,n),s instanceof Promise&&(s=await s);return s}}}const p="root";class d{constructor(){const e={};let t=!1,o=[],n="/";this.addNamespaceRoot=function(n,s,r){const i=(t?s.replace(/^\\/,""):s).replace(/\\/g,"/"),c=t?`file://${i}`:i;e[n]={ext:r??"js",ns:n,[p]:c},o=Object.keys(e).sort(((e,t)=>t.localeCompare(e)))},this.resolve=function(t){let s,r,i;for(i of o)if(t.startsWith(i)){s=e[i][p],r=e[i].ext;break}if(s&&r){let e=t.replace(i,"");0===e.indexOf("_")&&(e=e.replace("_",""));const o=e.replaceAll("_",n);return`${s}${n}${o}.${r}`}return t},this.setWindowsEnv=function(e=!0){t=e,n=e?"\\":"/"}}}function m(e){return`${e.moduleName}#${e.exportName}`}class h{constructor(){let t=new r,o=!1,n=new u,s=new l,i=new f;const c={},a={};let p=new d;function h(){o&&console.log(...arguments)}this.get=async function(e,t=[]){return this.compose(e,t)},this.compose=async function(o,r=[]){if(h(`Object '${o}' is requested.`),o===e.ID||o===e.ID_FQN)return h("Container itself is returned."),a[e.ID];const u=n.parse(o),l=s.modify(u,r);if(l.life===e.LS){const e=m(l);if(a[e])return h(`Existing singleton '${e}' is returned.`),a[e]}let f;c[l.moduleName]||(h(`ES6 module '${l.moduleName}' is not resolved yet`),c[l.moduleName]=p.resolve(l.moduleName));const d=c[l.moduleName];try{f=await import(d),h(`ES6 module '${l.moduleName}' is loaded from '${d}'.`)}catch(e){throw console.error(e?.message,`Object key: "${o}".`,`Path: "${d}".`,`Stack: ${JSON.stringify(r)}`),e}let $=await t.create(l,f,r,this);var g;if(null===(g=$)||"object"!=typeof g&&"function"!=typeof g||"[object Module]"===Object.prototype.toString.call(g)||Object.isFrozen(g)||Object.freeze($),$=await i.modify($,l,r),h(`Object '${o}' is created.`),l.life===e.LS){const e=m(l);a[e]=$,h(`Object '${o}' is saved as singleton.`)}return $},this.getParser=()=>n,this.getPreProcessor=()=>s,this.getPostProcessor=()=>i,this.getResolver=()=>p,this.register=function(t,o){if(!t||!o)throw new Error("depId and object are required");const s=n.parse(t);if(s.life!==e.LS)throw new Error(`Only singletons can be registered manually. Given: ${t}`);{const e=m(s);a[e]=o,h(`Object '${t}' is registered manually as singleton.`)}},this.setDebug=function(e){o=e,t.setDebug(e)},this.setParser=e=>n=e,this.setPreProcessor=e=>s=e,this.setPostProcessor=e=>i=e,this.setResolver=e=>p=e,a[e.ID]=this}}export{h as default};
package/dist/umd.js CHANGED
@@ -1 +1 @@
1
- !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).TeqFw_Di_Container=t()}(this,(function(){"use strict";var e={COMP_A:"A",COMP_F:"F",ID:"container",ID_FQN:"TeqFw_Di_Container$",LIFE_I:"I",LIFE_S:"S",isClass(e){const t=Object.getOwnPropertyDescriptor(e,"prototype");return t&&!t.writable}};const t=/(function)*\s*\w*\s*\(\s*\{([^\}]*)\}/s,o=/constructor\s*\(\s*\{([^\}]*)\}/s;function n(e){const t=[];try{const o=new Function(`{${e}}`,"return");o(new Proxy({},{get:(e,o)=>t.push(o)}))}catch(t){throw new Error(`Cannot analyze the deps specification:${e}\n\nPlease, be sure that spec does not contain extra ')' in a comments.\n\nError: ${t}`)}return t}function s(s){return"function"==typeof s?e.isClass(s)?function(e){const t=[],s=e.toString(),r=o.exec(s);return r&&t.push(...n(r[1])),t}(s):function(e){const o=[],s=e.toString(),r=t.exec(s);return r&&o.push(...n(r[2])),o}(s):[]}class r{constructor(){let t=!1;this.create=async function(o,n,r,i){if(r.includes(o.value))throw new Error(`Circular dependency for '${o.value}'. Parents are: ${JSON.stringify(r)}`);if(o.exportName){const a=[...r,o.value],{[o.exportName]:u}=n;if(o.composition===e.COMP_F){if("function"==typeof u){const n=s(u);n.length&&(c=`Deps for object '${o.value}' are: ${JSON.stringify(n)}`,t&&console.log(c));const r={};for(const e of n)r[e]=await i.compose(e,a);const l=e.isClass(u)?new u(r):u(r);return l instanceof Promise?await l:l}return Object.assign({},u)}return u}return n;var c},this.setDebug=function(e){t=e}}}class i{exportName;composition;life;moduleName;value;wrappers=[]}const c=/^((([A-Z])[A-Za-z0-9_]*)((\.)?([A-Za-z0-9_]*)((\$)?(\$)?)?)?(\(([A-Za-z0-9_,]*)\))?)$/;class a{canParse(e){return!0}parse(t){const o=new i;o.value=t;const n=c.exec(t);if(n&&(o.moduleName=n[2],"."===n[5]?"$"===n[7]||"$$"===n[7]?(o.composition=e.COMP_F,o.exportName=n[6],o.life="$"===n[7]?e.LIFE_S:e.LIFE_I):(o.composition=e.COMP_A,o.life=e.LIFE_S,o.exportName=""!==n[6]?n[6]:"default"):"$"===n[7]||"$$"===n[7]?(o.composition=e.COMP_F,o.exportName="default",o.life="$"===n[7]?e.LIFE_S:e.LIFE_I):(o.composition=void 0,o.exportName=void 0,o.life=void 0),n[11]&&(o.wrappers=n[11].split(","))),o.composition===e.COMP_A&&o.life===e.LIFE_I)throw new Error(`Export is not a function and should be used as a singleton only: '${o.value}'.`);return o}}class u{constructor(){let e=new a;const t=[];this.addChunk=function(e){t.push(e)},this.parse=function(o){let n;for(const e of t)if(e.canParse(o)){n=e.parse(o);break}return n||(n=e?.parse(o)),n},this.setDefaultChunk=function(t){e=t}}}class l{constructor(){const e=[];this.addChunk=function(t){e.push(t)},this.modify=function(t,o){let n=t;for(const s of e)n=s.modify(n,t,o);return n}}}class f{constructor(){const e=[];this.addChunk=function(t){e.push(t)},this.modify=async function(t,o,n){let s=t;for(const t of e)s=t.modify(s,o,n),s instanceof Promise&&(s=await s);return s}}}const p="root";class d{constructor(){const e={};let t=!1,o=[],n="/";this.addNamespaceRoot=function(n,s,r){const i=(t?s.replace(/^\\/,""):s).replace(/\\/g,"/"),c=t?`file://${i}`:i;e[n]={ext:r??"js",ns:n,[p]:c},o=Object.keys(e).sort(((e,t)=>t.localeCompare(e)))},this.resolve=function(t){let s,r,i;for(i of o)if(t.startsWith(i)){s=e[i][p],r=e[i].ext;break}if(s&&r){let e=t.replace(i,"");0===e.indexOf("_")&&(e=e.replace("_",""));const o=e.replaceAll("_",n);return`${s}${n}${o}.${r}`}return t},this.setWindowsEnv=function(e=!0){t=e,n=e?"\\":"/"}}}function m(e){return`${e.moduleName}#${e.exportName}`}return class{constructor(){let t=new r,o=!1,n=new u,s=new l,i=new f;const c={},a={};let p=new d;function h(){o&&console.log(...arguments)}this.get=async function(e,t=[]){return this.compose(e,t)},this.compose=async function(o,r=[]){if(h(`Object '${o}' is requested.`),o===e.ID||o===e.ID_FQN)return h("Container itself is returned."),a[e.ID];const u=n.parse(o),l=s.modify(u,r);if(l.life===e.LIFE_S){const e=m(l);if(a[e])return h(`Existing singleton '${e}' is returned.`),a[e]}let f;c[l.moduleName]||(h(`ES6 module '${l.moduleName}' is not resolved yet`),c[l.moduleName]=p.resolve(l.moduleName));const d=c[l.moduleName];try{f=await import(d),h(`ES6 module '${l.moduleName}' is loaded from '${d}'.`)}catch(e){throw console.error(e?.message,`Object key: "${o}".`,`Path: "${d}".`,`Stack: ${JSON.stringify(r)}`),e}let $=await t.create(l,f,r,this);if($=await i.modify($,l,r),h(`Object '${o}' is created.`),l.life===e.LIFE_S){const e=m(l);a[e]=$,h(`Object '${o}' is saved as singleton.`)}return $},this.getParser=()=>n,this.getPreProcessor=()=>s,this.getPostProcessor=()=>i,this.getResolver=()=>p,this.setDebug=function(e){o=e,t.setDebug(e)},this.setParser=e=>n=e,this.setPreProcessor=e=>s=e,this.setPostProcessor=e=>i=e,this.setResolver=e=>p=e,a[e.ID]=this}}}));
1
+ !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).TeqFw_Di_Container=t()}(this,(function(){"use strict";var e={CA:"A",CF:"F",ID:"container",ID_FQN:"TeqFw_Di_Container$",LI:"I",LS:"S",isClass(e){const t=Object.getOwnPropertyDescriptor(e,"prototype");return t&&!t.writable}};const t=/(function)*\s*\w*\s*\(\s*\{([^}]*)}/s,o=/constructor\s*\(\s*\{([^}]*)}/s;function n(e){const t=[];try{const o=new Function(`{${e}}`,"return");o(new Proxy({},{get:(e,o)=>t.push(o)}))}catch(t){throw new Error(`Cannot analyze the deps specification:${e}\n\nPlease, be sure that spec does not contain extra ')' in a comments.\n\nError: ${t}`)}return t}function s(s){return"function"==typeof s?e.isClass(s)?function(e){const t=[],s=e.toString(),r=o.exec(s);return r&&t.push(...n(r[1])),t}(s):function(e){const o=[],s=e.toString(),r=t.exec(s);return r&&o.push(...n(r[2])),o}(s):[]}class r{constructor(){let t=!1;this.create=async function(o,n,r,i){if(r.includes(o.origin))throw new Error(`Circular dependency for '${o.origin}'. Parents are: ${JSON.stringify(r)}`);if(o.exportName){const a=[...r,o.origin],{[o.exportName]:u}=n;if(o.composition===e.CF){if("function"==typeof u){const n=s(u);n.length&&(c=`Deps for object '${o.origin}' are: ${JSON.stringify(n)}`,t&&console.log(c));const r={};for(const e of n)r[e]=await i.compose(e,a);const l=e.isClass(u)?new u(r):u(r);return l instanceof Promise?await l:l}return Object.assign({},u)}return u}return n;var c},this.setDebug=function(e){t=e}}}class i{exportName;composition;life;moduleName;origin;wrappers=[]}const c=/^(node:)?(@?[A-Za-z0-9_-]+\/?[A-Za-z0-9_-]*)(([.#])?([A-Za-z0-9_]*)((\$)?(\$)?)?)?(\(([A-Za-z0-9_,]*)\))?$/;class a{canParse(){return!0}parse(t){const o=new i;o.origin=t;const n=c.exec(t);if(n&&(o.isNodeModule=Boolean(n[1]),o.moduleName=n[2].replace(/^node:/,""),"."===n[4]||"#"===n[4]?"$"===n[6]||"$$"===n[6]?(o.composition=e.CF,o.exportName=n[5],o.life="$"===n[6]?e.LS:e.LI):(o.composition=e.CA,o.life=e.LS,o.exportName=""!==n[5]?n[5]:"default"):"$"===n[6]||"$$"===n[6]?(o.composition=e.CF,o.exportName="default",o.life="$"===n[6]?e.LS:e.LI):(o.composition=void 0,o.exportName=void 0,o.life=void 0),n[10]&&(o.wrappers=n[10].split(","))),o.composition===e.CA&&o.life===e.LI)throw new Error(`Export is not a function and should be used as a singleton only: '${o.origin}'.`);return o}}class u{constructor(){let e=new a;const t=[];this.addChunk=function(e){t.push(e)},this.parse=function(o){let n;for(const e of t)if(e.canParse(o)){n=e.parse(o);break}return n||(n=e?.parse(o)),n},this.setDefaultChunk=function(t){e=t}}}class l{constructor(){const e=[];this.addChunk=function(t){e.push(t)},this.modify=function(t,o){let n=t;for(const s of e)n=s.modify(n,t,o);return n}}}class f{constructor(){const e=[];this.addChunk=function(t){e.push(t)},this.modify=async function(t,o,n){let s=t;for(const t of e)s=t.modify(s,o,n),s instanceof Promise&&(s=await s);return s}}}const d="root";class p{constructor(){const e={};let t=!1,o=[],n="/";this.addNamespaceRoot=function(n,s,r){const i=(t?s.replace(/^\\/,""):s).replace(/\\/g,"/"),c=t?`file://${i}`:i;e[n]={ext:r??"js",ns:n,[d]:c},o=Object.keys(e).sort(((e,t)=>t.localeCompare(e)))},this.resolve=function(t){let s,r,i;for(i of o)if(t.startsWith(i)){s=e[i][d],r=e[i].ext;break}if(s&&r){let e=t.replace(i,"");0===e.indexOf("_")&&(e=e.replace("_",""));const o=e.replaceAll("_",n);return`${s}${n}${o}.${r}`}return t},this.setWindowsEnv=function(e=!0){t=e,n=e?"\\":"/"}}}function m(e){return`${e.moduleName}#${e.exportName}`}return class{constructor(){let t=new r,o=!1,n=new u,s=new l,i=new f;const c={},a={};let d=new p;function h(){o&&console.log(...arguments)}this.get=async function(e,t=[]){return this.compose(e,t)},this.compose=async function(o,r=[]){if(h(`Object '${o}' is requested.`),o===e.ID||o===e.ID_FQN)return h("Container itself is returned."),a[e.ID];const u=n.parse(o),l=s.modify(u,r);if(l.life===e.LS){const e=m(l);if(a[e])return h(`Existing singleton '${e}' is returned.`),a[e]}let f;c[l.moduleName]||(h(`ES6 module '${l.moduleName}' is not resolved yet`),c[l.moduleName]=d.resolve(l.moduleName));const p=c[l.moduleName];try{f=await import(p),h(`ES6 module '${l.moduleName}' is loaded from '${p}'.`)}catch(e){throw console.error(e?.message,`Object key: "${o}".`,`Path: "${p}".`,`Stack: ${JSON.stringify(r)}`),e}let g=await t.create(l,f,r,this);var $;if(null===($=g)||"object"!=typeof $&&"function"!=typeof $||"[object Module]"===Object.prototype.toString.call($)||Object.isFrozen($)||Object.freeze(g),g=await i.modify(g,l,r),h(`Object '${o}' is created.`),l.life===e.LS){const e=m(l);a[e]=g,h(`Object '${o}' is saved as singleton.`)}return g},this.getParser=()=>n,this.getPreProcessor=()=>s,this.getPostProcessor=()=>i,this.getResolver=()=>d,this.register=function(t,o){if(!t||!o)throw new Error("depId and object are required");const s=n.parse(t);if(s.life!==e.LS)throw new Error(`Only singletons can be registered manually. Given: ${t}`);{const e=m(s);a[e]=o,h(`Object '${t}' is registered manually as singleton.`)}},this.setDebug=function(e){o=e,t.setDebug(e)},this.setParser=e=>n=e,this.setPreProcessor=e=>s=e,this.setPostProcessor=e=>i=e,this.setResolver=e=>d=e,a[e.ID]=this}}}));
@@ -0,0 +1,37 @@
1
+ // eslint.config.js
2
+ import js from '@eslint/js';
3
+
4
+ /** @type {import('eslint').Linter.FlatConfig[]} */
5
+ export default [
6
+ js.configs.recommended,
7
+ {
8
+ languageOptions: {
9
+ ecmaVersion: 2022, // required for public class fields
10
+ sourceType: 'module',
11
+ globals: {
12
+ console: 'readonly',
13
+ },
14
+ },
15
+ rules: {
16
+ 'camelcase': [
17
+ 'warn',
18
+ {
19
+ properties: 'never',
20
+ ignoreDestructuring: true,
21
+ allow: ['^([A-Z][a-zA-Z0-9]*_)+[A-Z][a-zA-Z0-9]*$'],
22
+ },
23
+ ],
24
+ 'indent': ['error', 4],
25
+ 'linebreak-style': ['error', 'unix'],
26
+ 'quotes': ['error', 'single'],
27
+ 'semi': ['error', 'always'],
28
+ },
29
+ },
30
+ // Special rule override for interface declarations
31
+ {
32
+ files: ['./src/Api/**/*.js'],
33
+ rules: {
34
+ 'no-unused-vars': 'off',
35
+ },
36
+ },
37
+ ];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teqfw/di",
3
- "version": "0.32.0",
3
+ "version": "0.33.0",
4
4
  "description": "Dependency Injection container for ES6 modules that works in both browser and Node.js apps.",
5
5
  "keywords": [
6
6
  "dependency injection",
@@ -28,13 +28,16 @@
28
28
  },
29
29
  "scripts": {
30
30
  "rollup": "rollup -c",
31
+ "eslint": "eslint './src/**/*.js'",
31
32
  "test": "mocha --recursive './test/**/*.test.mjs'"
32
33
  },
33
34
  "devDependencies": {
35
+ "@eslint/js": "^9.25.0",
34
36
  "@rollup/plugin-node-resolve": "^16.0.1",
37
+ "@rollup/plugin-terser": "^0.4.4",
38
+ "eslint": "^9.25.0",
35
39
  "mocha": "^11.1.0",
36
- "rollup": "^4.36.0",
37
- "@rollup/plugin-terser": "^0.4.4"
40
+ "rollup": "^4.36.0"
38
41
  },
39
42
  "mocha": {
40
43
  "spec": "./test/**/*.test.mjs",
@@ -8,8 +8,8 @@
8
8
  import Defs from '../../../../Defs.js';
9
9
 
10
10
  // VARS
11
- const FUNC = /(function)*\s*\w*\s*\(\s*\{([^\}]*)\}/s;
12
- const CLASS = /constructor\s*\(\s*\{([^\}]*)\}/s;
11
+ const FUNC = /(function)*\s*\w*\s*\(\s*\{([^}]*)}/s;
12
+ const CLASS = /constructor\s*\(\s*\{([^}]*)}/s;
13
13
 
14
14
  // FUNCS
15
15
 
@@ -32,7 +32,7 @@ function _analyze(params) {
32
32
  fn(spec);
33
33
  } catch (e) {
34
34
  const msg = `Cannot analyze the deps specification:${params}\n`
35
- + `\nPlease, be sure that spec does not contain extra ')' in a comments.`
35
+ + '\nPlease, be sure that spec does not contain extra \')\' in a comments.'
36
36
  + `\n\nError: ${e}`;
37
37
  throw new Error(msg);
38
38
  }
@@ -10,16 +10,16 @@ import Dto from '../../../../DepId.js';
10
10
  import Defs from '../../../../Defs.js';
11
11
 
12
12
  // VARS
13
- /** @type {RegExp} expression for default object key */
14
- const REGEXP = /^(node:)?((@?[A-Za-z0-9_\-]+\/?[A-Za-z0-9_\-]*))((\.)?([A-Za-z0-9_]*)((\$)?(\$)?)?)?(\(([A-Za-z0-9_,]*)\))?$/;
13
+ /** @type {RegExp} expression for a default object key */
14
+ const REGEXP = /^(node:)?(@?[A-Za-z0-9_-]+\/?[A-Za-z0-9_-]*)(([.#])?([A-Za-z0-9_]*)((\$)?(\$)?)?)?(\(([A-Za-z0-9_,]*)\))?$/;
15
15
 
16
16
  /**
17
17
  * @implements TeqFw_Di_Api_Container_Parser_Chunk
18
18
  */
19
19
  export default class TeqFw_Di_Container_A_Parser_Chunk_Def {
20
20
 
21
- canParse(depId) {
22
- // default parser always tries to parse the depId
21
+ canParse() {
22
+ // the default parser always tries to parse the depId
23
23
  return true;
24
24
  }
25
25
 
@@ -31,22 +31,22 @@ export default class TeqFw_Di_Container_A_Parser_Chunk_Def {
31
31
  res.isNodeModule = Boolean(parts[1]); // Detect 'node:' prefix
32
32
  res.moduleName = parts[2].replace(/^node:/, ''); // Remove 'node:' prefix
33
33
 
34
- if (parts[5] === '.') {
34
+ if ((parts[4] === '.') || (parts[4] === '#')) {
35
35
  // Ns_Module.export or node:package.export
36
- if ((parts[7] === '$') || (parts[7] === '$$')) {
36
+ if ((parts[6] === '$') || (parts[6] === '$$')) {
37
37
  res.composition = Defs.CF;
38
- res.exportName = parts[6];
39
- res.life = (parts[7] === '$') ? Defs.LS : Defs.LI;
38
+ res.exportName = parts[5];
39
+ res.life = (parts[6] === '$') ? Defs.LS : Defs.LI;
40
40
  } else {
41
41
  res.composition = Defs.CA;
42
42
  res.life = Defs.LS;
43
- res.exportName = (parts[6] !== '') ? parts[6] : 'default';
43
+ res.exportName = (parts[5] !== '') ? parts[5] : 'default';
44
44
  }
45
- } else if ((parts[7] === '$') || parts[7] === '$$') {
45
+ } else if ((parts[6] === '$') || parts[6] === '$$') {
46
46
  // Ns_Module$$ or node:package$$
47
47
  res.composition = Defs.CF;
48
48
  res.exportName = 'default';
49
- res.life = (parts[7] === '$') ? Defs.LS : Defs.LI;
49
+ res.life = (parts[6] === '$') ? Defs.LS : Defs.LI;
50
50
  } else {
51
51
  // Ns_Module or node:package (ES6 module)
52
52
  res.composition = undefined;
@@ -55,8 +55,8 @@ export default class TeqFw_Di_Container_A_Parser_Chunk_Def {
55
55
  }
56
56
 
57
57
  // Wrappers handling
58
- if (parts[11]) {
59
- res.wrappers = parts[11].split(',');
58
+ if (parts[10]) {
59
+ res.wrappers = parts[10].split(',');
60
60
  }
61
61
  }
62
62
 
@@ -9,16 +9,16 @@ import Dto from '../../../../DepId.js';
9
9
  import Defs from '../../../../Defs.js';
10
10
 
11
11
  // VARS
12
- /** @type {RegExp} expression for default object key */
13
- const REGEXP = /^(node:)?((([A-Z])[A-Za-z0-9_]*|[a-z][a-z0-9\-]*))((#|\.)?([A-Za-z0-9_]*)((\$)([F|A])?([S|I])?)?)?$/;
12
+ /** @type {RegExp} expression for a default object key */
13
+ const REGEXP = /^(node:)?(([A-Z])[A-Za-z0-9_]*|[a-z][a-z0-9-]*)(([#.])?([A-Za-z0-9_]*)((\$)([F|A])?([S|I])?)?)?$/;
14
14
 
15
15
  /**
16
16
  * @implements TeqFw_Di_Api_Container_Parser_Chunk
17
17
  */
18
18
  export default class TeqFw_Di_Container_A_Parser_Chunk_V02X {
19
19
 
20
- canParse(depId) {
21
- // default parser always tries to parse the depId
20
+ canParse() {
21
+ // the default parser always tries to parse the depId
22
22
  return true;
23
23
  }
24
24
 
@@ -30,29 +30,30 @@ export default class TeqFw_Di_Container_A_Parser_Chunk_V02X {
30
30
  res.isNodeModule = Boolean(parts[1]); // Check if it starts with 'node:'
31
31
  res.moduleName = parts[2].replace(/^node:/, ''); // Remove 'node:' if present
32
32
 
33
- if (parts[6] === '.') {
33
+ if (parts[5] === '.') {
34
34
  // App_Service.export or node:package.export
35
- if (parts[9] === '$') {
35
+ if (parts[8] === '$') {
36
36
  // App_Service.export$ or node:package.export$
37
37
  res.composition = Defs.CF;
38
- res.exportName = parts[7];
39
- res.life = (parts[11] === Defs.LI) ? Defs.LI : Defs.LS;
38
+ res.exportName = parts[6];
39
+ res.life = (parts[10] === Defs.LI) ? Defs.LI : Defs.LS;
40
40
  } else {
41
- res.composition = (!parts[9] || parts[9] === Defs.CA) ? Defs.CA : Defs.CF;
42
- res.exportName = parts[7];
43
- res.life = (!parts[9] || parts[11] === Defs.LS) ? Defs.LS : Defs.LI;
41
+ res.composition = (!parts[8] || parts[8] === Defs.CA) ? Defs.CA : Defs.CF;
42
+ res.exportName = parts[6];
43
+ res.life = (!parts[8] || parts[10] === Defs.LS) ? Defs.LS : Defs.LI;
44
44
  }
45
- } else if (parts[9] === '$') {
45
+ } else if (parts[8] === '$') {
46
46
  // App_Logger$FS or node:package$
47
- res.composition = (!parts[10] || parts[10] === Defs.CF) ? Defs.CF : Defs.CA;
47
+ res.composition = (!parts[9] || parts[9] === Defs.CF) ? Defs.CF : Defs.CA;
48
48
  res.exportName = 'default';
49
- res.life = parts[11] ? (parts[11] === Defs.LS ? Defs.LS : Defs.LI) : (res.composition === Defs.CF ? Defs.LS : Defs.LI);
49
+ res.life = parts[10] ? (parts[10] === Defs.LS ? Defs.LS : Defs.LI) : (res.composition === Defs.CF ? Defs.LS : Defs.LI);
50
50
  } else {
51
51
  // App_Service or node:package (ES6 module)
52
52
  res.composition = undefined;
53
53
  res.exportName = undefined;
54
54
  res.life = undefined;
55
55
  }
56
+
56
57
  }
57
58
 
58
59
  // Enforce singleton for non-factory exports
package/src/Container.js CHANGED
@@ -87,7 +87,7 @@ export default class TeqFw_Di_Container {
87
87
  (depId === Defs.ID) ||
88
88
  (depId === Defs.ID_FQN)
89
89
  ) {
90
- log(`Container itself is returned.`);
90
+ log('Container itself is returned.');
91
91
  return _regSingles[Defs.ID];
92
92
  }
93
93
  // parse the `objectKey` and get the structured DTO
package/.eslintrc.mjs DELETED
File without changes