@andrewcaires/decorator 1.0.3 → 1.1.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/dist/index.cjs.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @andrewcaires/decorator v1.0.3
2
+ * @andrewcaires/decorator v1.1.0
3
3
  * Typescript decorator library for nodejs development
4
4
  * (c) 2026 Andrew Caires
5
5
  * @license: MIT
6
6
  */
7
- "use strict";var e=require("@andrewcaires/utils.js");const t=Symbol("INJECTION");class r{static register(e,t){this.has(e)||this.registry.set(e,t)}static get(e){var t;return null!==(t=this.registry.get(e))&&void 0!==t?t:null}static has(e){return this.registry.has(e)}}r.registry=new Map;const s=Symbol("SINGLETON"),n=e.cache();exports.Inject=e=>(r,s,n)=>{var i;const o={index:n,key:e},a=null!==(i=r[t])&&void 0!==i?i:[];Object.defineProperty(r,t,{enumerable:!1,configurable:!0,writable:!1,value:[o,...a]})},exports.Injectable=s=>class extends s{constructor(...n){(n=e.toArray(s[t])).forEach(({key:e})=>{r.has(e)||r.register(e,new e)}),super(...n.sort(({index:e},{index:t})=>e-t).map(({key:e})=>r.get(e)))}},exports.InjectionKey=t,exports.Injections=r,exports.Singleton=e=>class t extends e{constructor(...e){if(t[s])return t[s];super(...e),t[s]=this}},exports.SingletonKey=s,exports.metadata=(t,r,s)=>{e.isObject(r)&&!e.isSymbol(r)&&(r=r.constructor);const i=n(r);return i[t]||(i[t]=s),i[t]};
7
+ "use strict";var e=require("@andrewcaires/utils.js");const t=e.cache(),r=(r,s,o)=>{e.isObject(s)&&!e.isSymbol(s)&&(s=s.constructor);const n=t(s);return n[r]||(n[r]=o),n[r]},s=Symbol("INJECTION"),o=e=>{var t;const n=r(s,e,{});return(null!==(t=n.args)&&void 0!==t?t:[]).sort(({index:e},{index:t})=>e-t).map(({key:e})=>(n.instance||(n.instance=new e(o(e))),n.instance))},n=Symbol("SINGLETON");exports.Inject=e=>(t,o,n)=>{const c=r(s,t,{});c.args||(c.args=[]),c.args.push({index:n,key:e})},exports.Injectable=()=>e=>class t extends e{constructor(...n){super(...o(e)),r(s,t,{}).constructor=e}},exports.InjectionKey=s,exports.Singleton=()=>e=>class t extends e{constructor(...e){if(t[n])return t[n];super(...e),t[n]=this}},exports.SingletonKey=n,exports.Trait=(...e)=>t=>{e.forEach(e=>{Object.getOwnPropertyNames(e.prototype).forEach(r=>{var s;Object.defineProperty(t.prototype,r,null!==(s=Object.getOwnPropertyDescriptor(e.prototype,r))&&void 0!==s?s:Object.create(null))})})},exports.getInjectionArgs=o,exports.metadata=r;
package/dist/index.d.ts CHANGED
@@ -1,14 +1,16 @@
1
1
  /*!
2
- * @andrewcaires/decorator v1.0.3
2
+ * @andrewcaires/decorator v1.1.0
3
3
  * Typescript decorator library for nodejs development
4
4
  * (c) 2026 Andrew Caires
5
5
  * @license: MIT
6
6
  */
7
- import { TypeAnyConstructor, TypeAnyObject } from '@andrewcaires/utils.js';
7
+ import { TypeAnyConstructor, TypeAnyFunction, TypeAnyObject } from '@andrewcaires/utils.js';
8
+
9
+ declare const getInjectionArgs: (target: TypeAnyConstructor) => Array<any>;
8
10
 
9
11
  declare const Inject: (key: TypeAnyConstructor) => ParameterDecorator;
10
12
 
11
- declare const Injectable: <T extends TypeAnyConstructor>(constructor: T) => T;
13
+ declare const Injectable: <T extends TypeAnyConstructor>() => TypeAnyFunction<T>;
12
14
 
13
15
  interface Injection {
14
16
  args: Array<any>;
@@ -18,18 +20,13 @@ interface Injection {
18
20
 
19
21
  declare const InjectionKey: unique symbol;
20
22
 
21
- declare class Injections {
22
- private static registry;
23
- static register(key: TypeAnyConstructor, instance: TypeAnyObject): void;
24
- static get(key: TypeAnyConstructor): TypeAnyObject | null;
25
- static has(key: TypeAnyConstructor): boolean;
26
- }
27
-
28
- declare const Singleton: <T extends TypeAnyConstructor>(constructor: T) => T;
23
+ declare const Singleton: <T extends TypeAnyConstructor>() => TypeAnyFunction<T>;
29
24
 
30
25
  declare const SingletonKey: unique symbol;
31
26
 
27
+ declare const Trait: (...constructors: Array<TypeAnyConstructor>) => ClassDecorator;
28
+
32
29
  declare const metadata: <T = any>(key: symbol, target: any, value: T) => T;
33
30
 
34
- export { Inject, Injectable, InjectionKey, Injections, Singleton, SingletonKey, metadata };
31
+ export { Inject, Injectable, InjectionKey, Singleton, SingletonKey, Trait, getInjectionArgs, metadata };
35
32
  export type { Injection };
package/dist/index.esm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @andrewcaires/decorator v1.0.3
2
+ * @andrewcaires/decorator v1.1.0
3
3
  * Typescript decorator library for nodejs development
4
4
  * (c) 2026 Andrew Caires
5
5
  * @license: MIT
6
6
  */
7
- import{toArray as t,cache as e,isObject as r,isSymbol as s}from"@andrewcaires/utils.js";const i=Symbol("INJECTION"),n=t=>(e,r,s)=>{var n;const a={index:s,key:t},o=null!==(n=e[i])&&void 0!==n?n:[];Object.defineProperty(e,i,{enumerable:!1,configurable:!0,writable:!1,value:[a,...o]})};class a{static register(t,e){this.has(t)||this.registry.set(t,e)}static get(t){var e;return null!==(e=this.registry.get(t))&&void 0!==e?e:null}static has(t){return this.registry.has(t)}}a.registry=new Map;const o=e=>class extends e{constructor(...r){(r=t(e[i])).forEach(({key:t})=>{a.has(t)||a.register(t,new t)}),super(...r.sort(({index:t},{index:e})=>t-e).map(({key:t})=>a.get(t)))}},c=Symbol("SINGLETON"),l=t=>class e extends t{constructor(...t){if(e[c])return e[c];super(...t),e[c]=this}},u=e(),g=(t,e,i)=>{r(e)&&!s(e)&&(e=e.constructor);const n=u(e);return n[t]||(n[t]=i),n[t]};export{n as Inject,o as Injectable,i as InjectionKey,a as Injections,l as Singleton,c as SingletonKey,g as metadata};
7
+ import{cache as r,isObject as t,isSymbol as e}from"@andrewcaires/utils.js";const o=r(),s=(r,s,n)=>{t(s)&&!e(s)&&(s=s.constructor);const c=o(s);return c[r]||(c[r]=n),c[r]},n=Symbol("INJECTION"),c=r=>{var t;const e=s(n,r,{});return(null!==(t=e.args)&&void 0!==t?t:[]).sort(({index:r},{index:t})=>r-t).map(({key:r})=>(e.instance||(e.instance=new r(c(r))),e.instance))},a=r=>(t,e,o)=>{const c=s(n,t,{});c.args||(c.args=[]),c.args.push({index:o,key:r})},p=()=>r=>class t extends r{constructor(...e){super(...c(r)),s(n,t,{}).constructor=r}},i=Symbol("SINGLETON"),u=()=>r=>class t extends r{constructor(...r){if(t[i])return t[i];super(...r),t[i]=this}},l=(...r)=>t=>{r.forEach(r=>{Object.getOwnPropertyNames(r.prototype).forEach(e=>{var o;Object.defineProperty(t.prototype,e,null!==(o=Object.getOwnPropertyDescriptor(r.prototype,e))&&void 0!==o?o:Object.create(null))})})};export{a as Inject,p as Injectable,n as InjectionKey,u as Singleton,i as SingletonKey,l as Trait,c as getInjectionArgs,s as metadata};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andrewcaires/decorator",
3
- "version": "1.0.3",
3
+ "version": "1.1.0",
4
4
  "description": "Typescript decorator library for nodejs development",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs.js",
@@ -37,18 +37,18 @@
37
37
  },
38
38
  "homepage": "https://github.com/andrewcaires/npm/tree/main/decorator#readme",
39
39
  "dependencies": {
40
- "@andrewcaires/utils.js": "^0.4.20"
40
+ "@andrewcaires/utils.js": "^0.4.25"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@rollup/plugin-commonjs": "^29.0.0",
44
44
  "@rollup/plugin-terser": "^0.4.4",
45
45
  "@rollup/plugin-typescript": "^12.3.0",
46
- "@types/node": "^25.0.8",
46
+ "@types/node": "^25.0.9",
47
47
  "eslint": "^9.39.2",
48
- "rollup": "^4.55.1",
48
+ "rollup": "^4.55.2",
49
49
  "rollup-plugin-dts": "^6.3.0",
50
50
  "tslib": "^2.8.1",
51
51
  "tsx": "^4.21.0",
52
- "typescript-eslint": "^8.53.0"
52
+ "typescript-eslint": "^8.53.1"
53
53
  }
54
54
  }