@stompbox/tape-delay 1.0.10 → 1.0.12

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 CHANGED
@@ -52,9 +52,9 @@ const Scope = {
52
52
  ConstantValue
53
53
  };
54
54
  class TapeDelay {
55
- constructor(entries, getEnvironment){
55
+ constructor(entries, environmentDetector){
56
56
  this.entries = entries;
57
- this.getEnvironment = getEnvironment;
57
+ this.environmentDetector = environmentDetector;
58
58
  this.key = Math.random().toString();
59
59
  this.container = (environment)=>{
60
60
  const globalContainer = globalThis;
@@ -96,7 +96,7 @@ class TapeDelay {
96
96
  return container;
97
97
  };
98
98
  this.instance = (entryName)=>{
99
- const environment = this.getEnvironment ? this.getEnvironment() : process.env.NODE_ENV;
99
+ const environment = this.environmentDetector ? this.environmentDetector() : process.env.NODE_ENV;
100
100
  const container = this.container(environment);
101
101
  return container.get(entryName.toString());
102
102
  };
package/dist/index.d.ts CHANGED
@@ -13,10 +13,55 @@ type Entry<T> = [EntryDescription<T>, EntryDescription<T>, EntryDescription<T>]
13
13
  export type Entries = Record<string, Entry<unknown>>;
14
14
  export type EnvironmentDetector = () => Environment;
15
15
  type EntryType<T> = T extends Entry<infer G> ? PublicFields<G> : never;
16
+ /**
17
+ * Lifetime scopes.
18
+ */
16
19
  export declare const Scope: {
20
+ /**
21
+ * Singleton scope.
22
+ *
23
+ * @example
24
+ * ```ts
25
+ * import { Scope } from '@stompbox/tape-delay'
26
+ *
27
+ * const entries = { A: Scope.Singleton(A) }
28
+ * ```
29
+ */
17
30
  Singleton: <T>(EntryClass: ClassEntry<T>) => EntryDescription<T>;
31
+ /**
32
+ * Transient scope (used by default).
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import { Scope } from '@stompbox/tape-delay'
37
+ *
38
+ * const entries = { A: Scope.Transient(A) }
39
+ * ```
40
+ */
18
41
  Transient: <T>(EntryClass: ClassEntry<T>) => EntryDescription<T>;
42
+ /**
43
+ * Request scope.
44
+ *
45
+ * @example
46
+ * ```ts
47
+ * import { Scope } from '@stompbox/tape-delay'
48
+ *
49
+ * const entries = { A: Scope.Request(A) }
50
+ * ```
51
+ */
19
52
  Request: <T>(EntryClass: ClassEntry<T>) => EntryDescription<T>;
53
+ /**
54
+ * Constant value scope.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * import { Scope } from '@stompbox/tape-delay'
59
+ *
60
+ * const instance = new A()
61
+ *
62
+ * const entries = { A: Scope.ConstantValue(instance) }
63
+ * ```
64
+ */
20
65
  ConstantValue: <T>(value: T) => ConstantValueEntry<T>;
21
66
  };
22
67
  /**
@@ -57,7 +102,19 @@ export declare class TapeDelay<T extends Entries> {
57
102
  * ```
58
103
  */
59
104
  private readonly entries;
60
- private readonly getEnvironment?;
105
+ /**
106
+ * Optional environment detector. `process.env.NODE_ENV` is used by default.
107
+ *
108
+ * @example
109
+ * ```ts
110
+ * const randomEnvDetector: EnvironmentDetector = () => {
111
+ * if (Math.random() > 0.5) { return 'test' }
112
+ * if (Math.random() > 0.5) { return 'development' }
113
+ * return 'production'
114
+ * }
115
+ * ```
116
+ */
117
+ private readonly environmentDetector?;
61
118
  private readonly key;
62
119
  constructor(
63
120
  /**
@@ -83,7 +140,20 @@ export declare class TapeDelay<T extends Entries> {
83
140
  * }
84
141
  * ```
85
142
  */
86
- entries: T, getEnvironment?: EnvironmentDetector | undefined);
143
+ entries: T,
144
+ /**
145
+ * Optional environment detector. `process.env.NODE_ENV` is used by default.
146
+ *
147
+ * @example
148
+ * ```ts
149
+ * const randomEnvDetector: EnvironmentDetector = () => {
150
+ * if (Math.random() > 0.5) { return 'test' }
151
+ * if (Math.random() > 0.5) { return 'development' }
152
+ * return 'production'
153
+ * }
154
+ * ```
155
+ */
156
+ environmentDetector?: EnvironmentDetector | undefined);
87
157
  private container;
88
158
  instance: <E extends keyof T>(entryName: E) => EntryType<T[E]>;
89
159
  }
package/dist/index.js CHANGED
@@ -21,9 +21,9 @@ const Scope = {
21
21
  ConstantValue: ConstantValue
22
22
  };
23
23
  class TapeDelay {
24
- constructor(entries, getEnvironment){
24
+ constructor(entries, environmentDetector){
25
25
  this.entries = entries;
26
- this.getEnvironment = getEnvironment;
26
+ this.environmentDetector = environmentDetector;
27
27
  this.key = Math.random().toString();
28
28
  this.container = (environment)=>{
29
29
  const globalContainer = globalThis;
@@ -65,7 +65,7 @@ class TapeDelay {
65
65
  return container;
66
66
  };
67
67
  this.instance = (entryName)=>{
68
- const environment = this.getEnvironment ? this.getEnvironment() : process.env.NODE_ENV;
68
+ const environment = this.environmentDetector ? this.environmentDetector() : process.env.NODE_ENV;
69
69
  const container = this.container(environment);
70
70
  return container.get(entryName.toString());
71
71
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stompbox/tape-delay",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "license": "MIT",
5
5
  "description": "Plug-and-play DI based on Inversify",
6
6
  "repository": {