@goodie-ts/decorators 0.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/LICENSE +21 -0
- package/dist/eager.d.ts +13 -0
- package/dist/eager.d.ts.map +1 -0
- package/dist/eager.js +16 -0
- package/dist/eager.js.map +1 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/inject.d.ts +17 -0
- package/dist/inject.d.ts.map +1 -0
- package/dist/inject.js +24 -0
- package/dist/inject.js.map +1 -0
- package/dist/injectable.d.ts +11 -0
- package/dist/injectable.d.ts.map +1 -0
- package/dist/injectable.js +14 -0
- package/dist/injectable.js.map +1 -0
- package/dist/metadata.d.ts +34 -0
- package/dist/metadata.d.ts.map +1 -0
- package/dist/metadata.js +40 -0
- package/dist/metadata.js.map +1 -0
- package/dist/module.d.ts +19 -0
- package/dist/module.d.ts.map +1 -0
- package/dist/module.js +20 -0
- package/dist/module.js.map +1 -0
- package/dist/named.d.ts +13 -0
- package/dist/named.d.ts.map +1 -0
- package/dist/named.js +16 -0
- package/dist/named.js.map +1 -0
- package/dist/optional.d.ts +12 -0
- package/dist/optional.d.ts.map +1 -0
- package/dist/optional.js +19 -0
- package/dist/optional.js.map +1 -0
- package/dist/pre-destroy.d.ts +20 -0
- package/dist/pre-destroy.d.ts.map +1 -0
- package/dist/pre-destroy.js +25 -0
- package/dist/pre-destroy.js.map +1 -0
- package/dist/provides.d.ts +14 -0
- package/dist/provides.d.ts.map +1 -0
- package/dist/provides.js +19 -0
- package/dist/provides.js.map +1 -0
- package/dist/singleton.d.ts +11 -0
- package/dist/singleton.d.ts.map +1 -0
- package/dist/singleton.js +14 -0
- package/dist/singleton.js.map +1 -0
- package/package.json +33 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 GOOD Code ApS
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/eager.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marks a singleton bean for eager instantiation during context creation.
|
|
3
|
+
* By default, singletons are lazy (created on first `get()`).
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* @Eager()
|
|
7
|
+
* @Singleton()
|
|
8
|
+
* class StartupService { ... }
|
|
9
|
+
*/
|
|
10
|
+
export declare function Eager(): ClassDecorator_Stage3;
|
|
11
|
+
type ClassDecorator_Stage3 = (target: new (...args: any[]) => any, context: ClassDecoratorContext) => void;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=eager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eager.d.ts","sourceRoot":"","sources":["../src/eager.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAAgB,KAAK,IAAI,qBAAqB,CAI7C;AAED,KAAK,qBAAqB,GAAG,CAC3B,MAAM,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACnC,OAAO,EAAE,qBAAqB,KAC3B,IAAI,CAAC"}
|
package/dist/eager.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { META, setMeta } from './metadata.js';
|
|
2
|
+
/**
|
|
3
|
+
* Marks a singleton bean for eager instantiation during context creation.
|
|
4
|
+
* By default, singletons are lazy (created on first `get()`).
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* @Eager()
|
|
8
|
+
* @Singleton()
|
|
9
|
+
* class StartupService { ... }
|
|
10
|
+
*/
|
|
11
|
+
export function Eager() {
|
|
12
|
+
return (_target, context) => {
|
|
13
|
+
setMeta(context.metadata, META.EAGER, true);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=eager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"eager.js","sourceRoot":"","sources":["../src/eager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE9C;;;;;;;;GAQG;AACH,MAAM,UAAU,KAAK;IACnB,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QAC1B,OAAO,CAAC,OAAO,CAAC,QAAS,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAC/C,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export { Eager } from './eager.js';
|
|
2
|
+
export { Inject } from './inject.js';
|
|
3
|
+
export { Injectable } from './injectable.js';
|
|
4
|
+
export { getClassMetadata, META, pushMeta, setMeta } from './metadata.js';
|
|
5
|
+
export type { ModuleOptions } from './module.js';
|
|
6
|
+
export { Module } from './module.js';
|
|
7
|
+
export { Named } from './named.js';
|
|
8
|
+
export { Optional } from './optional.js';
|
|
9
|
+
export { PreDestroy } from './pre-destroy.js';
|
|
10
|
+
export { Provides } from './provides.js';
|
|
11
|
+
export { Singleton } from './singleton.js';
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAC1E,YAAY,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { Eager } from './eager.js';
|
|
2
|
+
export { Inject } from './inject.js';
|
|
3
|
+
export { Injectable } from './injectable.js';
|
|
4
|
+
export { getClassMetadata, META, pushMeta, setMeta } from './metadata.js';
|
|
5
|
+
export { Module } from './module.js';
|
|
6
|
+
export { Named } from './named.js';
|
|
7
|
+
export { Optional } from './optional.js';
|
|
8
|
+
export { PreDestroy } from './pre-destroy.js';
|
|
9
|
+
export { Provides } from './provides.js';
|
|
10
|
+
export { Singleton } from './singleton.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE1E,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/inject.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { InjectionToken } from '@goodie-ts/core';
|
|
2
|
+
/**
|
|
3
|
+
* Accessor decorator to inject a dependency by qualifier name or InjectionToken.
|
|
4
|
+
*
|
|
5
|
+
* Note: Native Stage 3 decorators don't support parameter decorators.
|
|
6
|
+
* Use `@Inject` on auto-accessor fields only. Constructor parameter injection
|
|
7
|
+
* is handled by the Phase 2 transformer via AST analysis.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* @Singleton()
|
|
11
|
+
* class UserService {
|
|
12
|
+
* @Inject('primary') accessor repo!: UserRepository
|
|
13
|
+
* @Inject(DB_URL) accessor url!: string
|
|
14
|
+
* }
|
|
15
|
+
*/
|
|
16
|
+
export declare function Inject(qualifier: string | InjectionToken<unknown>): (target: ClassAccessorDecoratorTarget<unknown, unknown>, context: ClassAccessorDecoratorContext) => void;
|
|
17
|
+
//# sourceMappingURL=inject.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject.d.ts","sourceRoot":"","sources":["../src/inject.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAGtD;;;;;;;;;;;;;GAaG;AACH,wBAAgB,MAAM,CACpB,SAAS,EAAE,MAAM,GAAG,cAAc,CAAC,OAAO,CAAC,GAC1C,CACD,MAAM,EAAE,4BAA4B,CAAC,OAAO,EAAE,OAAO,CAAC,EACtD,OAAO,EAAE,6BAA6B,KACnC,IAAI,CAOR"}
|
package/dist/inject.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { META, pushMeta } from './metadata.js';
|
|
2
|
+
/**
|
|
3
|
+
* Accessor decorator to inject a dependency by qualifier name or InjectionToken.
|
|
4
|
+
*
|
|
5
|
+
* Note: Native Stage 3 decorators don't support parameter decorators.
|
|
6
|
+
* Use `@Inject` on auto-accessor fields only. Constructor parameter injection
|
|
7
|
+
* is handled by the Phase 2 transformer via AST analysis.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* @Singleton()
|
|
11
|
+
* class UserService {
|
|
12
|
+
* @Inject('primary') accessor repo!: UserRepository
|
|
13
|
+
* @Inject(DB_URL) accessor url!: string
|
|
14
|
+
* }
|
|
15
|
+
*/
|
|
16
|
+
export function Inject(qualifier) {
|
|
17
|
+
return (_target, context) => {
|
|
18
|
+
pushMeta(context.metadata, META.INJECT, {
|
|
19
|
+
fieldName: context.name,
|
|
20
|
+
qualifier,
|
|
21
|
+
});
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=inject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject.js","sourceRoot":"","sources":["../src/inject.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE/C;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,MAAM,CACpB,SAA2C;IAK3C,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QAC1B,QAAQ,CAAC,OAAO,CAAC,QAAS,EAAE,IAAI,CAAC,MAAM,EAAE;YACvC,SAAS,EAAE,OAAO,CAAC,IAAI;YACvB,SAAS;SACV,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marks a class as injectable with prototype scope.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* @Injectable()
|
|
6
|
+
* class UserRepository { ... }
|
|
7
|
+
*/
|
|
8
|
+
export declare function Injectable(): ClassDecorator_Stage3;
|
|
9
|
+
type ClassDecorator_Stage3 = (target: new (...args: any[]) => any, context: ClassDecoratorContext) => void;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=injectable.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectable.d.ts","sourceRoot":"","sources":["../src/injectable.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,wBAAgB,UAAU,IAAI,qBAAqB,CAIlD;AAED,KAAK,qBAAqB,GAAG,CAC3B,MAAM,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACnC,OAAO,EAAE,qBAAqB,KAC3B,IAAI,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { META, setMeta } from './metadata.js';
|
|
2
|
+
/**
|
|
3
|
+
* Marks a class as injectable with prototype scope.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* @Injectable()
|
|
7
|
+
* class UserRepository { ... }
|
|
8
|
+
*/
|
|
9
|
+
export function Injectable() {
|
|
10
|
+
return (_target, context) => {
|
|
11
|
+
setMeta(context.metadata, META.SCOPE, 'prototype');
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=injectable.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"injectable.js","sourceRoot":"","sources":["../src/injectable.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,UAAU,UAAU;IACxB,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QAC1B,OAAO,CAAC,OAAO,CAAC,QAAS,EAAE,IAAI,CAAC,KAAK,EAAE,WAA2B,CAAC,CAAC;IACtE,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata helpers for Stage 3 decorators.
|
|
3
|
+
*
|
|
4
|
+
* Stage 3 decorators provide `context.metadata` — an object that gets
|
|
5
|
+
* attached to the class via `Symbol.metadata`. We use well-known keys
|
|
6
|
+
* (Symbols) to avoid collisions with user metadata.
|
|
7
|
+
*/
|
|
8
|
+
/** Well-known metadata keys used by goodie decorators. */
|
|
9
|
+
export declare const META: {
|
|
10
|
+
readonly SCOPE: symbol;
|
|
11
|
+
readonly NAME: symbol;
|
|
12
|
+
readonly EAGER: symbol;
|
|
13
|
+
readonly MODULE: symbol;
|
|
14
|
+
readonly PROVIDES: symbol;
|
|
15
|
+
readonly INJECT: symbol;
|
|
16
|
+
readonly OPTIONAL: symbol;
|
|
17
|
+
readonly PRE_DESTROY: symbol;
|
|
18
|
+
};
|
|
19
|
+
type MetadataObject = DecoratorMetadataObject | Record<PropertyKey, unknown>;
|
|
20
|
+
/**
|
|
21
|
+
* Set a single metadata value on the decorator context metadata object.
|
|
22
|
+
*/
|
|
23
|
+
export declare function setMeta(metadata: MetadataObject, key: symbol, value: unknown): void;
|
|
24
|
+
/**
|
|
25
|
+
* Push a value onto an array stored under `key`. Creates the array if needed.
|
|
26
|
+
*/
|
|
27
|
+
export declare function pushMeta(metadata: MetadataObject, key: symbol, value: unknown): void;
|
|
28
|
+
/**
|
|
29
|
+
* Read the metadata object stashed on a class by Stage 3 decorators.
|
|
30
|
+
* Returns `undefined` if no decorators have run on the class.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getClassMetadata(cls: abstract new (...args: any[]) => any): Record<PropertyKey, unknown> | undefined;
|
|
33
|
+
export {};
|
|
34
|
+
//# sourceMappingURL=metadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,0DAA0D;AAC1D,eAAO,MAAM,IAAI;;;;;;;;;CASP,CAAC;AAEX,KAAK,cAAc,GAAG,uBAAuB,GAAG,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;AAE7E;;GAEG;AACH,wBAAgB,OAAO,CACrB,QAAQ,EAAE,cAAc,EACxB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,OAAO,GACb,IAAI,CAEN;AAED;;GAEG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,cAAc,EACxB,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,OAAO,GACb,IAAI,CAIN;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAC9B,GAAG,EAAE,QAAQ,MAAM,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,GACxC,MAAM,CAAC,WAAW,EAAE,OAAO,CAAC,GAAG,SAAS,CAI1C"}
|
package/dist/metadata.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Metadata helpers for Stage 3 decorators.
|
|
3
|
+
*
|
|
4
|
+
* Stage 3 decorators provide `context.metadata` — an object that gets
|
|
5
|
+
* attached to the class via `Symbol.metadata`. We use well-known keys
|
|
6
|
+
* (Symbols) to avoid collisions with user metadata.
|
|
7
|
+
*/
|
|
8
|
+
/** Well-known metadata keys used by goodie decorators. */
|
|
9
|
+
export const META = {
|
|
10
|
+
SCOPE: Symbol('goodie:scope'),
|
|
11
|
+
NAME: Symbol('goodie:name'),
|
|
12
|
+
EAGER: Symbol('goodie:eager'),
|
|
13
|
+
MODULE: Symbol('goodie:module'),
|
|
14
|
+
PROVIDES: Symbol('goodie:provides'),
|
|
15
|
+
INJECT: Symbol('goodie:inject'),
|
|
16
|
+
OPTIONAL: Symbol('goodie:optional'),
|
|
17
|
+
PRE_DESTROY: Symbol('goodie:pre-destroy'),
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Set a single metadata value on the decorator context metadata object.
|
|
21
|
+
*/
|
|
22
|
+
export function setMeta(metadata, key, value) {
|
|
23
|
+
metadata[key] = value;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Push a value onto an array stored under `key`. Creates the array if needed.
|
|
27
|
+
*/
|
|
28
|
+
export function pushMeta(metadata, key, value) {
|
|
29
|
+
const arr = metadata[key] ?? [];
|
|
30
|
+
arr.push(value);
|
|
31
|
+
metadata[key] = arr;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Read the metadata object stashed on a class by Stage 3 decorators.
|
|
35
|
+
* Returns `undefined` if no decorators have run on the class.
|
|
36
|
+
*/
|
|
37
|
+
export function getClassMetadata(cls) {
|
|
38
|
+
return cls[Symbol.metadata];
|
|
39
|
+
}
|
|
40
|
+
//# sourceMappingURL=metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"metadata.js","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,0DAA0D;AAC1D,MAAM,CAAC,MAAM,IAAI,GAAG;IAClB,KAAK,EAAE,MAAM,CAAC,cAAc,CAAC;IAC7B,IAAI,EAAE,MAAM,CAAC,aAAa,CAAC;IAC3B,KAAK,EAAE,MAAM,CAAC,cAAc,CAAC;IAC7B,MAAM,EAAE,MAAM,CAAC,eAAe,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC,iBAAiB,CAAC;IACnC,MAAM,EAAE,MAAM,CAAC,eAAe,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC,iBAAiB,CAAC;IACnC,WAAW,EAAE,MAAM,CAAC,oBAAoB,CAAC;CACjC,CAAC;AAIX;;GAEG;AACH,MAAM,UAAU,OAAO,CACrB,QAAwB,EACxB,GAAW,EACX,KAAc;IAEd,QAAQ,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AACxB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,QAAQ,CACtB,QAAwB,EACxB,GAAW,EACX,KAAc;IAEd,MAAM,GAAG,GAAI,QAAQ,CAAC,GAAG,CAAe,IAAI,EAAE,CAAC;IAC/C,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChB,QAAQ,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;AACtB,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAC9B,GAAyC;IAEzC,OACE,GACD,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AACrB,CAAC"}
|
package/dist/module.d.ts
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export interface ModuleOptions {
|
|
2
|
+
/** Other modules to import (compose). */
|
|
3
|
+
imports?: Array<new (...args: any[]) => any>;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Marks a class as a DI module. Modules group `@Provides()` factory methods
|
|
7
|
+
* and can import other modules.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* @Module({ imports: [DatabaseModule] })
|
|
11
|
+
* class AppModule {
|
|
12
|
+
* @Provides()
|
|
13
|
+
* dbUrl(): string { return process.env.DATABASE_URL! }
|
|
14
|
+
* }
|
|
15
|
+
*/
|
|
16
|
+
export declare function Module(options?: ModuleOptions): ClassDecorator_Stage3;
|
|
17
|
+
type ClassDecorator_Stage3 = (target: new (...args: any[]) => any, context: ClassDecoratorContext) => void;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,aAAa;IAC5B,yCAAyC;IACzC,OAAO,CAAC,EAAE,KAAK,CAAC,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,CAAC,CAAC;CAC9C;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,MAAM,CAAC,OAAO,GAAE,aAAkB,GAAG,qBAAqB,CAMzE;AAED,KAAK,qBAAqB,GAAG,CAC3B,MAAM,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACnC,OAAO,EAAE,qBAAqB,KAC3B,IAAI,CAAC"}
|
package/dist/module.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { META, setMeta } from './metadata.js';
|
|
2
|
+
/**
|
|
3
|
+
* Marks a class as a DI module. Modules group `@Provides()` factory methods
|
|
4
|
+
* and can import other modules.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* @Module({ imports: [DatabaseModule] })
|
|
8
|
+
* class AppModule {
|
|
9
|
+
* @Provides()
|
|
10
|
+
* dbUrl(): string { return process.env.DATABASE_URL! }
|
|
11
|
+
* }
|
|
12
|
+
*/
|
|
13
|
+
export function Module(options = {}) {
|
|
14
|
+
return (_target, context) => {
|
|
15
|
+
setMeta(context.metadata, META.MODULE, {
|
|
16
|
+
imports: options.imports ?? [],
|
|
17
|
+
});
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../src/module.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAO9C;;;;;;;;;;GAUG;AACH,MAAM,UAAU,MAAM,CAAC,UAAyB,EAAE;IAChD,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QAC1B,OAAO,CAAC,OAAO,CAAC,QAAS,EAAE,IAAI,CAAC,MAAM,EAAE;YACtC,OAAO,EAAE,OAAO,CAAC,OAAO,IAAI,EAAE;SAC/B,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/named.d.ts
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Assigns a qualifier name to a bean, used for disambiguation
|
|
3
|
+
* when multiple implementations exist for the same type.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* @Named('primary')
|
|
7
|
+
* @Singleton()
|
|
8
|
+
* class PrimaryUserRepository implements UserRepository { ... }
|
|
9
|
+
*/
|
|
10
|
+
export declare function Named(name: string): ClassDecorator_Stage3;
|
|
11
|
+
type ClassDecorator_Stage3 = (target: new (...args: any[]) => any, context: ClassDecoratorContext) => void;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=named.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"named.d.ts","sourceRoot":"","sources":["../src/named.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,wBAAgB,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,qBAAqB,CAIzD;AAED,KAAK,qBAAqB,GAAG,CAC3B,MAAM,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACnC,OAAO,EAAE,qBAAqB,KAC3B,IAAI,CAAC"}
|
package/dist/named.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { META, setMeta } from './metadata.js';
|
|
2
|
+
/**
|
|
3
|
+
* Assigns a qualifier name to a bean, used for disambiguation
|
|
4
|
+
* when multiple implementations exist for the same type.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* @Named('primary')
|
|
8
|
+
* @Singleton()
|
|
9
|
+
* class PrimaryUserRepository implements UserRepository { ... }
|
|
10
|
+
*/
|
|
11
|
+
export function Named(name) {
|
|
12
|
+
return (_target, context) => {
|
|
13
|
+
setMeta(context.metadata, META.NAME, name);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=named.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"named.js","sourceRoot":"","sources":["../src/named.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE9C;;;;;;;;GAQG;AACH,MAAM,UAAU,KAAK,CAAC,IAAY;IAChC,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QAC1B,OAAO,CAAC,OAAO,CAAC,QAAS,EAAE,IAAI,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC9C,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accessor decorator marking a dependency as optional.
|
|
3
|
+
* If no provider is registered, the field resolves to `undefined`.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* @Singleton()
|
|
7
|
+
* class MetricsService {
|
|
8
|
+
* @Optional() accessor tracer: Tracer | undefined
|
|
9
|
+
* }
|
|
10
|
+
*/
|
|
11
|
+
export declare function Optional(): (target: ClassAccessorDecoratorTarget<unknown, unknown>, context: ClassAccessorDecoratorContext) => void;
|
|
12
|
+
//# sourceMappingURL=optional.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optional.d.ts","sourceRoot":"","sources":["../src/optional.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,IAAI,CAC1B,MAAM,EAAE,4BAA4B,CAAC,OAAO,EAAE,OAAO,CAAC,EACtD,OAAO,EAAE,6BAA6B,KACnC,IAAI,CAMR"}
|
package/dist/optional.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { META, pushMeta } from './metadata.js';
|
|
2
|
+
/**
|
|
3
|
+
* Accessor decorator marking a dependency as optional.
|
|
4
|
+
* If no provider is registered, the field resolves to `undefined`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* @Singleton()
|
|
8
|
+
* class MetricsService {
|
|
9
|
+
* @Optional() accessor tracer: Tracer | undefined
|
|
10
|
+
* }
|
|
11
|
+
*/
|
|
12
|
+
export function Optional() {
|
|
13
|
+
return (_target, context) => {
|
|
14
|
+
pushMeta(context.metadata, META.OPTIONAL, {
|
|
15
|
+
fieldName: context.name,
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=optional.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"optional.js","sourceRoot":"","sources":["../src/optional.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE/C;;;;;;;;;GASG;AACH,MAAM,UAAU,QAAQ;IAItB,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QAC1B,QAAQ,CAAC,OAAO,CAAC,QAAS,EAAE,IAAI,CAAC,QAAQ,EAAE;YACzC,SAAS,EAAE,OAAO,CAAC,IAAI;SACxB,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marks a method to be called when the ApplicationContext is closed.
|
|
3
|
+
*
|
|
4
|
+
* Only effective on `@Singleton` / `@Injectable` classes. The method
|
|
5
|
+
* will be invoked during `close()` in reverse-topological order
|
|
6
|
+
* (dependents destroyed before their dependencies).
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* @Singleton()
|
|
10
|
+
* class DatabasePool {
|
|
11
|
+
* @PreDestroy()
|
|
12
|
+
* async shutdown() {
|
|
13
|
+
* await this.pool.end();
|
|
14
|
+
* }
|
|
15
|
+
* }
|
|
16
|
+
*/
|
|
17
|
+
export declare function PreDestroy(): MethodDecorator_Stage3;
|
|
18
|
+
type MethodDecorator_Stage3 = (target: (...args: never) => unknown, context: ClassMethodDecoratorContext) => void;
|
|
19
|
+
export {};
|
|
20
|
+
//# sourceMappingURL=pre-destroy.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pre-destroy.d.ts","sourceRoot":"","sources":["../src/pre-destroy.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,UAAU,IAAI,sBAAsB,CAMnD;AAED,KAAK,sBAAsB,GAAG,CAC5B,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,EACnC,OAAO,EAAE,2BAA2B,KACjC,IAAI,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { META, pushMeta } from './metadata.js';
|
|
2
|
+
/**
|
|
3
|
+
* Marks a method to be called when the ApplicationContext is closed.
|
|
4
|
+
*
|
|
5
|
+
* Only effective on `@Singleton` / `@Injectable` classes. The method
|
|
6
|
+
* will be invoked during `close()` in reverse-topological order
|
|
7
|
+
* (dependents destroyed before their dependencies).
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* @Singleton()
|
|
11
|
+
* class DatabasePool {
|
|
12
|
+
* @PreDestroy()
|
|
13
|
+
* async shutdown() {
|
|
14
|
+
* await this.pool.end();
|
|
15
|
+
* }
|
|
16
|
+
* }
|
|
17
|
+
*/
|
|
18
|
+
export function PreDestroy() {
|
|
19
|
+
return (_target, context) => {
|
|
20
|
+
pushMeta(context.metadata, META.PRE_DESTROY, {
|
|
21
|
+
methodName: context.name,
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=pre-destroy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pre-destroy.js","sourceRoot":"","sources":["../src/pre-destroy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE/C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,UAAU;IACxB,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QAC1B,QAAQ,CAAC,OAAO,CAAC,QAAS,EAAE,IAAI,CAAC,WAAW,EAAE;YAC5C,UAAU,EAAE,OAAO,CAAC,IAAI;SACzB,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marks a method inside a `@Module()` class as a bean factory.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* @Module()
|
|
6
|
+
* class AppModule {
|
|
7
|
+
* @Provides()
|
|
8
|
+
* databaseClient(): DatabaseClient { return new DatabaseClient() }
|
|
9
|
+
* }
|
|
10
|
+
*/
|
|
11
|
+
export declare function Provides(): MethodDecorator_Stage3;
|
|
12
|
+
type MethodDecorator_Stage3 = (target: (...args: never) => unknown, context: ClassMethodDecoratorContext) => void;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=provides.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provides.d.ts","sourceRoot":"","sources":["../src/provides.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,wBAAgB,QAAQ,IAAI,sBAAsB,CAMjD;AAED,KAAK,sBAAsB,GAAG,CAC5B,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,EACnC,OAAO,EAAE,2BAA2B,KACjC,IAAI,CAAC"}
|
package/dist/provides.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { META, pushMeta } from './metadata.js';
|
|
2
|
+
/**
|
|
3
|
+
* Marks a method inside a `@Module()` class as a bean factory.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* @Module()
|
|
7
|
+
* class AppModule {
|
|
8
|
+
* @Provides()
|
|
9
|
+
* databaseClient(): DatabaseClient { return new DatabaseClient() }
|
|
10
|
+
* }
|
|
11
|
+
*/
|
|
12
|
+
export function Provides() {
|
|
13
|
+
return (_target, context) => {
|
|
14
|
+
pushMeta(context.metadata, META.PROVIDES, {
|
|
15
|
+
methodName: context.name,
|
|
16
|
+
});
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=provides.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provides.js","sourceRoot":"","sources":["../src/provides.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE/C;;;;;;;;;GASG;AACH,MAAM,UAAU,QAAQ;IACtB,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QAC1B,QAAQ,CAAC,OAAO,CAAC,QAAS,EAAE,IAAI,CAAC,QAAQ,EAAE;YACzC,UAAU,EAAE,OAAO,CAAC,IAAI;SACzB,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Marks a class as a singleton bean.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* @Singleton()
|
|
6
|
+
* class UserService { ... }
|
|
7
|
+
*/
|
|
8
|
+
export declare function Singleton(): ClassDecorator_Stage3;
|
|
9
|
+
type ClassDecorator_Stage3 = (target: new (...args: any[]) => any, context: ClassDecoratorContext) => void;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=singleton.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"singleton.d.ts","sourceRoot":"","sources":["../src/singleton.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,wBAAgB,SAAS,IAAI,qBAAqB,CAIjD;AAED,KAAK,qBAAqB,GAAG,CAC3B,MAAM,EAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACnC,OAAO,EAAE,qBAAqB,KAC3B,IAAI,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { META, setMeta } from './metadata.js';
|
|
2
|
+
/**
|
|
3
|
+
* Marks a class as a singleton bean.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
* @Singleton()
|
|
7
|
+
* class UserService { ... }
|
|
8
|
+
*/
|
|
9
|
+
export function Singleton() {
|
|
10
|
+
return (_target, context) => {
|
|
11
|
+
setMeta(context.metadata, META.SCOPE, 'singleton');
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=singleton.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"singleton.js","sourceRoot":"","sources":["../src/singleton.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,UAAU,SAAS;IACvB,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QAC1B,OAAO,CAAC,OAAO,CAAC,QAAS,EAAE,IAAI,CAAC,KAAK,EAAE,WAA2B,CAAC,CAAC;IACtE,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@goodie-ts/decorators",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Stage 3 decorators for goodie-ts compile-time dependency injection",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/GOOD-Code-ApS/goodie.git",
|
|
10
|
+
"directory": "packages/decorators"
|
|
11
|
+
},
|
|
12
|
+
"publishConfig": {
|
|
13
|
+
"access": "public"
|
|
14
|
+
},
|
|
15
|
+
"main": "dist/index.js",
|
|
16
|
+
"types": "dist/index.d.ts",
|
|
17
|
+
"exports": {
|
|
18
|
+
".": {
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"import": "./dist/index.js"
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"@goodie-ts/core": "0.1.0"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist"
|
|
28
|
+
],
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "tsc",
|
|
31
|
+
"clean": "rm -rf dist *.tsbuildinfo"
|
|
32
|
+
}
|
|
33
|
+
}
|