@stompbox/tape-delay 0.0.8 → 0.0.10

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 CHANGED
@@ -37,4 +37,24 @@ const aInstance = container.instance('A')
37
37
  console.log(aInstance.hello())
38
38
  const bInstance = container.instance('B')
39
39
  console.log(bInstance.method())
40
+ ```
41
+
42
+ ## Environment detection
43
+
44
+ Environment variable `process.env.NODE_ENV` is used by default. This behaviour can be redefined with optional second parameter in `TapeDelay` constructor.
45
+
46
+ ```ts
47
+ import { TapeDelay, EnvironmentDetector } from '@stompbox/tape-delay'
48
+
49
+ const randomEnvDetector: EnvironmentDetector = () => {
50
+ if (Math.random() > 0.5) {
51
+ return 'test'
52
+ }
53
+ if (Math.random() > 0.5) {
54
+ return 'development'
55
+ }
56
+ return 'production'
57
+ }
58
+
59
+ const container = new TapeDelay({}, randomEnvDetector)
40
60
  ```
package/dist/index.cjs CHANGED
@@ -42,10 +42,14 @@ const Request = (EntryClass)=>[
42
42
  EntryClass,
43
43
  (x)=>x.inRequestScope()
44
44
  ];
45
+ const ConstantValue = (value)=>({
46
+ constantValue: value
47
+ });
45
48
  const Lifespans = {
46
49
  Singleton,
47
50
  Transient,
48
- Request
51
+ Request,
52
+ ConstantValue
49
53
  };
50
54
  class TapeDelay {
51
55
  entries;
package/dist/index.d.ts CHANGED
@@ -11,17 +11,19 @@ type PublicFields<T> = {
11
11
  type EntryDescription<T> = ClassEntry<T> | ConstantValueEntry<T> | [ClassEntry<T>, (x: BindInWhenOnFluentSyntax<unknown>) => any];
12
12
  type Entry<T> = [EntryDescription<T>, EntryDescription<T>, EntryDescription<T>] | EntryDescription<T>;
13
13
  export type Entries = Record<string, Entry<unknown>>;
14
+ export type EnvironmentDetector = () => Environment;
14
15
  type EntryType<T> = T extends Entry<infer G> ? PublicFields<G> : never;
15
16
  export declare const Lifespans: {
16
17
  Singleton: <T>(EntryClass: ClassEntry<T>) => EntryDescription<T>;
17
18
  Transient: <T>(EntryClass: ClassEntry<T>) => EntryDescription<T>;
18
19
  Request: <T>(EntryClass: ClassEntry<T>) => EntryDescription<T>;
20
+ ConstantValue: <T>(value: T) => ConstantValueEntry<T>;
19
21
  };
20
22
  export declare class TapeDelay<T extends Entries> {
21
23
  private readonly entries;
22
24
  private readonly getEnvironment?;
23
25
  private readonly key;
24
- constructor(entries: T, getEnvironment?: (() => Environment) | undefined);
26
+ constructor(entries: T, getEnvironment?: EnvironmentDetector | undefined);
25
27
  private container;
26
28
  instance: <E extends keyof T>(entryName: E) => EntryType<T[E]>;
27
29
  }
package/dist/index.js CHANGED
@@ -11,10 +11,14 @@ const Request = (EntryClass)=>[
11
11
  EntryClass,
12
12
  (x)=>x.inRequestScope()
13
13
  ];
14
+ const ConstantValue = (value)=>({
15
+ constantValue: value
16
+ });
14
17
  const Lifespans = {
15
18
  Singleton: Singleton,
16
19
  Transient: Transient,
17
- Request: Request
20
+ Request: Request,
21
+ ConstantValue: ConstantValue
18
22
  };
19
23
  class TapeDelay {
20
24
  entries;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stompbox/tape-delay",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "Plug-and-play DI based on Inversify",
5
5
  "type": "module",
6
6
  "exports": {