@goodie-ts/decorators 0.1.0 → 0.2.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 ADDED
@@ -0,0 +1,46 @@
1
+ # @goodie-ts/decorators
2
+
3
+ Stage 3 decorators for [goodie-ts](https://github.com/GOOD-Code-ApS/goodie) compile-time dependency injection.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pnpm add @goodie-ts/decorators
9
+ ```
10
+
11
+ ## Overview
12
+
13
+ Provides the decorators you use to annotate your classes. These attach metadata via `Symbol.metadata` which the transformer reads at build time — they do **not** wire anything at runtime. No `reflect-metadata` required.
14
+
15
+ ## Decorators
16
+
17
+ | Decorator | Target | Description |
18
+ |-----------|--------|-------------|
19
+ | `@Singleton()` | class | Singleton-scoped bean |
20
+ | `@Injectable()` | class | Prototype-scoped bean (new instance per lookup) |
21
+ | `@Named(name)` | class | Qualifier for disambiguation |
22
+ | `@Eager()` | class | Instantiate at startup instead of on first access |
23
+ | `@Module({ imports? })` | class | Groups `@Provides` factory methods |
24
+ | `@Provides()` | method | Marks a method in a `@Module` as a bean factory |
25
+ | `@Inject(qualifier?)` | accessor field | Field injection |
26
+ | `@Optional()` | accessor field | Marks a field as optional (resolves to `undefined` if missing) |
27
+
28
+ ## Usage
29
+
30
+ ```typescript
31
+ import { Singleton, Inject, Optional } from '@goodie-ts/decorators';
32
+
33
+ @Singleton()
34
+ class UserService {
35
+ @Inject() accessor userRepo!: UserRepository;
36
+ @Optional() accessor logger?: Logger;
37
+
38
+ getUsers() { return this.userRepo.findAll(); }
39
+ }
40
+ ```
41
+
42
+ > **Note:** `@Inject` and `@Optional` require the `accessor` keyword — Stage 3 decorators do not support parameter decorators.
43
+
44
+ ## License
45
+
46
+ [MIT](https://github.com/GOOD-Code-ApS/goodie/blob/main/LICENSE)
package/dist/index.d.ts CHANGED
@@ -6,7 +6,11 @@ export type { ModuleOptions } from './module.js';
6
6
  export { Module } from './module.js';
7
7
  export { Named } from './named.js';
8
8
  export { Optional } from './optional.js';
9
+ export { PostConstruct } from './post-construct.js';
10
+ export { PostProcessor } from './post-processor.js';
9
11
  export { PreDestroy } from './pre-destroy.js';
10
12
  export { Provides } from './provides.js';
11
13
  export { Singleton } from './singleton.js';
14
+ export type { ValueOptions } from './value.js';
15
+ export { Value } from './value.js';
12
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +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"}
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,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,YAAY,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC/C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -5,7 +5,10 @@ export { getClassMetadata, META, pushMeta, setMeta } from './metadata.js';
5
5
  export { Module } from './module.js';
6
6
  export { Named } from './named.js';
7
7
  export { Optional } from './optional.js';
8
+ export { PostConstruct } from './post-construct.js';
9
+ export { PostProcessor } from './post-processor.js';
8
10
  export { PreDestroy } from './pre-destroy.js';
9
11
  export { Provides } from './provides.js';
10
12
  export { Singleton } from './singleton.js';
13
+ export { Value } from './value.js';
11
14
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +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"}
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,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC"}
@@ -15,6 +15,9 @@ export declare const META: {
15
15
  readonly INJECT: symbol;
16
16
  readonly OPTIONAL: symbol;
17
17
  readonly PRE_DESTROY: symbol;
18
+ readonly POST_CONSTRUCT: symbol;
19
+ readonly POST_PROCESSOR: symbol;
20
+ readonly VALUE: symbol;
18
21
  };
19
22
  type MetadataObject = DecoratorMetadataObject | Record<PropertyKey, unknown>;
20
23
  /**
@@ -1 +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"}
1
+ {"version":3,"file":"metadata.d.ts","sourceRoot":"","sources":["../src/metadata.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,0DAA0D;AAC1D,eAAO,MAAM,IAAI;;;;;;;;;;;;CAYP,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 CHANGED
@@ -15,6 +15,9 @@ export const META = {
15
15
  INJECT: Symbol('goodie:inject'),
16
16
  OPTIONAL: Symbol('goodie:optional'),
17
17
  PRE_DESTROY: Symbol('goodie:pre-destroy'),
18
+ POST_CONSTRUCT: Symbol('goodie:post-construct'),
19
+ POST_PROCESSOR: Symbol('goodie:post-processor'),
20
+ VALUE: Symbol('goodie:value'),
18
21
  };
19
22
  /**
20
23
  * Set a single metadata value on the decorator context metadata object.
@@ -1 +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"}
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;IACzC,cAAc,EAAE,MAAM,CAAC,uBAAuB,CAAC;IAC/C,cAAc,EAAE,MAAM,CAAC,uBAAuB,CAAC;IAC/C,KAAK,EAAE,MAAM,CAAC,cAAc,CAAC;CACrB,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"}
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Marks a method to be called after the bean is fully constructed and
3
+ * `beforeInit` post-processors have run, but before `afterInit` post-processors.
4
+ *
5
+ * Only effective on `@Singleton` / `@Injectable` classes.
6
+ *
7
+ * @example
8
+ * @Singleton()
9
+ * class UserService {
10
+ * @PostConstruct()
11
+ * init() {
12
+ * // called after construction + beforeInit
13
+ * }
14
+ * }
15
+ */
16
+ export declare function PostConstruct(): MethodDecorator_Stage3;
17
+ type MethodDecorator_Stage3 = (target: (...args: never) => unknown, context: ClassMethodDecoratorContext) => void;
18
+ export {};
19
+ //# sourceMappingURL=post-construct.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"post-construct.d.ts","sourceRoot":"","sources":["../src/post-construct.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,aAAa,IAAI,sBAAsB,CAMtD;AAED,KAAK,sBAAsB,GAAG,CAC5B,MAAM,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,KAAK,OAAO,EACnC,OAAO,EAAE,2BAA2B,KACjC,IAAI,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { META, pushMeta } from './metadata.js';
2
+ /**
3
+ * Marks a method to be called after the bean is fully constructed and
4
+ * `beforeInit` post-processors have run, but before `afterInit` post-processors.
5
+ *
6
+ * Only effective on `@Singleton` / `@Injectable` classes.
7
+ *
8
+ * @example
9
+ * @Singleton()
10
+ * class UserService {
11
+ * @PostConstruct()
12
+ * init() {
13
+ * // called after construction + beforeInit
14
+ * }
15
+ * }
16
+ */
17
+ export function PostConstruct() {
18
+ return (_target, context) => {
19
+ pushMeta(context.metadata, META.POST_CONSTRUCT, {
20
+ methodName: context.name,
21
+ });
22
+ };
23
+ }
24
+ //# sourceMappingURL=post-construct.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"post-construct.js","sourceRoot":"","sources":["../src/post-construct.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE/C;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QAC1B,QAAQ,CAAC,OAAO,CAAC,QAAS,EAAE,IAAI,CAAC,cAAc,EAAE;YAC/C,UAAU,EAAE,OAAO,CAAC,IAAI;SACzB,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Marks a singleton bean as a BeanPostProcessor.
3
+ *
4
+ * The transformer will set `metadata.isBeanPostProcessor = true` on the
5
+ * generated BeanDefinition, so the runtime discovers it automatically.
6
+ *
7
+ * @example
8
+ * @PostProcessor()
9
+ * @Singleton()
10
+ * class LoggingPostProcessor implements BeanPostProcessor {
11
+ * afterInit(bean: unknown) { console.log('created', bean); return bean; }
12
+ * }
13
+ */
14
+ export declare function PostProcessor(): ClassDecorator_Stage3;
15
+ type ClassDecorator_Stage3 = (target: new (...args: any[]) => any, context: ClassDecoratorContext) => void;
16
+ export {};
17
+ //# sourceMappingURL=post-processor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"post-processor.d.ts","sourceRoot":"","sources":["../src/post-processor.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,wBAAgB,aAAa,IAAI,qBAAqB,CAIrD;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,20 @@
1
+ import { META, setMeta } from './metadata.js';
2
+ /**
3
+ * Marks a singleton bean as a BeanPostProcessor.
4
+ *
5
+ * The transformer will set `metadata.isBeanPostProcessor = true` on the
6
+ * generated BeanDefinition, so the runtime discovers it automatically.
7
+ *
8
+ * @example
9
+ * @PostProcessor()
10
+ * @Singleton()
11
+ * class LoggingPostProcessor implements BeanPostProcessor {
12
+ * afterInit(bean: unknown) { console.log('created', bean); return bean; }
13
+ * }
14
+ */
15
+ export function PostProcessor() {
16
+ return (_target, context) => {
17
+ setMeta(context.metadata, META.POST_PROCESSOR, true);
18
+ };
19
+ }
20
+ //# sourceMappingURL=post-processor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"post-processor.js","sourceRoot":"","sources":["../src/post-processor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAE9C;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,aAAa;IAC3B,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QAC1B,OAAO,CAAC,OAAO,CAAC,QAAS,EAAE,IAAI,CAAC,cAAc,EAAE,IAAI,CAAC,CAAC;IACxD,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,25 @@
1
+ /** Options for the @Value decorator. */
2
+ export interface ValueOptions {
3
+ /** Default value when the config key is missing. */
4
+ default?: unknown;
5
+ }
6
+ /**
7
+ * Injects a configuration value by key.
8
+ *
9
+ * The config source is a bean registered under the `__Goodie_Config` token,
10
+ * which defaults to `process.env` and can be overridden via `createContext(config)`.
11
+ *
12
+ * @param key The config key to inject (e.g. `'DB_URL'`)
13
+ * @param options Optional default value
14
+ *
15
+ * @example
16
+ * @Singleton()
17
+ * class DbService {
18
+ * @Value('DB_URL') accessor dbUrl!: string
19
+ * @Value('PORT', { default: 3000 }) accessor port!: number
20
+ * }
21
+ */
22
+ export declare function Value(key: string, options?: ValueOptions): FieldDecorator_Stage3;
23
+ type FieldDecorator_Stage3 = (target: ClassAccessorDecoratorTarget<unknown, unknown>, context: ClassAccessorDecoratorContext) => void;
24
+ export {};
25
+ //# sourceMappingURL=value.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value.d.ts","sourceRoot":"","sources":["../src/value.ts"],"names":[],"mappings":"AAEA,wCAAwC;AACxC,MAAM,WAAW,YAAY;IAC3B,oDAAoD;IACpD,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,KAAK,CACnB,GAAG,EAAE,MAAM,EACX,OAAO,CAAC,EAAE,YAAY,GACrB,qBAAqB,CAYvB;AAED,KAAK,qBAAqB,GAAG,CAC3B,MAAM,EAAE,4BAA4B,CAAC,OAAO,EAAE,OAAO,CAAC,EACtD,OAAO,EAAE,6BAA6B,KACnC,IAAI,CAAC"}
package/dist/value.js ADDED
@@ -0,0 +1,30 @@
1
+ import { META, pushMeta } from './metadata.js';
2
+ /**
3
+ * Injects a configuration value by key.
4
+ *
5
+ * The config source is a bean registered under the `__Goodie_Config` token,
6
+ * which defaults to `process.env` and can be overridden via `createContext(config)`.
7
+ *
8
+ * @param key The config key to inject (e.g. `'DB_URL'`)
9
+ * @param options Optional default value
10
+ *
11
+ * @example
12
+ * @Singleton()
13
+ * class DbService {
14
+ * @Value('DB_URL') accessor dbUrl!: string
15
+ * @Value('PORT', { default: 3000 }) accessor port!: number
16
+ * }
17
+ */
18
+ export function Value(key, options) {
19
+ return (_target, context) => {
20
+ const meta = {
21
+ fieldName: context.name,
22
+ key,
23
+ };
24
+ if (options?.default !== undefined) {
25
+ meta.default = options.default;
26
+ }
27
+ pushMeta(context.metadata, META.VALUE, meta);
28
+ };
29
+ }
30
+ //# sourceMappingURL=value.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value.js","sourceRoot":"","sources":["../src/value.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAQ/C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,KAAK,CACnB,GAAW,EACX,OAAsB;IAEtB,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,EAAE;QAC1B,MAAM,IAAI,GACR;YACE,SAAS,EAAE,OAAO,CAAC,IAAI;YACvB,GAAG;SACJ,CAAC;QACJ,IAAI,OAAO,EAAE,OAAO,KAAK,SAAS,EAAE,CAAC;YACnC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;QACjC,CAAC;QACD,QAAQ,CAAC,OAAO,CAAC,QAAS,EAAE,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC;IAChD,CAAC,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@goodie-ts/decorators",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Stage 3 decorators for goodie-ts compile-time dependency injection",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -21,7 +21,7 @@
21
21
  }
22
22
  },
23
23
  "dependencies": {
24
- "@goodie-ts/core": "0.1.0"
24
+ "@goodie-ts/core": "0.2.0"
25
25
  },
26
26
  "files": [
27
27
  "dist"