@andrewcaires/decorator 1.0.1 → 1.0.2

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.1
2
+ * @andrewcaires/decorator v1.0.2
3
3
  * Typescript decorator library for nodejs development
4
4
  * (c) 2026 Andrew Caires
5
5
  * @license: MIT
6
6
  */
7
- "use strict";var t=require("@andrewcaires/utils.js");const r=t.cache();exports.metadata=(e,s,c)=>{t.isObject(s)&&(s=s.constructor);const a=r(s);return a[e]||(a[e]=c),a[e]};
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)&&(r=r.constructor);const i=n(r);return i[t]||(i[t]=s),i[t]};
package/dist/index.d.ts CHANGED
@@ -1,9 +1,35 @@
1
1
  /*!
2
- * @andrewcaires/decorator v1.0.1
2
+ * @andrewcaires/decorator v1.0.2
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';
8
+
9
+ declare const Inject: (key: TypeAnyConstructor) => ParameterDecorator;
10
+
11
+ declare const Injectable: <T extends TypeAnyConstructor>(constructor: T) => T;
12
+
13
+ interface Injection {
14
+ args: Array<any>;
15
+ constructor: TypeAnyConstructor;
16
+ instance: TypeAnyObject;
17
+ }
18
+
19
+ declare const InjectionKey: unique symbol;
20
+
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;
29
+
30
+ declare const SingletonKey: unique symbol;
31
+
7
32
  declare const metadata: <T = any>(key: symbol, target: any, value: T) => T;
8
33
 
9
- export { metadata };
34
+ export { Inject, Injectable, InjectionKey, Injections, Singleton, SingletonKey, metadata };
35
+ export type { Injection };
package/dist/index.esm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @andrewcaires/decorator v1.0.1
2
+ * @andrewcaires/decorator v1.0.2
3
3
  * Typescript decorator library for nodejs development
4
4
  * (c) 2026 Andrew Caires
5
5
  * @license: MIT
6
6
  */
7
- import{cache as r,isObject as t}from"@andrewcaires/utils.js";const o=r(),s=(r,s,c)=>{t(s)&&(s=s.constructor);const n=o(s);return n[r]||(n[r]=c),n[r]};export{s as metadata};
7
+ import{toArray as t,cache as e,isObject as r}from"@andrewcaires/utils.js";const s=Symbol("INJECTION"),i=t=>(e,r,i)=>{var n;const a={index:i,key:t},o=null!==(n=e[s])&&void 0!==n?n:[];Object.defineProperty(e,s,{enumerable:!1,configurable:!0,writable:!1,value:[a,...o]})};class n{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)}}n.registry=new Map;const a=e=>class extends e{constructor(...r){(r=t(e[s])).forEach(({key:t})=>{n.has(t)||n.register(t,new t)}),super(...r.sort(({index:t},{index:e})=>t-e).map(({key:t})=>n.get(t)))}},o=Symbol("SINGLETON"),c=t=>class e extends t{constructor(...t){if(e[o])return e[o];super(...t),e[o]=this}},l=e(),u=(t,e,s)=>{r(e)&&(e=e.constructor);const i=l(e);return i[t]||(i[t]=s),i[t]};export{i as Inject,a as Injectable,s as InjectionKey,n as Injections,c as Singleton,o as SingletonKey,u as metadata};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andrewcaires/decorator",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Typescript decorator library for nodejs development",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs.js",
@@ -37,7 +37,7 @@
37
37
  },
38
38
  "homepage": "https://github.com/andrewcaires/npm/tree/main/decorator#readme",
39
39
  "dependencies": {
40
- "@andrewcaires/utils.js": "^0.4.19"
40
+ "@andrewcaires/utils.js": "^0.4.20"
41
41
  },
42
42
  "devDependencies": {
43
43
  "@rollup/plugin-commonjs": "^29.0.0",